From 174d49235552381552c34bbe4a98d0a2ff6f046f Mon Sep 17 00:00:00 2001 From: Randy Reddig Date: Thu, 2 Nov 2023 11:49:52 -0700 Subject: [PATCH] compileopts, targets, main: support Wasmtime v14 (#3972) compileopts, targets, main: support Wasmtime v14 --- .github/workflows/linux.yml | 8 ++++---- .github/workflows/windows.yml | 4 ++-- compileopts/target.go | 2 +- main.go | 13 +++++++------ targets/wasi.json | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index c9d75646e4..01c7e273d5 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -140,8 +140,8 @@ jobs: - name: Install wasmtime run: | mkdir -p $HOME/.wasmtime $HOME/.wasmtime/bin - curl https://github.com/bytecodealliance/wasmtime/releases/download/v13.0.0/wasmtime-v13.0.0-x86_64-linux.tar.xz -o wasmtime-v13.0.0-x86_64-linux.tar.xz -SfL - tar -C $HOME/.wasmtime/bin --wildcards -xf wasmtime-v13.0.0-x86_64-linux.tar.xz --strip-components=1 wasmtime-v13.0.0-x86_64-linux/* + curl https://github.com/bytecodealliance/wasmtime/releases/download/v14.0.4/wasmtime-v14.0.4-x86_64-linux.tar.xz -o wasmtime-v14.0.4-x86_64-linux.tar.xz -SfL + tar -C $HOME/.wasmtime/bin --wildcards -xf wasmtime-v14.0.4-x86_64-linux.tar.xz --strip-components=1 wasmtime-v14.0.4-x86_64-linux/* echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH - name: Download release artifact uses: actions/download-artifact@v3 @@ -187,8 +187,8 @@ jobs: - name: Install wasmtime run: | mkdir -p $HOME/.wasmtime $HOME/.wasmtime/bin - curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v13.0.0/wasmtime-v13.0.0-x86_64-linux.tar.xz -o wasmtime-v13.0.0-x86_64-linux.tar.xz -SfL - tar -C $HOME/.wasmtime/bin --wildcards -xf wasmtime-v13.0.0-x86_64-linux.tar.xz --strip-components=1 wasmtime-v13.0.0-x86_64-linux/* + curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v14.0.4/wasmtime-v14.0.4-x86_64-linux.tar.xz -o wasmtime-v14.0.4-x86_64-linux.tar.xz -SfL + tar -C $HOME/.wasmtime/bin --wildcards -xf wasmtime-v14.0.4-x86_64-linux.tar.xz --strip-components=1 wasmtime-v14.0.4-x86_64-linux/* echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH - name: Restore LLVM source cache uses: actions/cache/restore@v3 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index c4226c31f0..e95415f87b 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -96,7 +96,7 @@ jobs: run: make wasi-libc - name: Install wasmtime run: | - scoop install wasmtime@13.0.0 + scoop install wasmtime@14.0.4 - name: make gen-device run: make -j3 gen-device - name: Test TinyGo @@ -203,7 +203,7 @@ jobs: - name: Install Dependencies shell: bash run: | - scoop install binaryen && scoop install wasmtime@13.0.0 + scoop install binaryen && scoop install wasmtime@14.0.4 - name: Checkout uses: actions/checkout@v3 - name: Install Go diff --git a/compileopts/target.go b/compileopts/target.go index b21a0183a4..f7b8a065f3 100644 --- a/compileopts/target.go +++ b/compileopts/target.go @@ -386,7 +386,7 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { "--stack-first", "--no-demangle", ) - spec.Emulator = "wasmtime --mapdir=/tmp::{tmpDir} {}" + spec.Emulator = "wasmtime --dir={tmpDir}::/tmp {}" spec.ExtraFiles = append(spec.ExtraFiles, "src/runtime/asm_tinygowasm.S", "src/internal/task/task_asyncify_wasm.S", diff --git a/main.go b/main.go index 72bf76a113..f9eb4eff47 100644 --- a/main.go +++ b/main.go @@ -797,7 +797,7 @@ func buildAndRun(pkgName string, config *compileopts.Config, stdout io.Writer, c needsEnvInVars = true } } - var args, env []string + var args, emuArgs, env []string var extraCmdEnv []string if needsEnvInVars { runtimeGlobals := make(map[string]string) @@ -820,13 +820,14 @@ func buildAndRun(pkgName string, config *compileopts.Config, stdout io.Writer, c } else if config.EmulatorName() == "wasmtime" { // Wasmtime needs some special flags to pass environment variables // and allow reading from the current directory. - args = append(args, "--dir=.") + emuArgs = append(emuArgs, "--dir=.") for _, v := range environmentVars { - args = append(args, "--env", v) + emuArgs = append(emuArgs, "--env", v) } if len(cmdArgs) != 0 { - // mark end of wasmtime arguments and start of program ones: -- - args = append(args, "--") + // Use of '--' argument no longer necessary as of Wasmtime v14: + // https://github.com/bytecodealliance/wasmtime/pull/6946 + // args = append(args, "--") args = append(args, cmdArgs...) } @@ -876,7 +877,7 @@ func buildAndRun(pkgName string, config *compileopts.Config, stdout io.Writer, c return result, err } name = emulator[0] - emuArgs := append([]string(nil), emulator[1:]...) + emuArgs = append(emuArgs, emulator[1:]...) args = append(emuArgs, args...) } var cmd *exec.Cmd diff --git a/targets/wasi.json b/targets/wasi.json index 1d845c741f..1e1fff415f 100644 --- a/targets/wasi.json +++ b/targets/wasi.json @@ -22,5 +22,5 @@ "extra-files": [ "src/runtime/asm_tinygowasm.S" ], - "emulator": "wasmtime --mapdir=/tmp::{tmpDir} {}" + "emulator": "wasmtime --dir={tmpDir}::/tmp {}" }