You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1009 B
Bash
45 lines
1009 B
Bash
#!/usr/bin/env bash
|
|
INTERMEDIATE=intermediate.wat
|
|
|
|
read -r -d '' PREAMBLE <<'EOF'
|
|
(module $main
|
|
EOF
|
|
|
|
read -r -d '' EPILOGUE <<'EOF'
|
|
(memory $memory (export "memory") 10)
|
|
)
|
|
EOF
|
|
|
|
# remove file when done
|
|
trap "err=$?; rm $INTERMEDIATE; exit $err" EXIT
|
|
|
|
# load all sources
|
|
find ./src | grep -e '\.wat$' | xargs cat > $INTERMEDIATE
|
|
|
|
# Separate out imports (must be defined first)
|
|
IMPORT_REGEX='^\(import .*$'
|
|
IMPORTS="$(cat $INTERMEDIATE | grep -E "$IMPORT_REGEX")"
|
|
NONIMPORTS="$(cat $INTERMEDIATE | grep -vE "$IMPORT_REGEX")"
|
|
|
|
# generate file
|
|
echo "$PREAMBLE" > $INTERMEDIATE
|
|
echo "" >> $INTERMEDIATE
|
|
echo "$IMPORTS" >> $INTERMEDIATE
|
|
echo "" >> $INTERMEDIATE
|
|
echo "$NONIMPORTS" >> $INTERMEDIATE
|
|
echo "$EPILOGUE" >> $INTERMEDIATE
|
|
|
|
# test file
|
|
wat2wasm $INTERMEDIATE
|
|
result=$?
|
|
mv intermediate.wasm output.wasm
|
|
|
|
if [ 0 -ne $result ]; then
|
|
echo "Build failed"
|
|
# cat $INTERMEDIATE
|
|
exit $?
|
|
else
|
|
echo "Build succeeded, running:"
|
|
wasmtime ./output.wasm --wasi-modules wasi-common --tcplisten 127.0.0.1:8080
|
|
fi
|