Skip to content

Commit

Permalink
[workspace] Use sdformat hidden visibility
Browse files Browse the repository at this point in the history
When building C++ code, we should not use -fvisibility=hidden because
it infects all #included code, even the standard library. Instead, we
should wrap the third-party C++ code in a inline hidden namespace.
That way, only the third-party code itself is hidden.

TODO deprecation
  • Loading branch information
jwnimmer-tri committed May 27, 2022
1 parent 989011e commit 4cc50dd
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 123 deletions.
2 changes: 1 addition & 1 deletion multibody/parsing/detail_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string>
#include <variant>

#include <sdf/Element.hh>
#include <drake_vendor/sdf/Element.hh>
#include <tinyxml2.h>

#include "drake/common/diagnostic_policy.h"
Expand Down
2 changes: 1 addition & 1 deletion multibody/parsing/detail_sdf_diagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <set>
#include <string>

#include <sdf/Element.hh>
#include <drake_vendor/sdf/Element.hh>

#include "drake/common/diagnostic_policy.h"

Expand Down
14 changes: 7 additions & 7 deletions multibody/parsing/detail_sdf_geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
#include <string>
#include <utility>

#include <sdf/Box.hh>
#include <sdf/Capsule.hh>
#include <sdf/Cylinder.hh>
#include <sdf/Element.hh>
#include <sdf/Ellipsoid.hh>
#include <sdf/Plane.hh>
#include <sdf/Sphere.hh>
#include <drake_vendor/sdf/Box.hh>
#include <drake_vendor/sdf/Capsule.hh>
#include <drake_vendor/sdf/Cylinder.hh>
#include <drake_vendor/sdf/Element.hh>
#include <drake_vendor/sdf/Ellipsoid.hh>
#include <drake_vendor/sdf/Plane.hh>
#include <drake_vendor/sdf/Sphere.hh>

#include "drake/geometry/geometry_instance.h"
#include "drake/geometry/proximity_properties.h"
Expand Down
6 changes: 3 additions & 3 deletions multibody/parsing/detail_sdf_geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include <memory>
#include <string>

#include <sdf/Collision.hh>
#include <sdf/Geometry.hh>
#include <sdf/Visual.hh>
#include <drake_vendor/sdf/Collision.hh>
#include <drake_vendor/sdf/Geometry.hh>
#include <drake_vendor/sdf/Visual.hh>

#include "drake/common/diagnostic_policy.h"
#include "drake/geometry/geometry_instance.h"
Expand Down
18 changes: 9 additions & 9 deletions multibody/parsing/detail_sdf_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
#include <variant>
#include <vector>

#include <sdf/Error.hh>
#include <sdf/Frame.hh>
#include <sdf/Joint.hh>
#include <sdf/JointAxis.hh>
#include <sdf/Link.hh>
#include <sdf/Model.hh>
#include <sdf/ParserConfig.hh>
#include <sdf/Root.hh>
#include <sdf/World.hh>
#include <drake_vendor/sdf/Error.hh>
#include <drake_vendor/sdf/Frame.hh>
#include <drake_vendor/sdf/Joint.hh>
#include <drake_vendor/sdf/JointAxis.hh>
#include <drake_vendor/sdf/Link.hh>
#include <drake_vendor/sdf/Model.hh>
#include <drake_vendor/sdf/ParserConfig.hh>
#include <drake_vendor/sdf/Root.hh>
#include <drake_vendor/sdf/World.hh>

#include "drake/geometry/geometry_instance.h"
#include "drake/math/rigid_transform.h"
Expand Down
4 changes: 2 additions & 2 deletions multibody/parsing/test/detail_sdf_geometry_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#include <vector>

#include "fmt/ostream.h"
#include <drake_vendor/sdf/Root.hh>
#include <drake_vendor/sdf/parser.hh>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <sdf/Root.hh>
#include <sdf/parser.hh>

#include "drake/common/filesystem.h"
#include "drake/common/find_resource.h"
Expand Down
2 changes: 1 addition & 1 deletion multibody/parsing/test/detail_sdf_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <sstream>
#include <stdexcept>

#include <drake_vendor/sdf/parser.hh>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <sdf/parser.hh>

