From 666d2bd501eedaf26c7b5c90027e95afdbd579e9 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 3 Oct 2024 16:32:01 +0200 Subject: [PATCH] builder: keep wasm temporary files Don't rename them when -work is set, instead update result.Binary each time and leave result.Executable be the linker output (as intended: result.Executable should be the unmodified linker output). --- builder/build.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/builder/build.go b/builder/build.go index 780dc8df49..3f12b99911 100644 --- a/builder/build.go +++ b/builder/build.go @@ -823,19 +823,13 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe args = append(args, "--asyncify") } - exeunopt := result.Executable - - if config.Options.Work { - // Keep the work direction around => don't overwrite the .wasm binary with the optimized version - exeunopt += ".pre-wasm-opt" - os.Rename(result.Executable, exeunopt) - } - + inputFile := result.Binary + result.Binary = result.Executable + ".wasmopt" args = append(args, opt, "-g", - exeunopt, - "--output", result.Executable, + inputFile, + "--output", result.Binary, ) wasmopt := goenv.Get("WASMOPT") @@ -865,13 +859,15 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe // wasm-tools component embed -w wasi:cli/command // $$(tinygo env TINYGOROOT)/lib/wasi-cli/wit/ main.wasm -o embedded.wasm + componentEmbedInputFile := result.Binary + result.Binary = result.Executable + ".wasm-component-embed" args := []string{ "component", "embed", "-w", witWorld, witPackage, - result.Executable, - "-o", result.Executable, + componentEmbedInputFile, + "-o", result.Binary, } wasmtools := goenv.Get("WASMTOOLS") @@ -888,11 +884,13 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe } // wasm-tools component new embedded.wasm -o component.wasm + componentNewInputFile := result.Binary + result.Binary = result.Executable + ".wasm-component-new" args = []string{ "component", "new", - result.Executable, - "-o", result.Executable, + componentNewInputFile, + "-o", result.Binary, } if config.Options.PrintCommands != nil {