From be1e1fa180f333bb4c0818b988eb30e87773a583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 22 Jul 2024 21:59:56 +0200 Subject: [PATCH] std.Build.Step.Run: Fix invocation syntax for Wasmtime 14+. https://github.com/bytecodealliance/wasmtime/issues/7384 --- lib/std/Build/Step/Run.zig | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig index ff0c5e418aa6..dbb865047be7 100644 --- a/lib/std/Build/Step/Run.zig +++ b/lib/std/Build/Step/Run.zig @@ -1007,10 +1007,25 @@ fn runCommand( }, .wasmtime => |bin_name| { if (b.enable_wasmtime) { + // https://github.com/bytecodealliance/wasmtime/issues/7384 + // + // In Wasmtime versions prior to 14, options passed after the module name + // could be interpreted by Wasmtime if it recognized them. As with many CLI + // tools, the `--` token is used to stop that behavior and indicate that the + // remaining arguments are for the WASM program being executed. Historically, + // we passed `--` after the module name here. + // + // After version 14, the `--` can no longer be passed after the module name, + // but is also not necessary as Wasmtime will no longer try to interpret + // options after the module name. So, we could just simply omit `--` for + // newer Wasmtime versions. But to maintain compatibility for older versions + // that still try to interpret options after the module name, we have moved + // the `--` before the module name. This appears to work for both old and + // new Wasmtime versions. try interp_argv.append(bin_name); try interp_argv.append("--dir=."); - try interp_argv.append(argv[0]); try interp_argv.append("--"); + try interp_argv.append(argv[0]); try interp_argv.appendSlice(argv[1..]); } else { return failForeign(run, "-fwasmtime", argv[0], exe);