#include "drake/common/filesystem.h"
#include "drake/common/find_resource.h"
Expand Down
1 change: 1 addition & 0 deletions tools/workspace/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ drake_py_binary(
name = "vendor_cxx",
srcs = ["vendor_cxx.py"],
visibility = [
"@sdformat//:__pkg__",
"@yaml_cpp_internal//:__pkg__",
],
deps = [":module_py"],
Expand Down
233 changes: 136 additions & 97 deletions tools/workspace/sdformat/package.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ load(
"@drake//tools/install:install.bzl",
"install",
)
load(
"@drake//tools/workspace:vendor_cxx.bzl",
"cc_library_vendored",
)
load("@drake//tools/workspace:generate_file.bzl", "generate_file")

licenses(["notice"]) # Apache-2.0 AND BSD-3-Clause AND BSL-1.0

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

# Generates config.h based on the version numbers in CMake code.
cmake_configure_file(
Expand Down Expand Up @@ -55,7 +59,7 @@ generate_file(
)

# Public headers are indicated in sdformat's `include/sdf/CMakeLists.txt`.
SDFORMAT_MOST_PUBLIC_HDRS = [
_MOST_PUBLIC_HDRS = [
"include/sdf/Actor.hh",
"include/sdf/AirPressure.hh",
"include/sdf/Altimeter.hh",
Expand Down Expand Up @@ -139,107 +143,119 @@ py_binary(
srcs_version = "PY3",
)

SDFORMAT_ALL_PUBLIC_HDRS = SDFORMAT_MOST_PUBLIC_HDRS + [
_HDRS = _MOST_PUBLIC_HDRS + [
"include/sdf/config.hh", # from cmake_configure_file above
"include/sdf/sdf_config.h", # alias to config.hh
"include/sdf/Export.hh", # from generate_file above
]

# Generates the library exported to users. The explicitly listed srcs= matches
# upstream's explicitly listed sources (sdformat/src/CMakeLists.txt), with two
# exceptions: ign.hh and ign.cc are not incorporated in this library, but are
# incorporated into the `ign_sdf_cmdline` library defined below; and the
# parser_urdf.hh and parser_urdf.cc are excluded because we don't use them.
cc_library(
# This list of sources matches upstream's explicitly listed sources
# (sdformat/src/CMakeLists.txt), with two exceptions: ign.hh and ign.cc are not
# incorporated in this library, but are incorporated into the `ign_sdf_cmdline`
# library defined below; and the parser_urdf.hh and parser_urdf.cc are excluded
# because we don't use them.
_SRCS = [
"src/Actor.cc",
"src/AirPressure.cc",
"src/Altimeter.cc",
"src/Atmosphere.cc",
"src/Box.cc",
"src/Camera.cc",
"src/Capsule.cc",
"src/Collision.cc",
"src/Console.cc",
"src/Converter.cc",
"src/Converter.hh",
"src/Cylinder.cc",
"src/Element.cc",
"src/Ellipsoid.cc",
"src/EmbeddedSdf.hh",
"src/Error.cc",
"src/Exception.cc",
"src/Filesystem.cc",
"src/ForceTorque.cc",
"src/Frame.cc",
"src/FrameSemantics.cc",
"src/FrameSemantics.hh",
"src/Geometry.cc",
"src/Gui.cc",
"src/Heightmap.cc",
"src/Imu.cc",
"src/InterfaceElements.cc",
"src/InterfaceFrame.cc",
"src/InterfaceJoint.cc",
"src/InterfaceLink.cc",
"src/InterfaceModel.cc",
"src/InterfaceModelPoseGraph.cc",
"src/Joint.cc",
"src/JointAxis.cc",
"src/Lidar.cc",
"src/Light.cc",
"src/Link.cc",
"src/Magnetometer.cc",
"src/Material.cc",
"src/Mesh.cc",
"src/Model.cc",
"src/NavSat.cc",
"src/Noise.cc",
"src/OutputConfig.cc",
"src/Param.cc",
"src/ParamPassing.cc",
"src/ParamPassing.hh",
"src/ParserConfig.cc",
"src/ParticleEmitter.cc",
"src/Pbr.cc",
"src/Physics.cc",
"src/Plane.cc",
"src/Plugin.cc",
"src/Polyline.cc",
"src/PrintConfig.cc",
"src/Root.cc",
"src/SDF.cc",
"src/SDFExtension.cc",
"src/SDFExtension.hh",
"src/SDFImplPrivate.hh",
"src/Scene.cc",
"src/ScopedGraph.hh",
"src/SemanticPose.cc",
"src/Sensor.cc",
"src/Sky.cc",
"src/Sphere.cc",
"src/Surface.cc",
"src/Types.cc",
"src/Utils.cc",
"src/Utils.hh",
"src/Visual.cc",
"src/World.cc",
"src/XmlUtils.cc",
"src/XmlUtils.hh",
"src/parser.cc",
"src/parser_private.hh",
":src/EmbeddedSdf.cc",
]


# Generates the library exported to users.
cc_library_vendored(
name = "sdformat",
srcs = [
"src/Actor.cc",
"src/AirPressure.cc",
"src/Altimeter.cc",
"src/Atmosphere.cc",
"src/Box.cc",
"src/Camera.cc",
"src/Capsule.cc",
"src/Collision.cc",
"src/Console.cc",
"src/Converter.cc",
"src/Converter.hh",
"src/Cylinder.cc",
"src/Element.cc",
"src/Ellipsoid.cc",
"src/EmbeddedSdf.hh",
"src/Error.cc",
"src/Exception.cc",
"src/Filesystem.cc",
"src/ForceTorque.cc",
"src/Frame.cc",
"src/FrameSemantics.cc",
"src/FrameSemantics.hh",
"src/Geometry.cc",
"src/Gui.cc",
"src/Heightmap.cc",
"src/Imu.cc",
"src/InterfaceElements.cc",
"src/InterfaceFrame.cc",
"src/InterfaceJoint.cc",
"src/InterfaceLink.cc",
"src/InterfaceModel.cc",
"src/InterfaceModelPoseGraph.cc",
"src/Joint.cc",
"src/JointAxis.cc",
"src/Lidar.cc",
"src/Light.cc",
"src/Link.cc",
"src/Magnetometer.cc",
"src/Material.cc",
"src/Mesh.cc",
"src/Model.cc",
"src/NavSat.cc",
"src/Noise.cc",
"src/OutputConfig.cc",
"src/Param.cc",
"src/ParamPassing.cc",
"src/ParamPassing.hh",
"src/ParserConfig.cc",
"src/ParticleEmitter.cc",
"src/Pbr.cc",
"src/Physics.cc",
"src/Plane.cc",
"src/Plugin.cc",
"src/Polyline.cc",
"src/PrintConfig.cc",
"src/Root.cc",
"src/SDF.cc",
"src/SDFExtension.cc",
"src/SDFExtension.hh",
"src/SDFImplPrivate.hh",
"src/Scene.cc",
"src/ScopedGraph.hh",
"src/SemanticPose.cc",
"src/Sensor.cc",
"src/Sky.cc",
"src/Sphere.cc",
"src/Surface.cc",
"src/Types.cc",
"src/Utils.cc",
"src/Utils.hh",
"src/Visual.cc",
"src/World.cc",
"src/XmlUtils.cc",
"src/XmlUtils.hh",
"src/parser.cc",
"src/parser_private.hh",
":src/EmbeddedSdf.cc",
srcs = _SRCS,
srcs_vendored = [
x.replace("src/", "drake_src/src/")
for x in _SRCS
],
hdrs = SDFORMAT_ALL_PUBLIC_HDRS,
# TODO(jamiesnape): Enable visibility after resolving warnings such as
# "Direct access in function means the weak symbol cannot be overridden at
# runtime. This was likely caused by different translation units being
# compiled with different visibility settings."
hdrs = _HDRS,
hdrs_vendored = [
x.replace("include/sdf/", "drake_src/drake_vendor/sdf/")
for x in _HDRS
],
edit_include = {
"sdf/": "drake_vendor/sdf/",
},
includes = ["drake_src"],
copts = ["-w"],
defines = ["SDFORMAT_STATIC_DEFINE", "SDFORMAT_DISABLE_CONSOLE_LOGFILE"],
includes = ["include"],
linkstatic = 1,
visibility = ["//visibility:public"],
deps = [
"@ignition_math",
"@ignition_utils",
Expand All @@ -251,21 +267,44 @@ cc_library(
],
)

_IGN_SRCS = [
"src/ign.cc",
"src/ign.hh",
]

_VENDORED_IGN_SRCS = [
x.replace("src/", "drake_src/src/")
for x in _IGN_SRCS
]

genrule(
name = "vendoring_ign",
srcs = _IGN_SRCS,
outs = _VENDORED_IGN_SRCS,
cmd = " ".join([
"$(execpath @drake//tools/workspace:vendor_cxx)",
"--edit-include=sdf/:drake_vendor/sdf/",
] + [
"$(execpath {}):$(execpath {})".format(old, new)
for old, new in zip(_IGN_SRCS, _VENDORED_IGN_SRCS)
]),
tools = ["@drake//tools/workspace:vendor_cxx"],
)

cc_library(
name = "ign_sdf_cmdline",
srcs = [
"src/ign.cc",
"src/ign.hh",
],
srcs = _VENDORED_IGN_SRCS,
copts = ["-w"],
linkstatic = 1,
visibility = ["@drake//tools/workspace/sdformat:__pkg__"],
deps = [
":sdformat",
],
)

install(
name = "install",
visibility = ["//visibility:public"],
docs = [
"COPYING",
"LICENSE",
Expand Down
Loading

0 comments on commit 4cc50dd

Please sign in to comment.