Skip to content

Commit

Permalink
[workspace] Add OpenUSD as an optional dependency (RobotLocomotion#20923
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jwnimmer-tri authored Feb 19, 2024
1 parent 9560a0a commit 84cc25a
Show file tree
Hide file tree
Showing 15 changed files with 2,700 additions and 4 deletions.
9 changes: 9 additions & 0 deletions tools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,13 @@ config_setting(
values = {"define": "NO_SCS=ON"},
)

# We are exploring adding USD support to Drake. For the moment, it is opt-in.
# See https://github.com/PixarAnimationStudios/OpenUSD for details.
# Use `--define=WITH_USD=ON` on the bazel command line to enable it.
# (In CI, --config=everything also enables it on Ubuntu.)
config_setting(
name = "with_usd",
values = {"define": "WITH_USD=ON"},
)

add_lint_tests()
4 changes: 4 additions & 0 deletions tools/ubuntu-jammy.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ build:clang --action_env=CC=clang-14
build:clang --action_env=CXX=clang++-14
build:clang --host_action_env=CC=clang-14
build:clang --host_action_env=CXX=clang++-14

# In CI (but only in CI), we want to test the opt-in USD build support.
# TODO(jwnimmer-tri) We should try to enable USD by default on all platforms.
build:everything --define=WITH_USD=ON
4 changes: 4 additions & 0 deletions tools/ubuntu-noble.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ build:clang --action_env=CC=clang-14
build:clang --action_env=CXX=clang++-14
build:clang --host_action_env=CC=clang-14
build:clang --host_action_env=CXX=clang++-14

# In CI (but only in CI), we want to test the opt-in USD build support.
# TODO(jwnimmer-tri) We should try to enable USD by default on all platforms.
build:everything --define=WITH_USD=ON
6 changes: 3 additions & 3 deletions tools/workspace/cmake_configure_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ def _transform_autoconf(*, line, definitions, strict):
return line, used_vars


# Looks like "set(VAR value)".
_set_var = re.compile(r'^\s*set\s*\(\s*(.+)\s+(.+)\s*\)\s*$')
# Looks like "set(VAR value)", maybe with an end-of-line comment.
_set_var = re.compile(r'^\s*set\s*\(\s*(.+)\s+(.+)\s*\)\s*(#.*)?$')


# From a line of CMakeLists.txt, return a set(...) key-value pair, if found.
def _extract_definition(line, prior_definitions):
match = _set_var.match(line)
if not match:
return dict()
var, value = match.groups()
var, value, _ = match.groups()
try:
value, _ = _transform_cmake(
line=value,
Expand Down
6 changes: 6 additions & 0 deletions tools/workspace/default.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ load("//tools/workspace/nasm:repository.bzl", "nasm_repository")
load("//tools/workspace/net_sf_jchart2d:repository.bzl", "net_sf_jchart2d_repository") # noqa
load("//tools/workspace/nlohmann_internal:repository.bzl", "nlohmann_internal_repository") # noqa
load("//tools/workspace/nlopt_internal:repository.bzl", "nlopt_internal_repository") # noqa
load("//tools/workspace/onetbb_internal:repository.bzl", "onetbb_internal_repository") # noqa
load("//tools/workspace/openblas:repository.bzl", "openblas_repository")
load("//tools/workspace/opencl:repository.bzl", "opencl_repository")
load("//tools/workspace/opengl:repository.bzl", "opengl_repository")
load("//tools/workspace/openusd_internal:repository.bzl", "openusd_internal_repository") # noqa
load("//tools/workspace/org_apache_xmlgraphics_commons:repository.bzl", "org_apache_xmlgraphics_commons_repository") # noqa
load("//tools/workspace/osqp_internal:repository.bzl", "osqp_internal_repository") # noqa
load("//tools/workspace/picosha2_internal:repository.bzl", "picosha2_internal_repository") # noqa
Expand Down Expand Up @@ -239,12 +241,16 @@ def add_default_repositories(excludes = [], mirrors = DEFAULT_MIRRORS):
nlohmann_internal_repository(name = "nlohmann_internal", mirrors = mirrors) # noqa
if "nlopt_internal" not in excludes:
nlopt_internal_repository(name = "nlopt_internal", mirrors = mirrors)
if "onetbb_internal" not in excludes:
onetbb_internal_repository(name = "onetbb_internal", mirrors = mirrors)
if "openblas" not in excludes:
openblas_repository(name = "openblas")
if "opencl" not in excludes:
opencl_repository(name = "opencl")
if "opengl" not in excludes:
opengl_repository(name = "opengl")
if "openusd_internal" not in excludes:
openusd_internal_repository(name = "openusd_internal", mirrors = mirrors) # noqa
if "org_apache_xmlgraphics_commons" not in excludes:
org_apache_xmlgraphics_commons_repository(name = "org_apache_xmlgraphics_commons", mirrors = mirrors) # noqa
if "osqp_internal" not in excludes:
Expand Down
3 changes: 2 additions & 1 deletion tools/workspace/mosek/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def _impl(repository_ctx):
else:
files = [
# We use the the MOSEK™ copy of libtbb. The version of libtbb
# available in Ubuntu is too old.
# available in Ubuntu is too old. Anytime we change this, we must
# also sync our @onetbb_internal version number to match this.
"bin/libtbb.so.12",
"bin/libtbb.so.12.8",
"bin/libmosek64.so.{}.{}".format(
Expand Down
3 changes: 3 additions & 0 deletions tools/workspace/onetbb_internal/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
load("//tools/lint:lint.bzl", "add_lint_tests")

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

cc_library(
name = "tbb",
hdrs = glob([
"include/oneapi/*.h",
"include/oneapi/tbb/*.h",
"include/oneapi/tbb/detail/*.h",
]),
includes = [
"include/oneapi",
],
deps = [
# TODO(jwnimmer-tri) This should just be the TBB runtime, not the
# entirety of MOSEK. We'll need to clean that up before we enable
# WITH_USD in Drake's installed packages.
"@mosek",
],
visibility = ["//visibility:public"],
)
17 changes: 17 additions & 0 deletions tools/workspace/onetbb_internal/repository.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("//tools/workspace:github.bzl", "github_archive")

def onetbb_internal_repository(
name,
mirrors = None):
github_archive(
name = name,
repository = "oneapi-src/oneTBB",
commit = "v2021.8.0",
# TODO(jwnimmer-tri) We are using the TBB headers from this repository,
# but the TBB library from MOSEK's binary release. We'll probably need
# some tooling to keep all of that in sync, but for now we'll just pin.
commit_pin = 1,
sha256 = "eee380323bb7ce864355ed9431f85c43955faaae9e9bce35c62b372d7ffd9f8b", # noqa
build_file = ":package.BUILD.bazel",
mirrors = mirrors,
)
33 changes: 33 additions & 0 deletions tools/workspace/openusd_internal/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load("//tools/workspace:generate_file.bzl", "generate_file")
load("//tools/lint:lint.bzl", "add_lint_tests")

# TODO(jwnimmer-tri) To prove that the @openusd_internal build system is
# working properly, here we perform a smoke test of `usdcat --help`. Once
# we have enough real unit tests in Drake that call into USD and prove out
# the build, we should remove this simple smoke test.

alias(
name = "usdcat",
actual = "@openusd_internal//:usdcat",
tags = [
# Only compile this binary when the usdcat_help test needs it.
"manual",
],
)

generate_file(
name = "empty.sh",
# When WITH_USD is off, this serves as a test stub dummy.
content = "echo 'WITH_USD is not ON'",
)

sh_test(
name = "usdcat_help",
srcs = select({
"//tools:with_usd": [":usdcat"],
"//conditions:default": ["empty.sh"],
}),
args = ["--help"],
)

add_lint_tests()
52 changes: 52 additions & 0 deletions tools/workspace/openusd_internal/defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
load("@drake//tools/skylark:cc.bzl", "cc_library")
load("@drake//tools/workspace/openusd_internal:lock/files.bzl", "FILES")

def pxr_library(
name,
*,
subdir):
"""Defines a cc_library in the spirit of OpenUSD's pxr_library CMake macro.
The srcs, hdrs, and deps are not passed as an argument to this function.
Instead, they are loaded from the `lock/files.bzl` database.
Args:
name: Matches the upstream name (the first argument in CMake).
subdir: The subdirectory under `OpenUSD/pxr` (e.g. "base/arch").
"""
attrs = FILES[subdir]
srcs = [
subdir + "/" + x + ".cpp"
for x in attrs["PUBLIC_CLASSES"] + attrs["PRIVATE_CLASSES"]
] + [
subdir + "/" + x
for x in attrs["CPPFILES"]
]
hdrs = [
subdir + "/" + x + ".h"
for x in attrs["PUBLIC_CLASSES"] + attrs["PRIVATE_CLASSES"]
] + [
subdir + "/" + x
for x in attrs["PUBLIC_HEADERS"] + attrs["PRIVATE_HEADERS"]
]
defines = [
# In Drake we use the oneAPI flavor of TBB, which is not the default
# in OpenUSD, so we need to opt-in.
"PXR_ONETBB_SUPPORT_ENABLED",
# OpenUSD still has calls to deprecated TBB functions, so we need to
# opt-in to some vestigial parts of TBB.
"TBB_ALLOCATOR_TRAITS_BROKEN",
]
deps = attrs["LIBRARIES"] + [
":pxr_h",
"@onetbb_internal//:tbb",
# TODO(jwnimmer-tri) We also need to list some @boost here.
]
cc_library(
name = name,
srcs = srcs,
hdrs = hdrs,
defines = defines,
copts = ["-w"],
deps = deps,
)
Loading

0 comments on commit 84cc25a

Please sign in to comment.