Skip to content

Commit

Permalink
[workspace] Build NLopt from source
Browse files Browse the repository at this point in the history
Compared to the Ubuntu and macOS packages, this removes the LGPL'd
"luksan" solver from the build, which means we can link the library
statically (and eventually, hidden). This might mean that NLopt is
no longer able to solve certain kinds of programs, but that is a
fair trade-off given all of the problems caused by LGPL linking.

The package.BUILD.bazel is modeled on nlopt.BUILD.bazel in a10ebb7.

Deprecate the now-unused current (host OS) nlopt external.
  • Loading branch information
jwnimmer-tri committed Jun 7, 2022
1 parent 80488ae commit 13b33a9
Show file tree
Hide file tree
Showing 19 changed files with 669 additions and 17 deletions.
2 changes: 1 addition & 1 deletion solvers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ drake_cc_variant_library(
],
deps_enabled = [
"//math:autodiff",
"@nlopt",
"@nlopt_internal//:nlopt",
],
)

Expand Down
13 changes: 0 additions & 13 deletions tools/install/libdrake/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ cc_library(
name = "dreal_deps",
deps = select({
"//conditions:default": [
"@nlopt",
"@ibex",
],
"//tools:no_dreal": [],
Expand Down Expand Up @@ -162,17 +161,6 @@ cc_library(
}),
)

# Depend on NLOPT's shared library iff NLOPT is enabled.
cc_library(
name = "nlopt_deps",
deps = select({
"//conditions:default": [
"@nlopt",
],
"//tools:no_nlopt": [],
}),
)

# Depend on the subset of VTK's shared libraries that Drake uses.
cc_library(
name = "vtk_deps",
Expand Down Expand Up @@ -239,7 +227,6 @@ cc_library(
":gurobi_deps",
":ipopt_deps",
":mosek_deps",
":nlopt_deps",
":vtk_deps",
":x11_deps",
"//common:drake_marker_shared_library",
Expand Down
2 changes: 0 additions & 2 deletions tools/wheel/image/packages-focal
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ zip
# Build dependencies (general).
libgl1-mesa-dev
libglib2.0-dev
libnlopt-dev
libnlopt-cxx-dev
libxt-dev
# Build dependencies (OpenCL).
opencl-headers
Expand Down
1 change: 1 addition & 0 deletions tools/workspace/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ drake_py_binary(
srcs = ["vendor_cxx.py"],
visibility = [
# These should all be of the form "@foo_internal//:__pkg__".
"@nlopt_internal//:__pkg__",
"@qhull_internal//:__pkg__",
"@yaml_cpp_internal//:__pkg__",
],
Expand Down
5 changes: 5 additions & 0 deletions tools/workspace/default.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ load("@drake//tools/workspace/mosek:repository.bzl", "mosek_repository")
load("@drake//tools/workspace/msgpack:repository.bzl", "msgpack_repository")
load("@drake//tools/workspace/net_sf_jchart2d:repository.bzl", "net_sf_jchart2d_repository") # noqa
load("@drake//tools/workspace/nlopt:repository.bzl", "nlopt_repository")
load("@drake//tools/workspace/nlopt_internal:repository.bzl", "nlopt_internal_repository") # noqa
load("@drake//tools/workspace/openblas:repository.bzl", "openblas_repository")
load("@drake//tools/workspace/opencl:repository.bzl", "opencl_repository")
load("@drake//tools/workspace/opengl:repository.bzl", "opengl_repository")
Expand Down Expand Up @@ -238,7 +239,11 @@ def add_default_repositories(excludes = [], mirrors = DEFAULT_MIRRORS):
if "net_sf_jchart2d" not in excludes:
net_sf_jchart2d_repository(name = "net_sf_jchart2d", mirrors = mirrors)
if "nlopt" not in excludes:
# The @nlopt external is being removed from Drake on 2020-09-01.
# TODO(jwnimmer-tri) When removing @nlopt, also update install_prereqs.
nlopt_repository(name = "nlopt")
if "nlopt_internal" not in excludes:
nlopt_internal_repository(name = "nlopt_internal", mirrors = mirrors)
if "openblas" not in excludes:
openblas_repository(name = "openblas")
if "opencl" not in excludes:
Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions tools/workspace/dreal/patches/warnings.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Silence this warning:
dreal/dreal/optimization/nlopt_optimizer.h:44:7: warning:
'dreal::NloptOptimizer' declared with greater visibility than the type
of its field 'dreal::NloptOptimizer::opt_' [-Wattributes]

TODO(jwnimmer-tri) Try to use a hidden inline namespace for dReal as well,
to silence this warning.

--- tools/dreal.bzl
+++ tools/dreal.bzl
@@ -25,6 +25,7 @@
"-Woverloaded-virtual",
"-Wpedantic",
"-Wshadow",
+ "-Wno-attributes",
]

# The CLANG_FLAGS will be enabled for all C++ rules in the project when
6 changes: 5 additions & 1 deletion tools/workspace/dreal/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def dreal_repository(
sha256 = "7bbd328a25c14cff814753694b1823257bb7cff7f84a7b705b9f111624d5b2e4", # noqa
mirrors = mirrors,
patches = [
"@drake//tools/workspace/dreal:ibex_2.8.6.patch",
"@drake//tools/workspace/dreal:patches/ibex_2.8.6.patch",
"@drake//tools/workspace/dreal:patches/warnings.patch",
],
repo_mapping = {
"@nlopt": "@nlopt_internal",
},
)
1 change: 1 addition & 0 deletions tools/workspace/nlopt/package-macos.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ cc_library(
"-lnlopt",
],
visibility = ["//visibility:public"],
deprecation = "DRAKE DEPRECATED: The @nlopt external is being removed from Drake on or after 2020-09-01. Downstream projects should add it to their own WORKSPACE if needed.", # noqa
)
1 change: 1 addition & 0 deletions tools/workspace/nlopt/package-ubuntu-20.04.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ cc_library(
"-lnlopt_cxx",
],
visibility = ["//visibility:public"],
deprecation = "DRAKE DEPRECATED: The @nlopt external is being removed from Drake on or after 2020-09-01. Downstream projects should add it to their own WORKSPACE if needed.", # noqa
)
45 changes: 45 additions & 0 deletions tools/workspace/nlopt_internal/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- python -*-

load("//tools/skylark:drake_py.bzl", "drake_py_unittest")
load("//tools/lint:lint.bzl", "add_lint_tests")

exports_files(
["patches/gen_enums.patch"],
visibility = ["@nlopt_internal//:__pkg__"],
)

# Creates api/nlopt.hpp using NLopt upstream's codegen so that we can
# cross-check it versus our Drake-local patch file.
genrule(
name = "cmake_genrule",
srcs = [
"@nlopt_internal//:cmake/generate-cpp.cmake",
"@nlopt_internal//:src/api/nlopt-in.hpp",
"@nlopt_internal//:src/api/nlopt.h",
],
outs = ["test/nlopt-upstream.hpp"],
cmd = " ".join([
"cmake",
"-DAPI_SOURCE_DIR=$$(dirname $(execpath @nlopt_internal//:src/api/nlopt.h))", # noqa
"-P $(execpath @nlopt_internal//:cmake/generate-cpp.cmake)",
"&&",
"mv nlopt.hpp $@",
]),
tags = [
"manual",
"nolint",
],
)

drake_py_unittest(
name = "enum_test",
data = [
":test/nlopt-upstream.hpp",
"@nlopt_internal//:genrule/nlopt.hpp",
],
deps = [
"@bazel_tools//tools/python/runfiles",
],
)

add_lint_tests()
Loading

0 comments on commit 13b33a9

Please sign in to comment.