Skip to content

Commit

Permalink
Provide macOS stubs for @blas and @lapack
Browse files Browse the repository at this point in the history
On macOS we should never use @blas and @lapack, but in order for `bazel
query` to succeed, all branches of select() statements need to resolve,
so because Ubuntu has real @blas and @lapack, we need to stub these out
on macOS.  The stubs merely have to load -- the library targets do not
need to (and should not) compile successfully.
  • Loading branch information
jwnimmer-tri committed Apr 24, 2018
1 parent 8121951 commit 016a94a
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tools/workspace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ it into Drake are roughly:

## When using a library from the host operating system

See `blas` or `glib` for examples.
See `glib` for an example.

Update the package setup lists to mention the new package:

Expand Down
9 changes: 9 additions & 0 deletions tools/workspace/blas/package-macos.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- python -*-

package(default_visibility = ["//visibility:public"])

# On macOS, no targets should depend on @blas.
cc_library(
name = "blas",
srcs = ["missing-macos.cc"],
)
41 changes: 30 additions & 11 deletions tools/workspace/blas/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
# -*- mode: python -*-

load(
"@drake//tools/workspace:os.bzl",
"determine_os",
)
load(
"@drake//tools/workspace:pkg_config.bzl",
"pkg_config_repository",
"setup_pkg_config_repository",
)

def blas_repository(
name,
licenses = ["notice"], # BSD-3-Clause
modname = "blas",
**kwargs):
pkg_config_repository(
name = name,
licenses = licenses,
modname = modname,
**kwargs)
def _impl(repo_ctx):
# On Ubuntu, we'll use use pkg-config to find libblas.
# On macOS, no targets should depend on @blas.
os_result = determine_os(repo_ctx)
if os_result.error != None:
fail(os_result.error)
if os_result.is_ubuntu:
error = setup_pkg_config_repository(repo_ctx).error
if error != None:
fail(error)
else:
repo_ctx.symlink(
Label("@drake//tools/workspace/blas:package-macos.BUILD.bazel"),
"BUILD.bazel")

blas_repository = repository_rule(
# TODO(jamiesnape): Pass down licenses to setup_pkg_config_repository.
# The license for this package should be:
# licenses(["notice"]) # BSD-3-Clause
attrs = {
"modname": attr.string(default = "blas"),
},
local = True,
implementation = _impl,
)
9 changes: 9 additions & 0 deletions tools/workspace/lapack/package-macos.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- python -*-

package(default_visibility = ["//visibility:public"])

# On macOS, no targets should depend on @lapack.
cc_library(
name = "lapack",
srcs = ["missing-macos.cc"],
)
41 changes: 30 additions & 11 deletions tools/workspace/lapack/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
# -*- mode: python -*-

load(
"@drake//tools/workspace:os.bzl",
"determine_os",
)
load(
"@drake//tools/workspace:pkg_config.bzl",
"pkg_config_repository",
"setup_pkg_config_repository",
)

def lapack_repository(
name,
licenses = ["notice"], # BSD-3-Clause
modname = "lapack",
**kwargs):
pkg_config_repository(
name = name,
licenses = licenses,
modname = modname,
**kwargs)
def _impl(repo_ctx):
# On Ubuntu, we'll use use pkg-config to find liblapack.
# On macOS, no targets should depend on @lapack.
os_result = determine_os(repo_ctx)
if os_result.error != None:
fail(os_result.error)
if os_result.is_ubuntu:
error = setup_pkg_config_repository(repo_ctx).error
if error != None:
fail(error)
else:
repo_ctx.symlink(
Label("@drake//tools/workspace/lapack:package-macos.BUILD.bazel"),
"BUILD.bazel")

lapack_repository = repository_rule(
# TODO(jamiesnape): Pass down licenses to setup_pkg_config_repository.
# The license for this package should be:
# licenses(["notice"]) # BSD-3-Clause
attrs = {
"modname": attr.string(default = "lapack"),
},
local = True,
implementation = _impl,
)

0 comments on commit 016a94a

Please sign in to comment.