From 9145cc39e11e8f46e977c4f88f3df5a7710ba966 Mon Sep 17 00:00:00 2001 From: Kohei Tokunaga Date: Sat, 6 Jan 2024 18:47:26 +0900 Subject: [PATCH] Migrate to new wasmtime CLI flags Signed-off-by: Kohei Tokunaga --- Dockerfile.test | 2 +- cmd/c2w-net/main.go | 18 ++++++++++++------ tests/integration/wasmtime_test.go | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Dockerfile.test b/Dockerfile.test index 6d503be..4cc11e9 100644 --- a/Dockerfile.test +++ b/Dockerfile.test @@ -6,7 +6,7 @@ ARG WAMR_VERSION=1.3.0 ARG WASMEDGE_VERSION=0.13.5 ARG GOLANG_VERSION=1.21.5 ARG WASMER_VERSION=v4.2.5 -ARG WASMTIME_VERSION=13.0.0 +ARG WASMTIME_VERSION=16.0.0 FROM docker:${DOCKER_VERSION}-dind AS dind FROM docker/buildx-bin:${BUILDX_VERSION} AS buildx diff --git a/cmd/c2w-net/main.go b/cmd/c2w-net/main.go index e8b0ceb..1cfd75f 100644 --- a/cmd/c2w-net/main.go +++ b/cmd/c2w-net/main.go @@ -26,11 +26,12 @@ func main() { var portFlags sliceFlags flag.Var(&portFlags, "p", "map port between host and guest (host:guest). -mac must be set correctly.") var ( - debug = flag.Bool("debug", false, "enable debug print") - listenWS = flag.Bool("listen-ws", false, "listen on a websocket port specified as argument") - invoke = flag.Bool("invoke", false, "invoke the container with NW support") - mac = flag.String("mac", vmMAC, "mac address assigned to the container") - wasiAddr = flag.String("wasi-addr", "127.0.0.1:1234", "IP address used to communicate between wasi and network stack (valid only with invoke flag)") // TODO: automatically use empty random port or unix socket + debug = flag.Bool("debug", false, "enable debug print") + listenWS = flag.Bool("listen-ws", false, "listen on a websocket port specified as argument") + invoke = flag.Bool("invoke", false, "invoke the container with NW support") + mac = flag.String("mac", vmMAC, "mac address assigned to the container") + wasiAddr = flag.String("wasi-addr", "127.0.0.1:1234", "IP address used to communicate between wasi and network stack (valid only with invoke flag)") // TODO: automatically use empty random port or unix socket + wasmtimeCli13 = flag.Bool("wasmtime-cli-13", false, "Use old wasmtime CLI (<= 13)") ) flag.Parse() args := flag.Args() @@ -93,7 +94,12 @@ func main() { fmt.Fprintf(os.Stderr, "failed AcceptQemu: %v\n", err) } }() - cmd := exec.Command("wasmtime", append([]string{"run", "--tcplisten=" + *wasiAddr, "--env='LISTEN_FDS=1'", "--"}, args...)...) + var cmd *exec.Cmd + if *wasmtimeCli13 { + cmd = exec.Command("wasmtime", append([]string{"run", "--tcplisten=" + *wasiAddr, "--env='LISTEN_FDS=1'", "--"}, args...)...) + } else { + cmd = exec.Command("wasmtime", append([]string{"run", "-S", "preview2=n", "-S", "tcplisten=" + *wasiAddr, "--env='LISTEN_FDS=1'", "--"}, args...)...) + } cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr diff --git a/tests/integration/wasmtime_test.go b/tests/integration/wasmtime_test.go index 7084fb9..e3f69d3 100644 --- a/tests/integration/wasmtime_test.go +++ b/tests/integration/wasmtime_test.go @@ -57,7 +57,7 @@ func TestWasmtime(t *testing.T) { assert.NilError(t, os.Remove(mapdirTestDir)) }, RuntimeOpts: func(t *testing.T, workdir string) []string { - return []string{"--mapdir=/mapped/dir/test::" + filepath.Join(workdir, "wasmtime-mapdirtest")} + return []string{"--dir=" + filepath.Join(workdir, "wasmtime-mapdirtest") + "::/mapped/dir/test"} }, Args: utils.StringFlags("cat", "/mapped/dir/test/hi"), Want: utils.WantString("teststring"), @@ -102,7 +102,7 @@ func TestWasmtime(t *testing.T) { }, Runtime: "wasmtime", RuntimeOpts: func(t *testing.T, workdir string) []string { - return []string{"--mapdir=/mapped/dir/test::" + filepath.Join(workdir, "wasmtime-mapdirtest-io")} + return []string{"--dir=" + filepath.Join(workdir, "wasmtime-mapdirtest-io") + "::/mapped/dir/test"} }, Args: utils.StringFlags("sh"), Want: utils.WantPrompt("/ # ",