Reputation: 477
Looking at the following WasmFiddle, once compiled to wasm the file is 259bytes. I'm trying to from WasmFiddle move to my local environment, so i've downloaded and installed the Emscripten compiler.
Now, since the Emscripten environment adds extra features same code is 22KB.
Q: How can I compile the c code on my local machine, and keep it lean? Even better how can I have the same output as the WasmFiddle?
Upvotes: 3
Views: 678
Reputation: 2793
A couple options using Emscripten's emcc
can keep your outputted wasm file lean.
Optimization:
-Oz
Only my code (removes Emscripten framework code):
-s ONLY_MY_CODE=1
These flags should bring you very close to your desired 259 bytes.
Upvotes: 1
Reputation: 70142
You can see the sourcecode for the server-side component that WasmFiddle uses for compilation here:
https://github.com/wasdk/wasmexplorer-service/blob/master/scripts/compile.sh
It is very similar to c2wasm, which also provides a minimal output:
https://github.com/tpimh/wasm-toolchain
Upvotes: 5