Last active
June 3, 2020 11:33
-
-
Save myobie/e5f15231cca4fc22e0b77a741ea64772 to your computer and use it in GitHub Desktop.
wasi-sdk release binaries example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/src/ | |
/tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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