Skip to content

Commit 9896fbe

Browse files
committed
[wasm64] Add wasm64 support
- Add wasm64 build target to build_usd.py - Extend static asserts in `pxr/base/tf/mallocTag.cpp`, `pxr/base/tf/smallVector.cpp` and `pxr/usd/usd/primData.cpp` to handle 32 and 64 bits architectures - Add required emscripten and node versions to VERSIONS.md
1 parent ecea8d8 commit 9896fbe

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

VERSIONS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ Our test machines have the following software versions installed.
3939
| OpenVDB | 10.1.0 | 10.1.0 | 10.1.0 |
4040
| Vulkan SDK | 1.4.321.0 | 1.4.321.0 | 1.4.321.0 |
4141
| Draco | 1.5.6 | 1.5.6 | 1.5.6 |
42+
| Emscripten | 4.0.15 | 4.0.15 | 4.0.15 |
43+
| node | 24.9.0 | 24.9.0 | 24.9.0 |

build_scripts/build_usd.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
# Helpers for printing output
3939
verbosity = 1
40+
EMSCRIPTEN_CMAKE_EXE_LINKER_FLAGS='-pthread'
41+
EMSCRIPTEN_CMAKE_CXX_FLAGS='-pthread --use-port=zlib'
4042

4143
def Print(msg):
4244
if verbosity > 0:
@@ -82,14 +84,15 @@ def GetBuildTargetDefault():
8284
return ''
8385

8486
TARGET_WASM='wasm'
87+
TARGET_WASM64='wasm64'
8588

8689
def GetBuildTargets():
8790
if MacOS():
88-
return apple_utils.GetBuildTargets() + [TARGET_WASM]
91+
return apple_utils.GetBuildTargets() + [TARGET_WASM, TARGET_WASM64]
8992
elif Linux():
90-
return [TARGET_WASM]
93+
return [TARGET_WASM, TARGET_WASM64]
9194
elif Windows():
92-
return [TARGET_WASM]
95+
return [TARGET_WASM, TARGET_WASM64]
9396
else:
9497
return []
9598

@@ -1007,7 +1010,10 @@ def InstallOneTBB(context, force, buildArgs):
10071010
with CurrentWorkingDirectory(DownloadURL(ONETBB_URL, context, force)):
10081011
cmakeOptions = ['-DTBB_TEST=OFF', '-DTBB_STRICT=OFF']
10091012
if context.targetWasm:
1010-
cmakeOptions += ['-DBUILD_SHARED_LIBS=OFF', '-DCMAKE_CXX_FLAGS="-pthread"']
1013+
cmakeOptions += [
1014+
'-DBUILD_SHARED_LIBS=OFF',
1015+
'-DCMAKE_CXX_FLAGS="' + EMSCRIPTEN_CMAKE_CXX_FLAGS + '"'
1016+
]
10111017

10121018
cmakeOptions += buildArgs
10131019
RunCMake(context, force, cmakeOptions)
@@ -1878,6 +1884,10 @@ def InstallUSD(context, force, buildArgs):
18781884

18791885
extraArgs.append('-DBUILD_SHARED_LIBS=OFF')
18801886

1887+
extraArgs.append('-DCMAKE_CXX_FLAGS="' + EMSCRIPTEN_CMAKE_CXX_FLAGS + '"')
1888+
extraArgs.append('-DCMAKE_C_FLAGS="' + EMSCRIPTEN_CMAKE_CXX_FLAGS + '"')
1889+
extraArgs.append('-DCMAKE_EXE_LINKER_FLAGS="' + EMSCRIPTEN_CMAKE_EXE_LINKER_FLAGS + '"')
1890+
18811891
RunCMake(context, force, extraArgs, context.usdInstDir)
18821892

18831893
USD = Dependency("USD", InstallUSD, "include/pxr/pxr.h")
@@ -2339,7 +2349,7 @@ def __init__(self, args):
23392349

