fix: only infer target for wasm when GOOS and GOARCH are set correctly, not just based on file extension

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2025-02-21 10:33:54 +01:00
committed by Ron Evans
parent 056394e24b
commit b0aef96340
3 changed files with 21 additions and 31 deletions
+18 -2
View File
@@ -1684,8 +1684,24 @@ func main() {
usage(command)
os.Exit(1)
}
if options.Target == "" && filepath.Ext(outpath) == ".wasm" {
options.Target = "wasm"
if options.Target == "" {
switch {
case options.GOARCH == "wasm":
switch options.GOOS {
case "js":
options.Target = "wasm"
case "wasip1":
options.Target = "wasip1"
case "wasip2":
options.Target = "wasip2"
default:
fmt.Fprintln(os.Stderr, "GOARCH=wasm but GOOS is not set correctly. Please set GOOS to wasm, wasip1, or wasip2.")
os.Exit(1)
}
case filepath.Ext(outpath) == ".wasm":
fmt.Fprintln(os.Stderr, "you appear to want to build a wasm file, but have not specified either a target flag, or the GOARCH/GOOS to use.")
os.Exit(1)
}
}
err := Build(pkgName, outpath, options)