Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify format of -s parameters in emccArgs in plugin-wasm options #523

Open
chrispcampbell opened this issue Aug 26, 2024 · 1 comment
Open

Comments

@chrispcampbell
Copy link
Contributor

In discussion thread #522, @serman noted an issue with passing -s parameters:

I managed to add the -S ASSERTIONS=1 to the wasm plugin:

wasmPlugin({ 
emccArgs: [
"-Wall", "-Os ", 
"-sSTRICT=1 ",
 "-sMALLOC=emmalloc", 
"-sFILESYSTEM=0 ",
 "-sMODULARIZE=1 ",
 "-sSINGLE_FILE=1 ", 
"-sEXPORT_ES6=1 ",
 "-sUSE_ES6_IMPORT_META=0 ", 
"-sENVIRONMENT='web,webview,worker' ", 
"-sEXPORTED_FUNCTIONS='_malloc','_free','_getInitialTime','_getFinalTime','_getSaveper','_setLookup','_runModelWithBuffers']", 
"-sEXPORTED_RUNTIME_METHODS=['cwrap']",
 "-sASSERTIONS=1"] }),

(note: I recommend including an example of this in the documentation since I didn't know that -s params don't have a space between "-s XXXXPARAMXXX" I can add it if you want)

It's interesting that in many of the Emscripten error messages, they show -s arguments with a space, and historically in SDE we have used a space as well, but it looks like the Emscripten documentation was amended at some point to recommend NOT including a space:
https://emscripten.org/docs/tools_reference/emcc.html

Options can be specified as a single argument with or without a space between the -s and option name. e.g. -sFOO or -s FOO. It’s highly recommended you use the notation without space.

@chrispcampbell
Copy link
Contributor Author

The reason that I think Sergio had trouble with spaces is because the plugin-wasm docs show this:

emccArgs

Optional emccArgs: string[] | () => string[]

The array of additional arguments to pass to emcc. If undefined, the plugin will
use the following default set of arguments, which are tuned for (and known to work
with) Emscripten versions 2.0.34 and 3.1.46, among others.

  -Wall
  -Os
  -s STRICT=1
  -s MALLOC=emmalloc
  -s FILESYSTEM=0
  -s MODULARIZE=1
  -s SINGLE_FILE=1
  -s EXPORT_ES6=1
  -s USE_ES6_IMPORT_META=0
  -s ENVIRONMENT='web,webview,worker'
  -s EXPORTED_FUNCTIONS=['_malloc','_free','_getInitialTime','_getFinalTime','_getSaveper','_setLookup','_runModelWithBuffers']
  -s EXPORTED_RUNTIME_METHODS=['cwrap']

When you pass an array of options, the spaces can cause problems if they are included in the strings due to the way args are passed to spawn. The above docs imply that you'd pass it like this (which I'm assuming how Sergio passed them):

['-s STRICT=1', ...]

But in fact you have to do the -s part as a separate string, like this:

['-s', 'STRICT=1', ...]

Or just drop the space altogether as Sergio found, and as recommended in the emcc docs:

['-sSTRICT=1', ...]

So I think we can amend the docs and the implementation of plugin-wasm to omit the space for clarity.

@climateinteractive climateinteractive deleted a comment from Saschl Aug 26, 2024
@Saschl
Copy link

Saschl commented Aug 26, 2024

Really sorry about that comment. My account got compromised and posted this malicious link. Lessons leaned..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants