-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR Defer "gurobi not found" errors until build time
This is required for `bazel query` commands or `genquery()` rules to run without error. We want users without Gurobi configured to still be able to use the query features of Bazel. (This will soon become required for linters that inspect libdrake.so compositional correctness.)
- Loading branch information
1 parent
d981bd3
commit 41bd35e
Showing
5 changed files
with
124 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- python -*- | ||
|
||
load("@drake//tools/install:install.bzl", "install") | ||
|
||
licenses(["by_exception_only"]) # Gurobi | ||
|
||
# This rule is only built if a glob() call fails. | ||
genrule( | ||
name = "error-message", | ||
outs = ["error-message.h"], | ||
cmd = "echo 'error: Gurobi 7.5.2 is not installed at {gurobi_path}' && false", # noqa | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
GUROBI_HDRS = glob([ | ||
"gurobi-distro/include/gurobi_c.h", | ||
"gurobi-distro/include/gurobi_c++.h", | ||
]) or [":error-message.h"] | ||
|
||
cc_library( | ||
name = "gurobi", | ||
hdrs = GUROBI_HDRS, | ||
includes = ["gurobi-distro/include"], | ||
linkopts = [ | ||
"-L{gurobi_path}/lib", | ||
"-lgurobi75", | ||
], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
# For macOS, the Drake install step does not need any additional actions to | ||
# install Gurobi, since Gurobi was already installed system-wide in /Library. | ||
install(name = "install") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# -*- python -*- | ||
|
||
load("@drake//tools/install:install.bzl", "install", "install_files") | ||
|
||
licenses(["by_exception_only"]) # Gurobi | ||
|
||
# This rule is only built if a glob() call fails. | ||
genrule( | ||
name = "error-message", | ||
outs = ["error-message.h"], | ||
cmd = "echo 'error: The value of environment variable GUROBI_PATH=\"{gurobi_path}\" is invalid; export GUROBI_PATH to the correct value.' && false", # noqa | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
GUROBI_HDRS = glob([ | ||
"gurobi-distro/include/gurobi_c.h", | ||
"gurobi-distro/include/gurobi_c++.h", | ||
]) or [":error-message.h"] | ||
|
||
# In the Gurobi package, libgurobi75.so is a symlink to libgurobi.so.7.5.2. | ||
# However, if we use libgurobi.so.7.5.2 in srcs, executables that link this | ||
# library will be unable to find it at runtime in the Bazel sandbox, | ||
# because the NEEDED statements in the executable will not square with the | ||
# RPATH statements. I don't really know why this happens, but I suspect it | ||
# might be a Bazel bug. | ||
GUROBI_SRCS = glob([ | ||
"gurobi-distro/lib/libgurobi75.so", | ||
]) or [":error-message.h"] | ||
|
||
GUROBI_INSTALL_LIBRARIES = glob([ | ||
"gurobi-distro/lib/libgurobi.so.7.5.2", | ||
"gurobi-distro/lib/libgurobi75.so", | ||
]) or [":error-message.h"] | ||
|
||
GUROBI_DOCS = glob([ | ||
"gurobi-distro/EULA.pdf", | ||
]) or [":error-message.h"] | ||
|
||
cc_library( | ||
name = "gurobi", | ||
srcs = GUROBI_SRCS, | ||
hdrs = GUROBI_HDRS, | ||
includes = ["gurobi-distro/include"], | ||
linkopts = ["-pthread"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
install_files( | ||
name = "install_libraries", | ||
dest = ".", | ||
files = GUROBI_INSTALL_LIBRARIES, | ||
strip_prefix = ["gurobi-distro"], | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
install( | ||
name = "install", | ||
docs = GUROBI_DOCS, | ||
doc_strip_prefix = ["gurobi-distro"], | ||
visibility = ["//visibility:public"], | ||
deps = [":install_libraries"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters