mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-20 02:25:14 -07:00
Add support for Node without wasmer-js
This commit is contained in:
parent
25316cce5a
commit
88a591050e
@ -27,12 +27,6 @@ if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wasmer" ]; then
|
||||
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
|
||||
|
||||
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wasm3" ]; then
|
||||
if command -v wasm3 >/dev/null; then
|
||||
wasm3 "$1" && exit 0
|
||||
@ -65,5 +59,27 @@ if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "lucet" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
echo "WebAssembly runtime failed" >&2
|
||||
exit 1
|
||||
|
Loading…
Reference in New Issue
Block a user