2019-05-30 10:04:55 -04:00
|
|
|
#! /bin/sh
|
|
|
|
|
|
|
|
MAX_MEMORY_TESTS="67108864"
|
|
|
|
|
2021-02-18 17:33:43 -05:00
|
|
|
unset LDFLAGS
|
|
|
|
unset CFLAGS
|
|
|
|
|
2020-06-04 04:53:29 -04:00
|
|
|
if command -v wasm-opt >/dev/null; then
|
2021-11-18 08:15:26 -05:00
|
|
|
wasm-opt -O4 -o "${1}.tmp" "$1" && mv -f "${1}.tmp" "$1"
|
2020-06-04 04:53:29 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wavm" ]; then
|
|
|
|
if command -v wavm >/dev/null; then
|
|
|
|
wavm run --abi=wasi "$1" && exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-05-30 10:04:55 -04:00
|
|
|
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wasmtime" ]; then
|
|
|
|
if command -v wasmtime >/dev/null; then
|
2021-02-18 17:33:43 -05:00
|
|
|
wasmtime run --dir=. "$1" && exit 0
|
2019-05-30 10:04:55 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-10-11 11:31:57 -04:00
|
|
|
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wasmer" ]; then
|
|
|
|
if command -v wasmer >/dev/null; then
|
2021-02-18 17:33:43 -05:00
|
|
|
wasmer run "$1" "--${WASMER_BACKEND:-cranelift}" --dir=. && exit 0
|
2019-10-11 11:31:57 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-02-04 13:52:25 -05:00
|
|
|
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wasm3" ]; then
|
|
|
|
if command -v wasm3 >/dev/null; then
|
|
|
|
wasm3 "$1" && exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-02-18 17:33:43 -05:00
|
|
|
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "iwasm" ]; then
|
|
|
|
if iwasm | grep -qi wasi >/dev/null 2>&1; then
|
|
|
|
iwasm "$1" && exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2022-05-12 06:36:11 -04:00
|
|
|
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wasmedge" ]; then
|
|
|
|
if command -v wasmedgec >/dev/null && command -v wasmedge >/dev/null; then
|
|
|
|
wasmedgec "$1" "${1}.so" &&
|
|
|
|
wasmedge --dir=.:. "${1}.so" &&
|
|
|
|
rm -f "${1}.so" &&
|
|
|
|
exit 0
|
2021-02-20 14:55:52 -05:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-02-20 15:24:29 -05:00
|
|
|
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "node" ]; then
|
|
|
|
if echo | node --experimental-wasi-unstable-preview1 >/dev/null 2>&1; then
|
|
|
|
{
|
|
|
|
echo "import fs from 'fs'; import { WASI } from 'wasi';"
|
|
|
|
echo "const wasi = new WASI({args: process.argv, env: process.env, preopens: {'.':'.'}});"
|
|
|
|
echo "const importObject = { wasi_snapshot_preview1: wasi.wasiImport };"
|
|
|
|
echo "const wasm = await WebAssembly.compile(fs.readFileSync('${1}'));"
|
|
|
|
echo "const instance = await WebAssembly.instantiate(wasm, importObject);"
|
|
|
|
echo "wasi.start(instance);"
|
|
|
|
} >"${1}.mjs"
|
|
|
|
cat "${1}.mjs" >/tmp/a
|
|
|
|
node --experimental-wasi-unstable-preview1 "${1}.mjs" 2>/tmp/err &&
|
|
|
|
rm -f "${1}.mjs" && exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wasmer-js" ]; then
|
|
|
|
if command -v wasmer-js >/dev/null; then
|
|
|
|
wasmer-js run "$1" --dir=. && exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-05-30 10:04:55 -04:00
|
|
|
echo "WebAssembly runtime failed" >&2
|
|
|
|
exit 1
|