diff --git a/perception/BUILD.bazel b/perception/BUILD.bazel index 0614efd7dcf0..f99ca6053197 100644 --- a/perception/BUILD.bazel +++ b/perception/BUILD.bazel @@ -42,7 +42,7 @@ drake_cc_library( deps = [ "//common:unused", "@abseil_cpp_internal//absl/container:flat_hash_map", - "@nanoflann", + "@nanoflann_internal//:nanoflann", ], ) diff --git a/perception/point_cloud.cc b/perception/point_cloud.cc index b31823216131..772e421eff24 100644 --- a/perception/point_cloud.cc +++ b/perception/point_cloud.cc @@ -6,9 +6,9 @@ #include #include "absl/container/flat_hash_map.h" +#include #include #include -#include #include "drake/common/drake_assert.h" #include "drake/common/drake_throw.h" diff --git a/tools/workspace/BUILD.bazel b/tools/workspace/BUILD.bazel index 14fcbb8557e0..a96587beadc2 100644 --- a/tools/workspace/BUILD.bazel +++ b/tools/workspace/BUILD.bazel @@ -90,6 +90,7 @@ _DRAKE_EXTERNAL_PACKAGE_INSTALLS = ["@%s//:install" % p for p in [ "meshcat_python", "msgpack_lite_js", "net_sf_jchart2d", + "nanoflann_internal", "nlopt_internal", "org_apache_xmlgraphics_commons", "petsc", diff --git a/tools/workspace/default.bzl b/tools/workspace/default.bzl index 8a3fab06f7b1..98bb3027336f 100644 --- a/tools/workspace/default.bzl +++ b/tools/workspace/default.bzl @@ -63,7 +63,7 @@ load("@drake//tools/workspace/msgpack:repository.bzl", "msgpack_repository") load("@drake//tools/workspace/msgpack_lite_js:repository.bzl", "msgpack_lite_js_repository") # noqa load("@drake//tools/workspace/mypy_extensions_internal:repository.bzl", "mypy_extensions_internal_repository") # noqa load("@drake//tools/workspace/mypy_internal:repository.bzl", "mypy_internal_repository") # noqa -load("@drake//tools/workspace/nanoflann:repository.bzl", "nanoflann_repository") # noqa +load("@drake//tools/workspace/nanoflann_internal:repository.bzl", "nanoflann_internal_repository") # noqa 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 @@ -278,8 +278,8 @@ def add_default_repositories(excludes = [], mirrors = DEFAULT_MIRRORS): mypy_extensions_internal_repository(name = "mypy_extensions_internal", mirrors = mirrors) # noqa if "mypy_internal" not in excludes: mypy_internal_repository(name = "mypy_internal", mirrors = mirrors) - if "nanoflann" not in excludes: - nanoflann_repository(name = "nanoflann", mirrors = mirrors) + if "nanoflann_internal" not in excludes: + nanoflann_internal_repository(name = "nanoflann_internal", mirrors = mirrors) # noqa if "net_sf_jchart2d" not in excludes: net_sf_jchart2d_repository(name = "net_sf_jchart2d", mirrors = mirrors) if "nlopt" not in excludes: diff --git a/tools/workspace/nanoflann/BUILD.bazel b/tools/workspace/nanoflann_internal/BUILD.bazel similarity index 100% rename from tools/workspace/nanoflann/BUILD.bazel rename to tools/workspace/nanoflann_internal/BUILD.bazel diff --git a/tools/workspace/nanoflann/package.BUILD.bazel b/tools/workspace/nanoflann_internal/package.BUILD.bazel similarity index 82% rename from tools/workspace/nanoflann/package.BUILD.bazel rename to tools/workspace/nanoflann_internal/package.BUILD.bazel index 3f98490cb4f0..5d7b8eca81ef 100644 --- a/tools/workspace/nanoflann/package.BUILD.bazel +++ b/tools/workspace/nanoflann_internal/package.BUILD.bazel @@ -12,8 +12,8 @@ package(default_visibility = ["//visibility:public"]) cc_library( name = "nanoflann", hdrs = ["include/nanoflann.hpp"], - includes = ["include"], - deps = [], + include_prefix = "drake_vendor", + strip_include_prefix = "include", linkstatic = 1, ) diff --git a/tools/workspace/nanoflann_internal/patches/namespace.patch b/tools/workspace/nanoflann_internal/patches/namespace.patch new file mode 100644 index 000000000000..f471a526d45f --- /dev/null +++ b/tools/workspace/nanoflann_internal/patches/namespace.patch @@ -0,0 +1,21 @@ +Add a drake_vendor namespace ala tools/workspace/vendor_cxx + +This prevents link-time symbol conflicts in case code downstream of +Drake wants to use a different build of nanoflann. + +--- include/nanoflann.hpp.orig ++++ include/nanoflann.hpp +@@ -70,6 +70,7 @@ + #endif + #endif + ++inline namespace drake_vendor __attribute__ ((visibility ("hidden"))) { + namespace nanoflann + { + /** @addtogroup nanoflann_grp nanoflann C++ library for ANN +@@ -2414,3 +2415,4 @@ + + /** @} */ // end of grouping + } // namespace nanoflann ++} // namespace drake_vendor +\ No newline at end of file diff --git a/tools/workspace/nanoflann/repository.bzl b/tools/workspace/nanoflann_internal/repository.bzl similarity index 79% rename from tools/workspace/nanoflann/repository.bzl rename to tools/workspace/nanoflann_internal/repository.bzl index 96f3ada3ea11..c7ec1f138668 100644 --- a/tools/workspace/nanoflann/repository.bzl +++ b/tools/workspace/nanoflann_internal/repository.bzl @@ -2,7 +2,7 @@ load("@drake//tools/workspace:github.bzl", "github_archive") -def nanoflann_repository( +def nanoflann_internal_repository( name, mirrors = None): github_archive( @@ -11,5 +11,8 @@ def nanoflann_repository( commit = "v1.4.3", sha256 = "cbcecf22bec528a8673a113ee9b0e134f91f1f96be57e913fa1f74e98e4449fa", # noqa build_file = ":package.BUILD.bazel", + patches = [ + ":patches/namespace.patch", + ], mirrors = mirrors, )