Prepare

toolchain

Just choose one of the following — I’d like to say so. But IDK why while it’s said “clang has WASI support out of box, my installing clang&llvm without following SDK only results in header-missing when compiling

Compile

Config

# ./nim.cfg, you can just place it in $CWD
--cpu:wasm32
#--os:wasi
--os:linux
--threads:off
--cc:clang
clang.options.always="--target=wasm32-wasi "
clang.options.always%="${clang.options.always} -D_WASI_EMULATED_MMAN "

# demo for `--export` usage:
# clang.options.linker="-Wl,--export=abcdef "
clang.options.linker%="${clang.options.linker} -Wl,-lwasi-emulated-mman "

# check for -d:noSignalHandler
@if not noSignalHandler:
  clang.options.always%="${clang.options.always} -D_WASI_EMULATED_SIGNAL "
  clang.options.linker%="${clang.options.linker} -Wl,-lwasi-emulated-signal "
@end

Another example

Export to WASM

To make function symbol exported to wasm, 3 methods:

util to gen export_name attribute

Run Compilation