WARDuino icon indicating copy to clipboard operation
WARDuino copied to clipboard

WASI support

Open beardhatcode opened this issue 4 years ago • 4 comments

We should look into supporting WASI.

beardhatcode avatar Feb 22 '21 10:02 beardhatcode

Note to ourselves: in case we want to test the WASI using emscripten, make sure to use at least v1.39.5. Since then, emscripten assumes WASI support by the runtime.

Also since emscripten v1.38.47 a standalone compilation to wasm no longer works with the -s ONLY_MY_CODE=1 option. We need to use -s STANDALONE_WASM instead.

carllocos avatar Feb 22 '21 12:02 carllocos

@carllocos , I have been digging a bit into emcc and the following works for me with EMCC 2.0

	emcc FILE \
		-s STANDALONE_WASM \
		--ignore-dynamic-linking \
		-s WASM=1 \
		-s NO_FILESYSTEM=1 \
		-s SIDE_MODULE=1 \
		-O3 \
		-o $@

Does that work for you?

beardhatcode avatar Mar 27 '21 13:03 beardhatcode

I sincerely do not remember how I managed to compile WASM that relies on WASI. The script that I have, that supposedly generates WASI dependency, no longer does it... Anyways, the above works for me @beardhatcode .

I observed that when transforming the obtained WASM to WAT from the attached file, I get imports (see below) which I'm not sure whether WARDuino provides. Just mentioning it for safety.

to WAT command: wasm2wat game.wasm -o game.wat

The imports: (import "env" "stackSave" (func (;0;) (type 1))) (import "env" "memory" (memory (;0;) 0)) (import "env" "__indirect_function_table" (table (;0;) 0 funcref))

game.txt

carllocos avatar Mar 28 '21 16:03 carllocos

@carllocos , I have been digging a bit into emcc and the following works for me with EMCC 2.0

	emcc FILE \
		-s STANDALONE_WASM \
		--ignore-dynamic-linking \
		-s WASM=1 \
		-s NO_FILESYSTEM=1 \
		-s SIDE_MODULE=1 \
		-O3 \
		-o $@

Does that work for you?

FYI, this seemed to break the microbenchmarks on the latest version. So I have removed this in 40d4287bd619c9e1e171d3cd8c0a1504b71bd90c, and instead call clang directly.

	clang $< \
              --target=wasm32 \
              -O3 \
              -flto \
              -nostdlib \
              -Wl,--export-all \
              -Wl,--no-entry \
              -Wl,--lto-O3 \
              -o $@

tolauwae avatar Oct 29 '21 13:10 tolauwae