Skip to content

Commit

Permalink
compileopts, targets, main: support Wasmtime v14
Browse files Browse the repository at this point in the history
Wasmtime v14 (released 2023-10-20) has a breaking change in how CLI arguments are processed.

1. Arguments after the .wasm module to run are passed to the Wasm module. The -- flag has no effect.
2. --mapdir becomes --dir, and the arguments are reversed: --dir=HOST:GUEST
  • Loading branch information
ydnar committed Oct 24, 2023
1 parent fd50227 commit 4ff1faa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion compileopts/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,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",
Expand Down
12 changes: 7 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -820,12 +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: --
// Mark end of wasmtime arguments and start of program ones: --
// This should not be necessary as of Wasmtime v14:
// https://github.com/bytecodealliance/wasmtime/pull/6946
args = append(args, "--")
args = append(args, cmdArgs...)
}
Expand Down Expand Up @@ -876,7 +878,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
Expand Down
2 changes: 1 addition & 1 deletion targets/wasi.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
"extra-files": [
"src/runtime/asm_tinygowasm.S"
],
"emulator": "wasmtime --mapdir=/tmp::{tmpDir} {}"
"emulator": "wasmtime --dir={tmpDir}::/tmp {}"
}

0 comments on commit 4ff1faa

Please sign in to comment.