]> Cypherpunks repositories - gostls13.git/commitdiff
misc/wasm: support new wasmtime CLI
authorJohan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Fri, 10 Nov 2023 06:20:27 +0000 (22:20 -0800)
committerJohan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Sun, 19 Nov 2023 21:11:54 +0000 (21:11 +0000)
Wasmtime 14.0.0 introduced new CLI flags and removed the existing
flags, in particular the --max-wasm-stack flag we were using to avoid
errors in some tests.

This introduces a regular expression based switch that uses the old
flags for wasmtime versions < 14 and the new flags otherwise.

Fixes #63718

Change-Id: I44673e7d9f8729065757abdbf8c41e8a61897d6a
Reviewed-on: https://go-review.googlesource.com/c/go/+/541219
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
misc/wasm/go_wasip1_wasm_exec

index dc110327af7a6361081c4c7b718c4816e6382870..cd16b96ea719ef849cb061a5a86567414c6ea52f 100755 (executable)
@@ -14,8 +14,15 @@ case "$GOWASIRUNTIME" in
                exec wazero run -mount /:/ -env-inherit -cachedir "${TMPDIR:-/tmp}"/wazero ${GOWASIRUNTIMEARGS:-} "$1" "${@:2}"
                ;;
        "wasmtime" | "")
-               # TODO(go.dev/issue/63718): Switch to the new CLI offered in the major version 14 of Wasmtime.
-               exec env WASMTIME_NEW_CLI=0 wasmtime run --dir=/ --env PWD="$PWD" --env PATH="$PATH" --max-wasm-stack 1048576 ${GOWASIRUNTIMEARGS:-} "$1" -- "${@:2}"
+               # Match the major version in "wasmtime-cli 14.0.0". For versions before 14
+               # we need to use the old CLI. This requires Bash v3.0 and above.
+               # TODO(johanbrandhorst): Remove this condition once 1.22 is released.
+               # From 1.23 onwards we'll only support the new wasmtime CLI.
+               if [[ "$(wasmtime --version)" =~ wasmtime-cli[[:space:]]([0-9]+)\.[0-9]+\.[0-9]+ && "${BASH_REMATCH[1]}" -lt 14 ]]; then
+                       exec wasmtime run --dir=/ --env PWD="$PWD" --env PATH="$PATH" --max-wasm-stack 1048576 ${GOWASIRUNTIMEARGS:-} "$1" -- "${@:2}"
+               else
+                       exec wasmtime run --dir=/ --env PWD="$PWD" --env PATH="$PATH" -W max-wasm-stack=1048576 ${GOWASIRUNTIMEARGS:-} "$1" "${@:2}"
+               fi
                ;;
        *)
                echo "Unknown Go WASI runtime specified: $GOWASIRUNTIME"