Skip to content

Instantly share code, notes, and snippets.

@myobie
Last active June 3, 2020 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myobie/e5f15231cca4fc22e0b77a741ea64772 to your computer and use it in GitHub Desktop.
Save myobie/e5f15231cca4fc22e0b77a741ea64772 to your computer and use it in GitHub Desktop.
wasi-sdk release binaries example
#!/bin/bash
set -e
set -o pipefail
mkdir -p {src,tmp,lib}
cat <<-'EOF' >src/main.c
int main(void)
{
return 0;
}
EOF
pushd tmp
wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-10/wasi-sdk-10.0-macos.tar.gz
tar -xf wasi-sdk-10.0-macos.tar.gz
popd
PATH="$(cd tmp/wasi-sdk-10.0/bin && pwd):$PATH"
WASI_SYSROOT="$(cd tmp/wasi-sdk-10.0/share/wasi-sysroot && pwd)"
which clang
FILES=$(find src -name "*.c")
clang \
--target=wasm32-wasi \
--sysroot="${WASI_SYSROOT}" \
-isysroot="${WASI_SYSROOT}" \
-Oz \
-flto \
-Wl,--export-all \
-Wl,--lto-O2 \
-o ./lib/test.wasm \
$FILES
pushd lib
wasm2wat test.wasm -o test.wat
popd
rm -rf ./src/
rm -rf ./tmp/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment