Add single threaded version
This commit is contained in:
@@ -211,8 +211,26 @@ build_test_wasm() {
|
|||||||
source emsdk/emsdk_env.sh
|
source emsdk/emsdk_env.sh
|
||||||
export PATH="$(pwd)/node_modules/.bin:$PATH"
|
export PATH="$(pwd)/node_modules/.bin:$PATH"
|
||||||
|
|
||||||
emcmake cmake -B build_wasm -DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=OFF $WASM_CMAKE_ARGS
|
echo "Building Multi-Threaded version..."
|
||||||
cmake --build build_wasm
|
emcmake cmake -B build_wasm_mt \
|
||||||
|
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=OFF \
|
||||||
|
-DMUJOCO_WASM_THREADS=ON \
|
||||||
|
$WASM_CMAKE_ARGS
|
||||||
|
cmake --build build_wasm_mt --parallel $(nproc)
|
||||||
|
|
||||||
|
echo "Moving Multi-Thread version under mt subfolder..."
|
||||||
|
mkdir -p wasm/dist/mt
|
||||||
|
mv wasm/dist/mujoco.js wasm/dist/mt/
|
||||||
|
mv wasm/dist/mujoco.wasm wasm/dist/mt/
|
||||||
|
mv wasm/dist/mujoco.d.ts wasm/dist/mt/
|
||||||
|
mv wasm/dist/mujoco.wasm.map wasm/dist/mt/
|
||||||
|
|
||||||
|
echo "Building Single-Threaded version..."
|
||||||
|
emcmake cmake -B build_wasm_st \
|
||||||
|
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=OFF \
|
||||||
|
-DMUJOCO_WASM_THREADS=OFF \
|
||||||
|
$WASM_CMAKE_ARGS
|
||||||
|
cmake --build build_wasm_st --parallel $(nproc)
|
||||||
|
|
||||||
npm run test --prefix ./wasm
|
npm run test --prefix ./wasm
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-2
@@ -31,11 +31,11 @@ if(NOT MUJOCO_WASM_FILES)
|
|||||||
message(FATAL_ERROR "No source files found in codegen/generated/")
|
message(FATAL_ERROR "No source files found in codegen/generated/")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
option(MUJOCO_WASM_THREADS "Build with multi-threading support" ON)
|
||||||
|
|
||||||
# Set Emscripten linker flags
|
# Set Emscripten linker flags
|
||||||
set(EMCC_LINKER_FLAGS
|
set(EMCC_LINKER_FLAGS
|
||||||
"--bind"
|
"--bind"
|
||||||
"-pthread"
|
|
||||||
"-s PTHREAD_POOL_SIZE=navigator.hardwareConcurrency"
|
|
||||||
"-s ASSERTIONS=1"
|
"-s ASSERTIONS=1"
|
||||||
"-s ALLOW_MEMORY_GROWTH=1"
|
"-s ALLOW_MEMORY_GROWTH=1"
|
||||||
"-s EXPORT_ES6=1"
|
"-s EXPORT_ES6=1"
|
||||||
@@ -48,6 +48,13 @@ set(EMCC_LINKER_FLAGS
|
|||||||
"-g"
|
"-g"
|
||||||
"--emit-tsd mujoco.d.ts"
|
"--emit-tsd mujoco.d.ts"
|
||||||
)
|
)
|
||||||
|
if(MUJOCO_WASM_THREADS)
|
||||||
|
list(APPEND EMCC_LINKER_FLAGS
|
||||||
|
"-pthread"
|
||||||
|
"-s PTHREAD_POOL_SIZE=navigator.hardwareConcurrency"
|
||||||
|
)
|
||||||
|
add_definitions(-DMUJOCO_WASM_THREADS)
|
||||||
|
endif()
|
||||||
string (REPLACE ";" " " EMCC_LINKER_FLAGS_STR "${EMCC_LINKER_FLAGS}")
|
string (REPLACE ";" " " EMCC_LINKER_FLAGS_STR "${EMCC_LINKER_FLAGS}")
|
||||||
|
|
||||||
add_executable(mujoco_wasm ${MUJOCO_WASM_FILES})
|
add_executable(mujoco_wasm ${MUJOCO_WASM_FILES})
|
||||||
|
|||||||
+20
-2
@@ -24,13 +24,31 @@
|
|||||||
"javascript",
|
"javascript",
|
||||||
"typescript"
|
"typescript"
|
||||||
],
|
],
|
||||||
"main": "mujoco.js",
|
"exports": {
|
||||||
"types": "mujoco.d.ts",
|
".": {
|
||||||
|
"types": "./mujoco.d.ts",
|
||||||
|
"import": "./mujoco.js",
|
||||||
|
"default": "./mujoco.js"
|
||||||
|
},
|
||||||
|
"./mt": {
|
||||||
|
"types": "./mt/mujoco.d.ts",
|
||||||
|
"import": "./mt/mujoco.js",
|
||||||
|
"default": "./mt/mujoco.js"
|
||||||
|
},
|
||||||
|
"./mujoco.wasm": "./mujoco.wasm",
|
||||||
|
"./mujoco.wasm.map": "./mujoco.wasm.map",
|
||||||
|
"./mt/mujoco.wasm": "./mt/mujoco.wasm",
|
||||||
|
"./mt/mujoco.wasm.map": "./mt/mujoco.wasm.map"
|
||||||
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"mujoco.js",
|
"mujoco.js",
|
||||||
"mujoco.d.ts",
|
"mujoco.d.ts",
|
||||||
"mujoco.wasm",
|
"mujoco.wasm",
|
||||||
"mujoco.wasm.map",
|
"mujoco.wasm.map",
|
||||||
|
"mt/mujoco.js",
|
||||||
|
"mt/mujoco.d.ts",
|
||||||
|
"mt/mujoco.wasm",
|
||||||
|
"mt/mujoco.wasm.map",
|
||||||
"README.md"
|
"README.md"
|
||||||
],
|
],
|
||||||
"author": "Google DeepMind",
|
"author": "Google DeepMind",
|
||||||
|
|||||||
Reference in New Issue
Block a user