Skip to content

Commit

Permalink
fix: Ammo() should assign the loaded module to global Ammo (kripken#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianpurvis authored Aug 19, 2020
1 parent aa26a62 commit dedcf2b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(WEBIDL_BINDER_SCRIPT $ENV{EMSCRIPTEN}/tools/webidl_binder.py)
set(AMMO_FRONT_MATTER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/front-matter.js)
set(AMMO_HEADER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/ammo.h)
set(AMMO_IDL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/ammo.idl)
set(AMMO_ONLOAD_FILE ${CMAKE_CURRENT_SOURCE_DIR}/onload.js)
set(BULLET_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bullet/src/)

set(BULLET_TARGETS BulletCollision BulletDynamics BulletSoftBody LinearMath)
Expand All @@ -32,6 +33,7 @@ set(EMCC_ARGS
--extern-pre-js ${AMMO_FRONT_MATTER_FILE}
--llvm-lto 1
--post-js glue.js
--post-js ${AMMO_ONLOAD_FILE}
-O3
-s ALLOW_MEMORY_GROWTH=${ALLOW_MEMORY_GROWTH}
-s EXPORTED_RUNTIME_METHODS=["UTF8ToString"]
Expand Down Expand Up @@ -101,7 +103,7 @@ add_custom_target(ammo-bindings ALL DEPENDS glue.js glue.o)
add_custom_command(
OUTPUT ammo.js
COMMAND emcc glue.o ${BULLET_LIBS} ${EMCC_JS_ARGS} -o ammo.js
DEPENDS ammo-bindings ${BULLET_TARGETS}
DEPENDS ammo-bindings ${AMMO_FRONT_MATTER_FILE} ${AMMO_ONLOAD_FILE} ${BULLET_TARGETS}
COMMENT "Building ammo javascript"
VERBATIM)
add_custom_target(ammo-javascript ALL DEPENDS ammo.js)
Expand All @@ -111,7 +113,7 @@ add_custom_target(ammo-javascript ALL DEPENDS ammo.js)
add_custom_command(
OUTPUT ammo.wasm.js ammo.wasm.wasm
COMMAND emcc glue.o ${BULLET_LIBS} ${EMCC_WASM_ARGS} -o ammo.wasm.js
DEPENDS ammo-bindings ${BULLET_TARGETS}
DEPENDS ammo-bindings ${AMMO_FRONT_MATTER_FILE} ${AMMO_ONLOAD_FILE} ${BULLET_TARGETS}
COMMENT "Building ammo webassembly"
VERBATIM)
add_custom_target(ammo-wasm ALL DEPENDS ammo.wasm.js ammo.wasm.wasm)
2 changes: 2 additions & 0 deletions onload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Reassign global Ammo to the loaded module:
this['Ammo'] = Module;
7 changes: 7 additions & 0 deletions tests/loading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const test = require('ava');
const loadAmmo = require('./helpers/load-ammo.js');

test('loading should assign global Ammo', async t => {
await loadAmmo()
t.assert(Ammo)
})

0 comments on commit dedcf2b

Please sign in to comment.