Skip to content

Commit

Permalink
[workspace] Build tinyxml2 from source (#17830)
Browse files Browse the repository at this point in the history
* [workspace] Build tinyxml2 from source

Deprecate the repository rule for the OS library.
  • Loading branch information
jwnimmer-tri authored Sep 6, 2022
1 parent a23c0fd commit 78eaea8
Show file tree
Hide file tree
Showing 24 changed files with 113 additions and 118 deletions.
1 change: 0 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ install(
"//lcmtypes:install",
"//manipulation/models:install_data",
"//setup:install",
"//tools/install/cmake:install",
"//tools/install/libdrake:install",
"//tools/workspace:install_external_packages",
"//tutorials:install",
Expand Down
8 changes: 4 additions & 4 deletions multibody/parsing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ drake_cc_library(
deps = [
"//common",
"//common:filesystem",
"@tinyxml2",
"@tinyxml2_internal//:tinyxml2",
],
)

Expand Down Expand Up @@ -98,7 +98,7 @@ drake_cc_library(
"//math:geometric_transform",
"//multibody/plant",
"@sdformat_internal//:sdformat",
"@tinyxml2",
"@tinyxml2_internal//:tinyxml2",
],
)

Expand Down Expand Up @@ -169,7 +169,7 @@ drake_cc_library(
":scoped_names",
"//common:filesystem",
"@fmt",
"@tinyxml2",
"@tinyxml2_internal//:tinyxml2",
],
)

Expand All @@ -184,7 +184,7 @@ drake_cc_library(
":scoped_names",
"//multibody/plant",
"@fmt",
"@tinyxml2",
"@tinyxml2_internal//:tinyxml2",
],
)

Expand Down
2 changes: 1 addition & 1 deletion multibody/parsing/detail_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <variant>

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

#include "drake/common/diagnostic_policy.h"
#include "drake/common/drake_copyable.h"
Expand Down
2 changes: 1 addition & 1 deletion multibody/parsing/detail_mujoco_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <utility>
#include <vector>

#include <drake_vendor/tinyxml2.h>
#include <fmt/format.h>
#include <tinyxml2.h>

#include "drake/geometry/shape_specification.h"
#include "drake/math/rigid_transform.h"
Expand Down
2 changes: 1 addition & 1 deletion multibody/parsing/detail_tinyxml.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <vector>

#include <Eigen/Dense>
#include <tinyxml2.h>
#include <drake_vendor/tinyxml2.h>

#include "drake/common/diagnostic_policy.h"
#include "drake/math/rigid_transform.h"
Expand Down
2 changes: 1 addition & 1 deletion multibody/parsing/detail_tinyxml2_diagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <string>

#include <tinyxml2.h>
#include <drake_vendor/tinyxml2.h>

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

#include <Eigen/Dense>
#include <tinyxml2.h>
#include <drake_vendor/tinyxml2.h>

#include "drake/common/diagnostic_policy.h"
#include "drake/geometry/geometry_instance.h"
Expand Down
2 changes: 1 addition & 1 deletion multibody/parsing/detail_urdf_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include <vector>

#include <Eigen/Dense>
#include <drake_vendor/tinyxml2.h>
#include <fmt/format.h>
#include <tinyxml2.h>

#include "drake/common/sorted_pair.h"
#include "drake/math/rotation_matrix.h"
Expand Down
2 changes: 1 addition & 1 deletion multibody/parsing/package_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <tuple>
#include <utility>

#include <tinyxml2.h>
#include <drake_vendor/tinyxml2.h>

#include "drake/common/drake_assert.h"
#include "drake/common/drake_path.h"
Expand Down
2 changes: 2 additions & 0 deletions setup/mac/binary_distribution/Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ brew '[email protected]'
brew 'spdlog'
brew 'suite-sparse'
brew 'tinyxml'
# TODO(jwnimmer-tri) Drop tinyxml2 as of the deprecation 2023-01-01.
# Ditto for the Ubuntu prereqs.
brew 'tinyxml2'
brew 'robotlocomotion/director/[email protected]'
brew 'xz'
Expand Down
16 changes: 0 additions & 16 deletions tools/install/cmake/BUILD.bazel

This file was deleted.

67 changes: 0 additions & 67 deletions tools/install/cmake/FindTinyXML2.cmake

This file was deleted.

1 change: 0 additions & 1 deletion tools/install/libdrake/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ cc_library(
"//common:drake_marker_shared_library",
"@lcm",
"@spdlog",
"@tinyxml2",
],
)