23402350
self.ignorePaths = args.ignore_paths or []
23412351
# Build target and code signing
2342-
self.targetWasm = (args.build_target == TARGET_WASM)
2352+
self.targetWasm = (args.build_target == TARGET_WASM or args.build_target == TARGET_WASM64)
23432353
self.buildTarget = args.build_target
23442354
if MacOS():
23452355
apple_utils.SetTarget(self, self.buildTarget)
@@ -2460,6 +2470,10 @@ def ForceBuildDependency(self, dep):
24602470

24612471
verbosity = args.verbosity
24622472

2473+
if args.build_target == TARGET_WASM64:
2474+
EMSCRIPTEN_CMAKE_EXE_LINKER_FLAGS+=' -sMEMORY64=1'
2475+
EMSCRIPTEN_CMAKE_CXX_FLAGS+=' -sMEMORY64=1'
2476+
24632477
# Augment PATH on Windows so that 3rd-party dependencies can find libraries
24642478
# they depend on. In particular, this is needed for building IlmBase/OpenEXR.
24652479
extraPaths = []

cmake/defaults/ProjectDefaults.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if(APPLE)
2828
endif()
2929

3030
if(EMSCRIPTEN)
31-
set(EMSCRIPTEN_COMPILE_FLAGS "-sMAXIMUM_MEMORY=4GB -fexceptions")
31+
set(EMSCRIPTEN_COMPILE_FLAGS "-fexceptions")
3232
add_compile_options("SHELL:${EMSCRIPTEN_COMPILE_FLAGS}")
3333
add_link_options("SHELL:${EMSCRIPTEN_COMPILE_FLAGS} -sALLOW_MEMORY_GROWTH=1")
3434
endif()

pxr/base/tf/mallocTag.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ struct Tf_MallocBlockInfo {
115115
Tf_MallocPathNode *pathNode = nullptr;
116116
};
117117

118-
#if defined (__wasm64__)
118+
#if defined(ARCH_OS_WASM_VM) && defined(ARCH_BITS_64)
119119
static_assert(sizeof(Tf_MallocBlockInfo) == 16,
120120
"Unexpected size for Tf_MallocBlockInfo");
121-
#elif defined (__wasm32__)
121+
#elif defined(ARCH_OS_WASM_VM) && defined(ARCH_BITS_32)
122122
static_assert(sizeof(Tf_MallocBlockInfo) == 8,
123123
"Unexpected size for Tf_MallocBlockInfo");
124124
#elif !defined(ARCH_OS_WINDOWS)

pxr/base/tf/smallVector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
PXR_NAMESPACE_OPEN_SCOPE
1111

12-
#ifndef ARCH_OS_WASM_VM
12+
#ifdef ARCH_BITS_64
1313
static_assert(
1414
sizeof(TfSmallVector<int, 1>) == 16,
1515
"Expecting sizeof(TfSmallVector<int, N = 1>) to be 16 bytes.");
@@ -31,7 +31,7 @@ static_assert(
3131
sizeof(TfSmallVector<double, 2>) == 24,
3232
"Expecting sizeof(TfSmallVector<double, N = 2>) to be 24 bytes.");
3333

34-
#ifndef ARCH_OS_WASM_VM
34+
#ifdef ARCH_BITS_64
3535
static_assert(
3636
TfSmallVectorBase::ComputeSerendipitousLocalCapacity<char>() == 8,
3737
"Expecting 8 bytes of local capacity.");

pxr/usd/usd/primData.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ PXR_NAMESPACE_OPEN_SCOPE
2828

2929
// Static assertion on PrimData size. We want to be warned when its size
3030
// changes.
31+
#ifdef ARCH_BITS_32
32+
static_assert(sizeof(Usd_PrimData) == 48,
33+
"Expected sizeof(Usd_PrimData) == 48");
34+
#else
3135
static_assert(sizeof(Usd_PrimData) == 64,
3236
"Expected sizeof(Usd_PrimData) == 64");
37+
#endif
3338

3439
// Usd_PrimData need to be always initialized with a valid type info pointer
3540
static const UsdPrimTypeInfo *_GetEmptyPrimTypeInfo()

0 commit comments

Comments
 (0)