Skip to content

Commit a4a1742

Browse files
committed
Slightly less hacky version to avoid dynamic import
See #245
1 parent bc88fa9 commit a4a1742

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ else()
8686
set(REMOVE_THREAD_LOCAL sed -i.bak -e "s:thread_local::g" glue.cpp)
8787
endif()
8888

89-
# Replace '("ReplaceWithImport"' with 'import(' in the generated JS code to workaround a bug in emscripten
89+
# Replace 'replace_by_import' by 'import' in the generated JS code to workaround a bug in emscripten
9090
# See: https://github.com/jrouwe/JoltPhysics.js/issues/245
91-
set(REPLACE_IMPORT sed -i -e "s:(\"ReplaceWithImport\"+:import(:g")
91+
set(REPLACE_IMPORT sed -i -e "s:replace_by_import:import:g")
9292

9393
# Enable SIMD flags
9494
if (ENABLE_SIMD)
@@ -136,6 +136,9 @@ set(EMCC_ARGS
136136
--extern-pre-js ${JOLT_FRONT_MATTER_FILE}
137137
--post-js glue.js
138138
--closure=1
139+
--closure-args="--dynamic_import_alias=replace_by_import"
140+
--closure-args="--externs"
141+
--closure-args="${CMAKE_CURRENT_SOURCE_DIR}/extern-import.js"
139142
${MULTI_THREADED_FLAG}
140143
--post-js ${CMAKE_CURRENT_SOURCE_DIR}/helpers.js
141144
${MEMORY_GROWTH_FLAG}

extern-import.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// A hack to not have to use 'import' in multi-threaded.js
2+
// See: https://github.com/jrouwe/JoltPhysics.js/issues/245
3+
var replace_by_import = (a) => { };

multi-threaded.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ if (ENVIRONMENT_IS_PTHREAD) {
44
invokeEntryPoint = (ptr, arg) => {
55
if (arg.script) {
66
// Workaround for bug: https://github.com/jrouwe/JoltPhysics.js/issues/245
7-
// '("ReplaceWithImport"+arg.script)' should be 'import(arg.script)'
8-
// This gets replaced by sed during the build process.
9-
("ReplaceWithImport"+arg.script).then(module => {
7+
// `replace_by_import` gets replaced by `import`
8+
replace_by_import(arg.script).then(module => {
109
module.default(Module, arg.params).then(() => _invokeEntryPoint(ptr, arg.value));
1110
})
1211
} else {

0 commit comments

Comments
 (0)