builder: always run wasm-opt for wasm32 binaries

Этот коммит содержится в:
Damian Gryski 2022-12-08 13:34:01 -08:00 коммит произвёл Ron Evans
родитель f3d0195d35
коммит 675b8e3f3c

Просмотреть файл

@ -800,28 +800,38 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe
} }
} }
// Run wasm-opt if necessary. // Run wasm-opt for wasm binaries
if config.Scheduler() == "asyncify" { if arch := strings.Split(config.Triple(), "-")[0]; arch == "wasm32" {
var optLevel, shrinkLevel int var opt string
switch config.Options.Opt { switch config.Options.Opt {
case "none", "0": case "none", "0":
opt = "-O0"
case "1": case "1":
optLevel = 1 opt = "-O1"
case "2": case "2":
optLevel = 2 opt = "-O2"
case "s": case "s":
optLevel = 2 opt = "-Os"
shrinkLevel = 1
case "z": case "z":
optLevel = 2 opt = "-Oz"
shrinkLevel = 2
default: default:
return fmt.Errorf("unknown opt level: %q", config.Options.Opt) return fmt.Errorf("unknown opt level: %q", config.Options.Opt)
} }
cmd := exec.Command(goenv.Get("WASMOPT"), "--asyncify", "-g",
"--optimize-level", strconv.Itoa(optLevel), var args []string
"--shrink-level", strconv.Itoa(shrinkLevel),
executable, "--output", executable) if config.Scheduler() == "asyncify" {
args = append(args, "--asyncify")
}
args = append(args,
opt,
"-g",
executable,
"--output", executable,
)
cmd := exec.Command(goenv.Get("WASMOPT"), args...)
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr