Skip to content

Commit 98d242c

Browse files
authored
Add OpenUSD module (#6532)
This adds an OpenUSD module, starting at version 25.11. It provides a target `@openusd//:openusd` to link OpenUSD as a C++ static library and a target `@openusd//:plugin_files` for specifying the default plugin files as a data dependency. @bazel-io skip_check unstable_url
1 parent 79d90db commit 98d242c

File tree

8 files changed

+292
-0
lines changed

8 files changed

+292
-0
lines changed

modules/openusd/25.11/MODULE.bazel

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module(
2+
name = "openusd",
3+
version = "25.11",
4+
# Required to be able to use the 'overlay' files feature of BCR
5+
bazel_compatibility = ['>=7.2.1'],
6+
)
7+
bazel_dep(name = "onetbb", version = "2022.1.0")
8+
9+
bazel_dep(name = "rules_foreign_cc", version = "0.15.1")
10+
bazel_dep(name = "rules_cc", version = "0.2.14")
11+
bazel_dep(name = "rules_license", version = "1.0.0")
12+
bazel_dep(name = "platforms", version = "1.0.0")
13+
bazel_dep(name = "bazel_lib", version = "3.0.0")
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
2+
load("@rules_cc//cc:defs.bzl", "cc_test")
3+
load("@rules_cc//cc:defs.bzl", "cc_binary")
4+
load("@rules_license//rules:license.bzl", "license")
5+
load("@bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
6+
7+
package(
8+
default_applicable_licenses = [":license"],
9+
default_visibility = ["//visibility:public"],
10+
)
11+
12+
exports_files(["LICENSE.txt"])
13+
14+
# Note: OpenUSD uses a derivative of the Apache 2.0 license called the
15+
# Tomorrow Open Source Technology License 1.0.
16+
license(
17+
name = "license",
18+
package_name = "openusd",
19+
license_kinds = [
20+
],
21+
license_text = ":LICENSE.txt",
22+
)
23+
24+
filegroup(
25+
name = "all_srcs",
26+
srcs = glob([
27+
"CMakeLists.txt",
28+
"pxr/**",
29+
"cmake/**",
30+
"extras/**",
31+
"docs/**",
32+
"third_party/**"
33+
], exclude=[
34+
"bazel*/**",
35+
"BUILD",
36+
"BUILD.bazel",
37+
"MODULE.bazel"
38+
]),
39+
visibility = ["//visibility:public"],
40+
)
41+
42+
# Build OpenUSD as a monolithic static library. This is the simplest option for linking
43+
# but note it does not allow USD plugins or Python modules. This is because it would result in duplicate
44+
# symbol definitions for libusd symbols (statically linked into the main exec and also linked into the dynamic libs).
45+
#
46+
# Also note: We must specify the alwayslink=True so that dependents link in all symbols from the archive. This is
47+
# a stated requirement in BUILDING.md. If not specified, OpenUSD will not initialize properly and you will encounter
48+
# segfaults when using certain objects.
49+
#
50+
# See BUILDING.md in the OpenUSD repo for details.
51+
#
52+
cmake(
53+
name = "openusd",
54+
cache_entries = {
55+
"BUILD_SHARED_LIBS": "OFF",
56+
"PXR_BUILD_MONOLITHIC": "ON",
57+
"PXR_PREFER_SAFETY_OVER_SPEED": "ON",
58+
"PXR_FIND_TBB_IN_CONFIG": "OFF",
59+
"TBB_USE_DEBUG_BUILD": "OFF",
60+
"PXR_ENABLE_PYTHON_SUPPORT": "OFF",
61+
"PXR_ENABLE_GL_SUPPORT": "OFF",
62+
"PXR_ENABLE_METAL_SUPPORT": "OFF",
63+
"PXR_BUILD_DOCUMENTATION": "OFF",
64+
"PXR_BUILD_HTML_DOCUMENTATION": "OFF",
65+
"PXR_BUILD_PYTHON_DOCUMENTATION": "OFF",
66+
"PXR_BUILD_TESTS": "OFF",
67+
"PXR_BUILD_EXAMPLES": "OFF",
68+
"PXR_BUILD_TUTORIALS": "OFF",
69+
"PXR_BUILD_USD_TOOLS": "OFF",
70+
"PXR_BUILD_USD_VALIDATION": "OFF",
71+
"PXR_BUILD_IMAGING": "OFF",
72+
"PXR_BUILD_USD_IMAGING": "OFF",
73+
"PXR_BUILD_USDVIEW": "OFF",
74+
"PXR_BUILD_ALEMBIC_PLUGIN": "OFF",
75+
"PXR_BUILD_DRACO_PLUGIN": "OFF",
76+
"PXR_ENABLE_MATERIALX_SUPPORT": "OFF",
77+
"PXR_BUILD_MAYAPY_TESTS": "OFF",
78+
"PXR_BUILD_ANIMX_TESTS": "OFF",
79+
"Boost_NO_SYSTEM_PATHS": "ON",
80+
},
81+
env = {
82+
"CMAKE_BUILD_TYPE": "Release",
83+
"CMAKE_BUILD_PARALLEL_LEVEL": "4",
84+
},
85+
alwayslink = True,
86+
out_static_libs = [
87+
# This is name of the monolithic static lib.
88+
"libusd_m.a",
89+
],
90+
out_data_dirs = [
91+
"lib/usd"
92+
],
93+
lib_source = ":all_srcs",
94+
deps = [
95+
"@onetbb//:tbb",
96+
],
97+
)
98+
99+
# As part of the cmake build, OpenUSD installs a directory of plugin file resources (many plugInfo.json files)
100+
# to openusd/lib/usd. On program startup, OpenUSD expects these plugin files to be in a usd/ dir directly next
101+
# to the executable or .so library. It will throw an exception and crash if they are not found.
102+
# We use the 'copy_to_directory' helper to copy them out of 'openusd/lib/usd' to just 'usd' so that they
103+
# are at the right path.
104+
copy_to_directory(
105+
name = "plugin_files",
106+
srcs = [":openusd"],
107+
out = "usd",
108+
replace_prefixes = {
109+
"openusd/lib/usd": "",
110+
}
111+
)
112+
113+
cc_test(
114+
name = "test_main",
115+
srcs = ["test_main.cpp"],
116+
deps = [
117+
":openusd",
118+
"@bazel_tools//tools/cpp/runfiles",
119+
],
120+
data = [
121+
":plugin_files",
122+
]
123+
)
124+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module(
2+
name = "openusd",
3+
version = "25.11",
4+
# Required to be able to use the 'overlay' files feature of BCR
5+
bazel_compatibility = ['>=7.2.1'],
6+
)
7+
bazel_dep(name = "onetbb", version = "2022.1.0")
8+
9+
bazel_dep(name = "rules_foreign_cc", version = "0.15.1")
10+
bazel_dep(name = "rules_cc", version = "0.2.14")
11+
bazel_dep(name = "rules_license", version = "1.0.0")
12+
bazel_dep(name = "platforms", version = "1.0.0")
13+
bazel_dep(name = "bazel_lib", version = "3.0.0")
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <iostream>
2+
3+
#include <pxr/usd/usd/stage.h>
4+
#include <pxr/usd/usdGeom/sphere.h>
5+
#include <pxr/base/tf/token.h>
6+
#include <pxr/base/plug/registry.h>
7+
8+
#include "tools/cpp/runfiles/runfiles.h"
9+
10+
using bazel::tools::cpp::runfiles::Runfiles;
11+
12+
int main(int argc, char** argv) {
13+
std::cout << "--- USD Initialization Test ---\n";
14+
15+
// Use the bazel runfiles lib to get the path to the openusd plugins that this
16+
// executable depends on. Use Create() for regular binaries and CreateForTest()
17+
// for tests.
18+
std::string error;
19+
//std::unique_ptr<Runfiles> runfiles(Runfiles::Create(argv[0], &error));
20+
std::unique_ptr<Runfiles> runfiles(Runfiles::CreateForTest(&error));
21+
if (runfiles == nullptr) {
22+
std::cout << "NO RUNFILES FOUND" << std::endl;
23+
return 1;
24+
}
25+
26+
// Register our custom plugins path with the plugin registry.
27+
// If we do not do this, OpenUSD will throw when creating a stage.
28+
std::string pluginsPath = runfiles->Rlocation("usd");
29+
std::cout << "PATH to openusd/usd => " << pluginsPath << std::endl;
30+
pxr::PlugRegistry::GetInstance().RegisterPlugins(pluginsPath);
31+
32+
// Create a USD Stage (the core container for a scene)
33+
auto stage = pxr::UsdStage::CreateNew(std::string("HelloWorld.usda"));
34+
if (stage) {
35+
// Create a primary root primitive (like a scene root)
36+
pxr::SdfPath primPath("/World/MyFirstPrim");
37+
pxr::UsdGeomSphere sphere =
38+
pxr::UsdGeomSphere::Define(stage, primPath);
39+
std::cout << "Successfully created a primitive at path: "
40+
<< sphere.GetPath().GetString() << "\n";
41+
42+
// Print a tftoken
43+
pxr::TfToken myToken("Success!");
44+
std::cout << "TfToken status: " << myToken.GetString() << "\n";
45+
} else {
46+
std::cerr << "ERROR: Failed to create an in-memory USD stage!\n";
47+
return 1;
48+
}
49+
50+
std::cout << "--- USD Test Complete ---\n";
51+
return 0;
52+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
matrix:
2+
platform:
3+
- ubuntu2204
4+
bazel:
5+
- 8.x
6+
tasks:
7+
verify_targets:
8+
name: Verify build targets
9+
platform: ${{ platform }}
10+
bazel: ${{ bazel }}
11+
build_targets:
12+
- '@openusd//:openusd'
13+
run_test_module:
14+
name: Run tests
15+
platform: ${{ platform }}
16+
bazel: ${{ bazel }}
17+
test_targets:
18+
- "@openusd//:test_main"

modules/openusd/25.11/source.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"url": "https://github.com/PixarAnimationStudios/OpenUSD/archive/refs/tags/v25.11.tar.gz",
3+
"integrity": "sha256-w3xjO1A3pFUvYVdGcOzKiDYim3gya9YmIvNCJnEYhmc=",
4+
"strip_prefix": "OpenUSD-25.11",
5+
"patch_strip": 0,
6+
"overlay": {
7+
"BUILD": "sha256-3rvywJSRTrPiFJr7Slalx9mPdROBi0gxlewue6exVag=",
8+
"MODULE.bazel": "sha256-7BYW8wgXpTMSAH+vpWLi9HTwPlQ5iyKzsbbDZSYrmq4=",
9+
"test_main.cpp": "sha256-5hfksFp7KzvT01pbtvmOz432CBbb2fBOd3bhsy3oiSw="
10+
}
11+
}

modules/openusd/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# OpenUSD
2+
3+
## Overview
4+
5+
This module allows linking a minimal build of OpenUSD as a static monolithic library. OpenUSD supports many optional addons and plugins, including Python support, but
6+
those are disabled here. Please refer to the README and BUILDING.md files of the OpenUSD repo on GitHub if you require a different build.
7+
8+
As explained in the OpenUSD BUILDING.md, there are several different ways to build OpenUSD (static vs shared and monolithic vs split-up). This Bazel module builds it
9+
as a monolithic static library, for ease of use.
10+
11+
Note: We currently only support building for linux.
12+
13+
## Working with this BCR module
14+
15+
If you must modify or update this BCR module, first read these docs:
16+
https://github.com/bazelbuild/bazel-central-registry/blob/main/docs/README.md
17+
https://bazel.build/external/registry
18+
19+
Commands cheat-sheet:
20+
21+
Run this to create a new BCR version:
22+
bazel run //tools:add_module
23+
24+
Run this to update the integrity checksums in the source.json (for patches and overlay files):
25+
bazel run -- //tools:update_integrity openusd
26+
27+
Run the validations:
28+
bazel run -- //tools:bcr_validation [email protected]
29+
30+
### Testing Locally
31+
32+
To test the module locally, run this:
33+
34+
Run:
35+
bazel shutdown && bazel build --enable_bzlmod --registry="file:///usr/local/google/home/mattriley/bazel-central-registry" --lockfile_mode=off //:main
36+
Or just:
37+
bazel test --enable_bzlmod --registry="file:///usr/local/google/home/mattriley/bazel-central-registry" --lockfile_mode=off //:test_main

modules/openusd/metadata.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"homepage": "https://openusd.org/release/index.html",
3+
"maintainers": [
4+
{
5+
"email": "[email protected]",
6+
"github": "mgriley",
7+
"github_user_id": 13209161,
8+
"name": "Matthew Riley"
9+
},
10+
{
11+
"email": "[email protected]",
12+
"github": "dgoel",
13+
"github_user_id": 834379,
14+
"name": "Dhiraj Goel"
15+
}
16+
],
17+
"repository": [
18+
"github:PixarAnimationStudios/OpenUSD"
19+
],
20+
"versions": [
21+
"25.11"
22+
],
23+
"yanked_versions": {}
24+
}

0 commit comments

Comments
 (0)