Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
* `EXPORT_ES6` and `ENVIRONMENT=*node*` requires `USE_ES6_IMPORT_META` to be set.

* `_malloc` and `_free` must be declared as exported functions to avoid removal by the compiler.

* Remove [`WASM_ASYNC_COMPILATION=0`](https://emsettings.surma.technology/#WASM_ASYNC_COMPILATION).

  The current code was broken by emscripten-core/emscripten#12650. Previously, `WASM_ASYNC_COMPILATION=0` would return `Promise<Module>`, but that PR made it return `Module` directly. (Took ages to find the cause of this!)

  Removing the flag to keep it async avoids a breaking change in this library. Node.js v14.8.0 and later support top-level await, so async isn't that ugly. Alternatively, the Node.js version could easily be changed to load synchronously. Node.js has no limit on the size of synchronously loaded WebAssembly modules, unlike Chromium.
  • Loading branch information
zbjornson committed Dec 30, 2022
1 parent 8dc5720 commit f6be54a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ EMX_FLAGS :=
EMX_FLAGS += -Os
EMX_FLAGS += -s EXPORT_ES6=1
EMX_FLAGS += -s MODULARIZE=1
EMX_FLAGS += -s USE_ES6_IMPORT_META=0
EMX_FLAGS += -s USE_ES6_IMPORT_META=1
EMX_FLAGS += -s EXPORT_NAME='promise'
EMX_FLAGS += -s WASM_ASYNC_COMPILATION=0
EMX_FLAGS += -s ALLOW_MEMORY_GROWTH=1
EMX_FLAGS += -s ALLOW_TABLE_GROWTH=1
EMX_FLAGS += -s INITIAL_MEMORY=8MB
Expand All @@ -31,14 +30,14 @@ node: lmfit
emcc $(EMX_FLAGS) -I$(LMFIT_SRC)/lib $(LMFIT_SRC)/build/lib/liblmfit.a src/lmfit.js.c \
-s ENVIRONMENT="node" \
-s EXPORTED_RUNTIME_METHODS="[addFunction, removeFunction, getValue, cwrap]" \
-s EXPORTED_FUNCTIONS="[_do_fit]" \
-s EXPORTED_FUNCTIONS="[_do_fit, _malloc, _free]" \
-o $(BUILD_DIR)/lmfit.js;

web: lmfit
emcc $(EMX_FLAGS) -I$(LMFIT_SRC)/lib $(LMFIT_SRC)/build/lib/liblmfit.a src/lmfit.js.c \
-s ENVIRONMENT="worker" \
-s EXPORTED_RUNTIME_METHODS="[addFunction, removeFunction, getValue, cwrap]" \
-s EXPORTED_FUNCTIONS="[_do_fit]" \
-s EXPORTED_FUNCTIONS="[_do_fit, _malloc, _free]" \
-o $(BUILD_DIR)/lmfit.web.js;

lmfit: dir lmfit-patch
Expand Down

0 comments on commit f6be54a

Please sign in to comment.