Skip to content

Instantly share code, notes, and snippets.

@dhil
Created January 4, 2024 15:39
Show Gist options
  • Save dhil/eb63d2c55d038c4d8deccea47fcb2a96 to your computer and use it in GitHub Desktop.
Save dhil/eb63d2c55d038c4d8deccea47fcb2a96 to your computer and use it in GitHub Desktop.
A thin wrapper around wasmtime's CLI to easily run WasmFX programs
#!/usr/bin/env bash
#
# A thin wrapper around wasmtime's CLI to easily run WasmFX programs.
#
DEBUG_BIN=~/projects/wasmfx/wasmtime/target/debug/wasmtime
RELEASE_BIN=~/projects/wasmfx/wasmtime/target/release/wasmtime
WASMTIME=$DEBUG_BIN
WFLAGS="exceptions,function-references,typed-continuations"
CLI_ARGS=("$@")
function compile ()
{
declare -a args
args=("$@")
$WASMTIME compile -W="$WFLAGS" ${args[@]}
}
function run ()
{
declare -a args
args=("$@")
$WASMTIME run --allow-precompiled -W="$WFLAGS" ${args[@]}
}
if [[ ${#CLI_ARGS[@]} -lt 1 ]]; then
echo "usage: wasmfxtime [ debug | release ] <compile | run> <args...>"
exit 1
fi
case ${CLI_ARGS[0]} in
"release")
shift 1
BIN=$RELEASE_BIN
;;
"debug")
shift 1
BIN=$DEBUG_BIN
;;
*)
BIN=$DEBUG_BIN
;;
esac
CLI_ARGS=("$@")
case ${CLI_ARGS[0]} in
"compile")
shift 1
compile "$@"
;;
"run")
shift 1
run "$@"
;;
*)
echo "unknown command"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment