add monolithic build variant of OpenUSD build script.

This commit is contained in:
Syoyo Fujita
2025-10-31 23:19:46 +09:00
parent c57788af01
commit f7c2a4fc00
2 changed files with 289 additions and 17 deletions

View File

@@ -4,6 +4,8 @@ This directory contains scripts and tools for setting up OpenUSD to compare its
## Quick Start
### Standard Build (Multiple Shared Libraries)
1. **Initial Setup** (one-time only):
```bash
cd aousd
@@ -27,34 +29,72 @@ This directory contains scripts and tools for setting up OpenUSD to compare its
source aousd/setup_env.sh
```
### Monolithic Build (Single Shared Library)
For applications that benefit from a single monolithic USD library:
1. **Initial Setup** (one-time only):
```bash
cd aousd
./setup_openusd_monolithic.sh
```
Or with specific compilers:
```bash
CC=clang CXX=clang++ ./setup_openusd_monolithic.sh
```
This will:
- Build OpenUSD as a single monolithic shared library (`-DPXR_BUILD_MONOLITHIC=ON`)
- Install to `aousd/dist_monolithic`
- Use the same Python virtual environment
2. **Activate Environment** (every new terminal session):
```bash
source aousd/setup_env_monolithic.sh
```
**Monolithic vs Standard Build:**
- **Monolithic**: Single `libusd_ms.so` library, faster linking, smaller total size
- **Standard**: Multiple libraries (45+ .so files), more modular, standard OpenUSD configuration
## Directory Structure
```
aousd/
├── OpenUSD/ # Cloned OpenUSD repository
├── dist/ # OpenUSD installation
│ ├── bin/ # USD command-line tools
│ ├── lib/ # USD libraries and Python modules
│ └── include/ # USD headers
├── venv/ # Python 3.11 virtual environment
├── setup_openusd.sh # Build and installation script
├── setup_env.sh # Environment setup script
└── README.md # This file
├── OpenUSD/ # Cloned OpenUSD repository
├── dist/ # OpenUSD standard build installation
│ ├── bin/ # USD command-line tools
│ ├── lib/ # USD libraries (45+ .so files) and Python modules
│ └── include/ # USD headers
├── dist_monolithic/ # OpenUSD monolithic build installation
│ ├── bin/ # USD command-line tools
│ ├── lib/ # Single monolithic USD library and Python modules
│ └── include/ # USD headers
├── venv/ # Python 3.11 virtual environment (shared)
├── setup_openusd.sh # Standard build script
├── setup_openusd_monolithic.sh # Monolithic build script
├── setup_env.sh # Environment setup for standard build
├── setup_env_monolithic.sh # Environment setup for monolithic build
└── README.md # This file
```
## Compiler Configuration
The build script automatically detects available compilers, but you can override them:
Both build scripts automatically detect available compilers, but you can override them:
```bash
# Use GCC
# Use GCC (standard build)
CC=gcc CXX=g++ ./setup_openusd.sh
# Use Clang
# Use Clang (standard build)
CC=clang CXX=clang++ ./setup_openusd.sh
# Use specific versions
# Use specific versions (standard build)
CC=gcc-11 CXX=g++-11 ./setup_openusd.sh
# Same for monolithic build
CC=clang CXX=clang++ ./setup_openusd_monolithic.sh
```
## Available Tools After Setup
@@ -169,15 +209,39 @@ usdzip output.usdz -r models/suzanne.usda
## Build Options
The current setup uses minimal dependencies. To enable additional features, modify `setup_openusd.sh`:
### Build Type Selection
**Standard Build (`setup_openusd.sh`):**
- Multiple shared libraries (libusd_arch.so, libusd_sdf.so, libusd_usd.so, etc.)
- Standard OpenUSD configuration used by most applications
- Modular library structure allows selective linking
- Installed to `dist/`
**Monolithic Build (`setup_openusd_monolithic.sh`):**
- Single monolithic shared library (libusd_ms.so)
- Faster link times for applications
- Smaller total disk footprint
- Easier deployment (fewer .so files)
- Installed to `dist_monolithic/`
### Feature Configuration
Both builds use minimal dependencies by default. To enable additional features, modify the respective script:
```bash
# In setup_openusd.sh or setup_openusd_monolithic.sh
# Remove these flags for full features:
# --no-imaging # Enable imaging support
# --no-usdview # Enable USD viewer
# --no-materialx # Enable MaterialX support
```
### Which Build to Use?
- **Use Standard Build** if you need maximum compatibility with other USD tools
- **Use Monolithic Build** if you want faster compilation/linking or easier deployment
- Both builds provide identical functionality and Python API
## Troubleshooting
### Build Fails
@@ -237,8 +301,11 @@ echo "Use 'diff' or 'vimdiff' to compare files"
## Notes
- The OpenUSD build is configured for minimal dependencies to reduce build time
- Two build variants available: Standard (modular) and Monolithic (single library)
- The OpenUSD builds are configured for minimal dependencies to reduce build time
- Python bindings are enabled for comprehensive API comparison
- The setup uses Python 3.11 via `uv` for consistent environment
- Build artifacts are isolated in `aousd/` directory for clean separation
- Compiler selection: The script auto-detects gcc/g++ or clang/clang++, or uses CC/CXX environment variables
- Build artifacts are isolated in separate directories (`dist/` and `dist_monolithic/`)
- Both builds share the same Python virtual environment
- Compiler selection: The scripts auto-detect gcc/g++ or clang/clang++, or use CC/CXX environment variables
- You can have both builds installed simultaneously