Expand Down
3 changes: 1 addition & 2 deletions tools/install/libdrake/drake-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ find_dependency(fmt 6.0 CONFIG HINTS "${${CMAKE_FIND_PACKAGE_NAME}_IMPORT_PREFIX
find_dependency(lcm 1.4 CONFIG HINTS "${${CMAKE_FIND_PACKAGE_NAME}_IMPORT_PREFIX}/lib/cmake/lcm")
find_dependency(optitrack CONFIG HINTS "${${CMAKE_FIND_PACKAGE_NAME}_IMPORT_PREFIX}/lib/cmake/optitrack")
find_dependency(spdlog 1.5 CONFIG HINTS "${${CMAKE_FIND_PACKAGE_NAME}_IMPORT_PREFIX}/lib/cmake/spdlog")
find_dependency(TinyXML2 2.2 MODULE)
set(_expectedTargets drake::drake drake::drake-lcmtypes-cpp drake::drake-lcmtypes-java drake::drake-marker)

set(_targetsDefined)
Expand Down Expand Up @@ -62,7 +61,7 @@ set_target_properties(drake::drake PROPERTIES
IMPORTED_LOCATION "${${CMAKE_FIND_PACKAGE_NAME}_IMPORT_PREFIX}/lib/libdrake.so"
IMPORTED_SONAME "${_apple_soname_prologue}libdrake.so"
INTERFACE_INCLUDE_DIRECTORIES "${${CMAKE_FIND_PACKAGE_NAME}_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "drake::drake-lcmtypes-cpp;drake::drake-marker;Eigen3::Eigen;fmt::fmt-header-only;lcm::lcm;optitrack::optitrack-lcmtypes-cpp;spdlog::spdlog;tinyxml2::tinyxml2"
INTERFACE_LINK_LIBRARIES "drake::drake-lcmtypes-cpp;drake::drake-marker;Eigen3::Eigen;fmt::fmt-header-only;lcm::lcm;optitrack::optitrack-lcmtypes-cpp;spdlog::spdlog"
INTERFACE_COMPILE_FEATURES "cxx_std_17"
INTERFACE_COMPILE_DEFINITIONS "HAVE_SPDLOG"
)
Expand Down
7 changes: 0 additions & 7 deletions tools/wheel/image/dependencies/projects.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ set(libtiff_url "http://download.osgeo.org/libtiff/tiff-${libtiff_version}.tar.g
set(libtiff_md5 "2165e7aba557463acc0664e71a3ed424")
list(APPEND ALL_PROJECTS libtiff)

# tinyxml2
set(tinyxml2_version 7.0.1)
set(tinyxml2_url "https://github.com/leethomason/tinyxml2/archive/${tinyxml2_version}.zip")
set(tinyxml2_md5 "03ad292c4b6454702c0cc22de0d196ad")
set(tinyxml2_dlname "tinyXML2.zip")
list(APPEND ALL_PROJECTS tinyxml2)

# msgpack
set(msgpack_version 3.1.0)
set(msgpack_url "https://github.com/msgpack/msgpack-c/releases/download/cpp-${msgpack_version}/msgpack-${msgpack_version}.tar.gz")
Expand Down
12 changes: 0 additions & 12 deletions tools/wheel/image/dependencies/projects/tinyxml2.cmake

This file was deleted.

1 change: 1 addition & 0 deletions tools/workspace/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ _DRAKE_EXTERNAL_PACKAGE_INSTALLS = ["@%s//:install" % p for p in [
"spdlog",
"statsjs",
"tinyobjloader",
"tinyxml2_internal",
"usockets",
"uwebsockets",
"vtk",
Expand Down
3 changes: 3 additions & 0 deletions tools/workspace/default.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ load("@drake//tools/workspace/styleguide:repository.bzl", "styleguide_repository
load("@drake//tools/workspace/suitesparse:repository.bzl", "suitesparse_repository") # noqa
load("@drake//tools/workspace/tinyobjloader:repository.bzl", "tinyobjloader_repository") # noqa
load("@drake//tools/workspace/tinyxml2:repository.bzl", "tinyxml2_repository")
load("@drake//tools/workspace/tinyxml2_internal:repository.bzl", "tinyxml2_internal_repository") # noqa
load("@drake//tools/workspace/tomli_internal:repository.bzl", "tomli_internal_repository") # noqa
load("@drake//tools/workspace/typing_extensions_internal:repository.bzl", "typing_extensions_internal_repository") # noqa
load("@drake//tools/workspace/uritemplate_py_internal:repository.bzl", "uritemplate_py_internal_repository") # noqa
Expand Down Expand Up @@ -353,6 +354,8 @@ def add_default_repositories(excludes = [], mirrors = DEFAULT_MIRRORS):
tinyobjloader_repository(name = "tinyobjloader", mirrors = mirrors)
if "tinyxml2" not in excludes:
tinyxml2_repository(name = "tinyxml2")
if "tinyxml2_internal" not in excludes:
tinyxml2_internal_repository(name = "tinyxml2_internal", mirrors = mirrors) # noqa
if "tomli_internal" not in excludes:
tomli_internal_repository(name = "tomli_internal", mirrors = mirrors)
if "typing_extensions_internal" not in excludes:
Expand Down
3 changes: 2 additions & 1 deletion tools/workspace/sdformat_internal/package.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ cc_library_vendored(
"sdf/": "drake_vendor/sdf/",
"ignition/math/": "drake_vendor/ignition/math/",
"ignition/utils/": "drake_vendor/ignition/utils/",
"tinyxml2": "drake_vendor/tinyxml2",
},
includes = ["drake_src"],
copts = ["-w"],
Expand All @@ -274,7 +275,7 @@ cc_library_vendored(
deps = [
"@gz_math_internal//:gz_math",
"@gz_utils_internal//:gz_utils",
"@tinyxml2",
"@tinyxml2_internal//:tinyxml2",
# N.B. It's very unusual to add a dependency from a third-party library
# onto Drake, but in this case it's the simplest way to be able to send
# error messages from sdformat parsing into Drake's logging API.
Expand Down
1 change: 1 addition & 0 deletions tools/workspace/tinyxml2/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ def tinyxml2_repository(
licenses = licenses,
modname = modname,
pkg_config_paths = pkg_config_paths,
extra_deprecation = "DRAKE DEPRECATED: The @tinyxml2 alias for the operating system's library is no longer used by Drake. If you still use it, you may copy the @tinyxml2 repository rule into your own project. This target will be removed from Drake on or after 2023-01-01.", # noqa
**kwargs
)
5 changes: 5 additions & 0 deletions tools/workspace/tinyxml2_internal/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- python -*-

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

add_lint_tests()
25 changes: 25 additions & 0 deletions tools/workspace/tinyxml2_internal/package.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- python -*-

load(
"@drake//tools/install:install.bzl",
"install",
)

licenses(["notice"]) # zlib

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

cc_library(
name = "tinyxml2",
hdrs = ["tinyxml2.h"],
srcs = ["tinyxml2.cpp"],
include_prefix = "drake_vendor",
linkstatic = 1,
visibility = ["//visibility:public"],
)

install(
name = "install",
docs = ["LICENSE.txt"],
visibility = ["//visibility:public"],
)
44 changes: 44 additions & 0 deletions tools/workspace/tinyxml2_internal/patches/namespace.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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 tinyxml2.

Note that the upstream source repository contains windows newlines
throughout, so we need to entertain `^M` shrapnel throughout this
patch file.

--- tinyxml2.h.orig 2021-06-06 17:10:24.000000000 -0700
+++ tinyxml2.h 2022-09-03 07:30:36.319764029 -0700
@@ -42,6 +42,8 @@
#endif
#include <stdint.h>

+inline namespace drake_vendor __attribute__ ((visibility ("hidden"))) {
+
/*
TODO: intern strings instead of allocation.
*/
@@ -2377,4 +2379,6 @@
# pragma warning(pop)
#endif

+} // namespace drake_vendor
+
#endif // TINYXML2_INCLUDED
--- tinyxml2.cpp.orig 2021-06-06 17:10:24.000000000 -0700
+++ tinyxml2.cpp 2022-09-03 07:31:12.036248705 -0700
@@ -32,6 +32,8 @@
# include <cstdarg>
#endif

+inline namespace drake_vendor __attribute__ ((visibility ("hidden"))) {
+
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
// Microsoft Visual Studio, version 2005 and higher. Not WinCE.
/*int _snprintf_s(
@@ -2984,3 +2986,5 @@
}

} // namespace tinyxml2
+
+} // namespace drake_vendor
18 changes: 18 additions & 0 deletions tools/workspace/tinyxml2_internal/repository.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- python -*-

load("@drake//tools/workspace:github.bzl", "github_archive")

def tinyxml2_internal_repository(
name,
mirrors = None):
github_archive(
name = name,
repository = "leethomason/tinyxml2",
commit = "9.0.0",
sha256 = "cc2f1417c308b1f6acc54f88eb70771a0bf65f76282ce5c40e54cfe52952702c", # noqa
build_file = ":package.BUILD.bazel",
patches = [
":patches/namespace.patch",
],
mirrors = mirrors,
)

0 comments on commit 78eaea8

Please sign in to comment.