Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions modules/openusd/25.11/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module(
name = "openusd",
version = "25.11",
# Required to be able to use the 'overlay' files feature of BCR
bazel_compatibility = ['>=7.2.1'],
)
bazel_dep(name = "onetbb", version = "2022.1.0")

bazel_dep(name = "rules_foreign_cc", version = "0.15.1")
bazel_dep(name = "rules_cc", version = "0.2.14")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "bazel_lib", version = "3.0.0")
127 changes: 127 additions & 0 deletions modules/openusd/25.11/overlay/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
load("@rules_cc//cc:defs.bzl", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@rules_license//rules:license.bzl", "license")
load("@bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")

package(
default_applicable_licenses = [":license"],
default_visibility = ["//visibility:public"],
)

exports_files(["LICENSE.txt"])

# Note: OpenUSD uses a derivative of the Apache 2.0 license called the
# Tomorrow Open Source Technology License 1.0.
license(
name = "license",
package_name = "openusd",
license_kinds = [
],
license_text = ":LICENSE.txt",
)

filegroup(
name = "all_srcs",
srcs = glob([
"CMakeLists.txt",
"pxr/**",
"cmake/**",
"extras/**",
"docs/**",
"third_party/**"
], exclude=[
"bazel*/**",
"BUILD",
"BUILD.bazel",
"MODULE.bazel"
]),
visibility = ["//visibility:public"],
)

# Build OpenUSD as a monolithic static library. This is the simplest option for linking
# but note it does not allow USD plugins or Python modules. This is because it would result in duplicate
# symbol definitions for libusd symbols (statically linked into the main exec and also linked into the dynamic libs).
#
# Also note: We must specify the alwayslink=True so that dependents link in all symbols from the archive. This is
# a stated requirement in BUILDING.md. If not specified, OpenUSD will not initialize properly and you will encounter
# segfaults when using certain objects.
#
# See BUILDING.md in the OpenUSD repo for details.
#
cmake(
name = "openusd",
build_args = [
"-j16",
],
cache_entries = {
"BUILD_SHARED_LIBS": "OFF",
"PXR_BUILD_MONOLITHIC": "ON",
"PXR_PREFER_SAFETY_OVER_SPEED": "ON",
"PXR_FIND_TBB_IN_CONFIG": "OFF",
"TBB_USE_DEBUG_BUILD": "OFF",
"PXR_ENABLE_PYTHON_SUPPORT": "OFF",
"PXR_ENABLE_GL_SUPPORT": "OFF",
"PXR_ENABLE_METAL_SUPPORT": "OFF",
"PXR_BUILD_DOCUMENTATION": "OFF",
"PXR_BUILD_HTML_DOCUMENTATION": "OFF",
"PXR_BUILD_PYTHON_DOCUMENTATION": "OFF",
"PXR_BUILD_TESTS": "OFF",
"PXR_BUILD_EXAMPLES": "OFF",
"PXR_BUILD_TUTORIALS": "OFF",
"PXR_BUILD_USD_TOOLS": "OFF",
"PXR_BUILD_USD_VALIDATION": "OFF",
"PXR_BUILD_IMAGING": "OFF",
"PXR_BUILD_USD_IMAGING": "OFF",
"PXR_BUILD_USDVIEW": "OFF",
"PXR_BUILD_ALEMBIC_PLUGIN": "OFF",
"PXR_BUILD_DRACO_PLUGIN": "OFF",
"PXR_ENABLE_MATERIALX_SUPPORT": "OFF",
"PXR_BUILD_MAYAPY_TESTS": "OFF",
"PXR_BUILD_ANIMX_TESTS": "OFF",
"Boost_NO_SYSTEM_PATHS": "ON",
},
env = {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_BUILD_PARALLEL_LEVEL": "16",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to the -j16 build argument, hardcoding CMAKE_BUILD_PARALLEL_LEVEL is not recommended. This overrides Bazel's job management. Please remove this environment variable to allow Bazel to control build parallelism.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think bazel cmake() rule with set this properly unless we specify it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is somewhat accurate: Bazel doesn't know that this will use 16 jobs, so it will likely run too many actions concurrently, which could slow down the overall progress or consume too much memory.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is somewhat accurate: Bazel doesn't know that this will use 16 jobs, so it will likely run too many actions concurrently, which could slow down the overall progress or consume too much memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fmeum , is the best practice to remove both the -j<threads> and CMAKE_BUILD_PARALLEL_LEVEL here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to use CMAKE_BUILD_PARRALEL_LEVEL of 4 here, which seems like a reasonable compromise. Most of the other uses of the cmake() rule I've seen seem to do the same.

},
alwayslink = True,
out_static_libs = [
# This is name of the monolithic static lib.
"libusd_m.a",
],
out_data_dirs = [
"lib/usd"
],
lib_source = ":all_srcs",
deps = [
"@onetbb//:tbb",
],
)

# As part of the cmake build, OpenUSD installs a directory of plugin file resources (many plugInfo.json files)
# to openusd/lib/usd. On program startup, OpenUSD expects these plugin files to be in a usd/ dir directly next
# to the executable or .so library. It will throw an exception and crash if they are not found.
# We use the 'copy_to_directory' helper to copy them out of 'openusd/lib/usd' to just 'usd' so that they
# are at the right path.
copy_to_directory(
name = "plugin_files",
srcs = [":openusd"],
out = "usd",
replace_prefixes = {
"openusd/lib/usd": "",
}
)

cc_test(
name = "test_main",
srcs = ["test_main.cpp"],
deps = [
":openusd",
"@bazel_tools//tools/cpp/runfiles",
],
data = [
":plugin_files",
]
)

13 changes: 13 additions & 0 deletions modules/openusd/25.11/overlay/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module(
name = "openusd",
version = "25.11",
# Required to be able to use the 'overlay' files feature of BCR
bazel_compatibility = ['>=7.2.1'],
)
bazel_dep(name = "onetbb", version = "2022.1.0")

bazel_dep(name = "rules_foreign_cc", version = "0.15.1")
bazel_dep(name = "rules_cc", version = "0.2.14")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "bazel_lib", version = "3.0.0")
52 changes: 52 additions & 0 deletions modules/openusd/25.11/overlay/test_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <iostream>

