Skip to content

Commit

Permalink
builder: keep wasm temporary files
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
aykevl authored and deadprogram committed Oct 3, 2024
1 parent 9d14489 commit 666d2bd
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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 {
Expand Down

0 comments on commit 666d2bd

Please sign in to comment.