From c3661c4bca0e71dbbe2fff0a1ee247ddd82fcce4 Mon Sep 17 00:00:00 2001 From: Jeremy Nimmer Date: Wed, 14 Sep 2022 11:34:15 -0700 Subject: [PATCH] link as hidden, vendor the include path --- perception/point_cloud.cc | 2 +- .../nanoflann_internal/package.BUILD.bazel | 4 ++-- .../patches/namespace.patch | 21 +++++++++++++++++++ .../nanoflann_internal/repository.bzl | 3 +++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 tools/workspace/nanoflann_internal/patches/namespace.patch 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/nanoflann_internal/package.BUILD.bazel b/tools/workspace/nanoflann_internal/package.BUILD.bazel index 3f98490cb4f0..5d7b8eca81ef 100644 --- a/tools/workspace/nanoflann_internal/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_internal/repository.bzl b/tools/workspace/nanoflann_internal/repository.bzl index 2bf8e9467cd4..c7ec1f138668 100644 --- a/tools/workspace/nanoflann_internal/repository.bzl +++ b/tools/workspace/nanoflann_internal/repository.bzl @@ -11,5 +11,8 @@ def nanoflann_internal_repository( commit = "v1.4.3", sha256 = "cbcecf22bec528a8673a113ee9b0e134f91f1f96be57e913fa1f74e98e4449fa", # noqa build_file = ":package.BUILD.bazel", + patches = [ + ":patches/namespace.patch", + ], mirrors = mirrors, )