#include <pxr/usd/usd/stage.h>
#include <pxr/usd/usdGeom/sphere.h>
#include <pxr/base/tf/token.h>
#include <pxr/base/plug/registry.h>

#include "tools/cpp/runfiles/runfiles.h"

using bazel::tools::cpp::runfiles::Runfiles;

int main(int argc, char** argv) {
std::cout << "--- USD Initialization Test ---\n";

// Use the bazel runfiles lib to get the path to the openusd plugins that this
// executable depends on. Use Create() for regular binaries and CreateForTest()
// for tests.
std::string error;
//std::unique_ptr<Runfiles> runfiles(Runfiles::Create(argv[0], &error));
std::unique_ptr<Runfiles> runfiles(Runfiles::CreateForTest(&error));
if (runfiles == nullptr) {
std::cout << "NO RUNFILES FOUND" << std::endl;
return 1;
}

// Register our custom plugins path with the plugin registry.
// If we do not do this, OpenUSD will throw when creating a stage.
std::string pluginsPath = runfiles->Rlocation("usd");
std::cout << "PATH to openusd/usd => " << pluginsPath << std::endl;
pxr::PlugRegistry::GetInstance().RegisterPlugins(pluginsPath);

// Create a USD Stage (the core container for a scene)
auto stage = pxr::UsdStage::CreateNew(std::string("HelloWorld.usda"));
if (stage) {
// Create a primary root primitive (like a scene root)
pxr::SdfPath primPath("/World/MyFirstPrim");
pxr::UsdGeomSphere sphere =
pxr::UsdGeomSphere::Define(stage, primPath);
std::cout << "Successfully created a primitive at path: "
<< sphere.GetPath().GetString() << "\n";

// Print a tftoken
pxr::TfToken myToken("Success!");
std::cout << "TfToken status: " << myToken.GetString() << "\n";
} else {
std::cerr << "ERROR: Failed to create an in-memory USD stage!\n";
return 1;
}

std::cout << "--- USD Test Complete ---\n";
return 0;
}
20 changes: 20 additions & 0 deletions modules/openusd/25.11/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
matrix:
platform:
- ubuntu2204
- macos
- windows
bazel:
- 8.x
tasks:
verify_targets:
name: Verify build targets
platform: ${{ platform }}
bazel: ${{ bazel }}
build_targets:
- '@openusd//:openusd'
run_test_module:
name: Run tests
platform: ${{ platform }}
bazel: ${{ bazel }}
test_targets:
- "@openusd//:test_main"
11 changes: 11 additions & 0 deletions modules/openusd/25.11/source.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"url": "https://github.com/PixarAnimationStudios/OpenUSD/archive/refs/tags/v25.11.tar.gz",
"integrity": "sha256-w3xjO1A3pFUvYVdGcOzKiDYim3gya9YmIvNCJnEYhmc=",
"strip_prefix": "OpenUSD-25.11",
"patch_strip": 0,
"overlay": {
"BUILD": "sha256-OOA7K5IYAEi+6X/1h7/qiJn1Sb9MugFceP81dwYNbiM=",
"MODULE.bazel": "sha256-7BYW8wgXpTMSAH+vpWLi9HTwPlQ5iyKzsbbDZSYrmq4=",
"test_main.cpp": "sha256-5hfksFp7KzvT01pbtvmOz432CBbb2fBOd3bhsy3oiSw="
}
}
36 changes: 36 additions & 0 deletions modules/openusd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# OpenUSD

## Overview

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
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.

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
as a monolithic static library, for ease of use.


## Working with this BCR module

If you must modify or update this BCR module, first read these docs:
https://github.com/bazelbuild/bazel-central-registry/blob/main/docs/README.md
https://bazel.build/external/registry

Commands cheat-sheet:

Run this to create a new BCR version:
bazel run //tools:add_module

Run this to update the integrity checksums in the source.json (for patches and overlay files):
bazel run -- //tools:update_integrity openusd

Run the validations:
bazel run -- //tools:bcr_validation [email protected]

### Testing Locally

To test the module locally, run this:

Run:
bazel shutdown && bazel build --enable_bzlmod --registry="file:///usr/local/google/home/mattriley/bazel-central-registry" --lockfile_mode=off //:main
Or just:
bazel test --enable_bzlmod --registry="file:///usr/local/google/home/mattriley/bazel-central-registry" --lockfile_mode=off //:test_main
24 changes: 24 additions & 0 deletions modules/openusd/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"homepage": "https://openusd.org/release/index.html",
"maintainers": [
{
"email": "[email protected]",
"github": "mgriley",
"github_user_id": 13209161,
"name": "Matthew Riley"
},
{
"email": "[email protected]",
"github": "dgoel",
"github_user_id": 834379,
"name": "Dhiraj Goel"
}
],
"repository": [
"github:PixarAnimationStudios/OpenUSD"
],
"versions": [
"25.11"
],
"yanked_versions": {}
}
Loading