205
aousd/setup_openusd_monolithic.sh Executable file
View File

@@ -0,0 +1,205 @@
#!/bin/bash
# OpenUSD Monolithic Build Setup Script for comparison with TinyUSDZ
# This script clones, builds, and installs OpenUSD as a single monolithic library
# with Python bindings
set -e # Exit on error
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OPENUSD_DIR="${SCRIPT_DIR}/OpenUSD"
DIST_DIR="${SCRIPT_DIR}/dist_monolithic"
VENV_DIR="${SCRIPT_DIR}/venv"
echo "================================================"
echo "OpenUSD Monolithic Build Setup Script"
echo "================================================"
echo "Working directory: ${SCRIPT_DIR}"
echo ""
# Step 1: Clone OpenUSD repository
echo "Step 1: Cloning OpenUSD repository (release branch)..."
if [ -d "${OPENUSD_DIR}" ]; then
echo "OpenUSD directory already exists. Pulling latest changes..."
cd "${OPENUSD_DIR}"
git fetch origin
git checkout release
git pull origin release
else
git clone -b release https://github.com/lighttransport/OpenUSD.git "${OPENUSD_DIR}"
fi
# Step 2: Setup Python 3.11 with uv (reuse existing venv if available)
echo ""
echo "Step 2: Setting up Python 3.11 with uv..."
if ! command -v uv &> /dev/null; then
echo "Installing uv..."
curl -LsSf https://astral.sh/uv/install.sh | sh
# Add uv to PATH for current session
export PATH="$HOME/.cargo/bin:$PATH"
fi
# Create virtual environment with Python 3.11 if it doesn't exist
if [ ! -d "${VENV_DIR}" ]; then
echo "Creating virtual environment with Python 3.11..."
cd "${SCRIPT_DIR}"
uv venv "${VENV_DIR}" --python 3.11
else
echo "Using existing virtual environment..."
fi
# Activate virtual environment
echo "Activating virtual environment..."
source "${VENV_DIR}/bin/activate"
# Step 3: Install Python dependencies
echo ""
echo "Step 3: Installing Python dependencies..."
uv pip install PyOpenGL PySide2 numpy cmake>=3.26
# Step 4: Setup compilers
echo ""
echo "Step 4: Setting up C/C++ compilers..."
# Allow user to override compilers via environment variables
# If not set, try to find suitable defaults
if [ -z "$CC" ]; then
if command -v gcc &> /dev/null; then
export CC=gcc
elif command -v clang &> /dev/null; then
export CC=clang
else
echo "Error: No C compiler found. Please install gcc or clang."
exit 1
fi
fi
if [ -z "$CXX" ]; then
if command -v g++ &> /dev/null; then
export CXX=g++
elif command -v clang++ &> /dev/null; then
export CXX=clang++
else
echo "Error: No C++ compiler found. Please install g++ or clang++."
exit 1
fi
fi
echo "Using C compiler: $CC"
echo "Using C++ compiler: $CXX"
# Step 5: Build OpenUSD with Monolithic option
echo ""
echo "Step 5: Building OpenUSD with MONOLITHIC option..."
echo "This may take a while..."
cd "${OPENUSD_DIR}"
# Prepare build arguments for monolithic build with Python support
BUILD_ARGS=(
"${DIST_DIR}"
--no-tests
--no-examples
--no-tutorials
--no-tools
--no-docs
--python
--no-imaging
--no-usdview
--no-materialx
--no-embree
--no-ptex
--no-openvdb
--no-draco
--build-args
"USD,\"-DPXR_BUILD_MONOLITHIC=ON\""
)
echo "Build configuration:"
echo " - Installation directory: ${DIST_DIR}"
echo " - Python bindings: ON"
echo " - Monolithic build: ON (single shared library)"
echo " - Minimal dependencies (no imaging, materialx, etc.)"
echo ""
# Run build script
python build_scripts/build_usd.py "${BUILD_ARGS[@]}"
# Step 6: Create environment setup script
echo ""
echo "Step 6: Creating environment setup script..."
cat > "${SCRIPT_DIR}/setup_env_monolithic.sh" << 'EOF'
#!/bin/bash
# OpenUSD Monolithic Build Environment Setup Script
# Source this script to set up the environment for using OpenUSD tools
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
USD_INSTALL_ROOT="${SCRIPT_DIR}/dist_monolithic"
VENV_DIR="${SCRIPT_DIR}/venv"
if [ ! -d "${USD_INSTALL_ROOT}" ]; then
echo "Error: OpenUSD monolithic installation not found at ${USD_INSTALL_ROOT}"
echo "Please run setup_openusd_monolithic.sh first."
return 1
fi
# Activate Python virtual environment
if [ -f "${VENV_DIR}/bin/activate" ]; then
source "${VENV_DIR}/bin/activate"
echo "Python virtual environment activated."
else
echo "Warning: Python virtual environment not found."
fi
# Set up USD environment variables
export USD_INSTALL_ROOT="${USD_INSTALL_ROOT}"
export PATH="${USD_INSTALL_ROOT}/bin:${PATH}"
export PYTHONPATH="${USD_INSTALL_ROOT}/lib/python:${PYTHONPATH}"
# Set library paths
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
export DYLD_LIBRARY_PATH="${USD_INSTALL_ROOT}/lib:${DYLD_LIBRARY_PATH}"
else
# Linux
export LD_LIBRARY_PATH="${USD_INSTALL_ROOT}/lib:${LD_LIBRARY_PATH}"
fi
echo "================================================"
echo "OpenUSD Monolithic environment configured!"
echo "================================================"
echo "USD_INSTALL_ROOT: ${USD_INSTALL_ROOT}"
echo "Python: $(which python)"
echo "Build type: Monolithic (single shared library)"
echo ""
echo "Available commands:"
echo " - usdcat: Display USD files in text format"
echo " - usddiff: Compare two USD files"
echo " - usdtree: Display USD scene hierarchy"
echo " - usdchecker: Validate USD files"
echo " - usdzip: Create USDZ archives"
echo ""
echo "Python USD module:"
echo " python -c 'from pxr import Usd; print(Usd)'"
echo "================================================"
EOF
chmod +x "${SCRIPT_DIR}/setup_env_monolithic.sh"
echo ""
echo "================================================"
echo "OpenUSD Monolithic build completed successfully!"
echo "================================================"
echo ""
echo "Installation directory: ${DIST_DIR}"
echo "Build type: Monolithic (single shared library)"
echo ""
echo "To use OpenUSD tools and Python bindings, run:"
echo " source ${SCRIPT_DIR}/setup_env_monolithic.sh"
echo ""
echo "Then you can use commands like:"
echo " - usdcat <file.usd>"
echo " - python -c 'from pxr import Usd'"
echo "================================================"