mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-10 14:03:39 +00:00
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:
@@ -69,7 +69,6 @@ func TestClangAttributes(t *testing.T) {
|
|||||||
{GOOS: "darwin", GOARCH: "arm64"},
|
{GOOS: "darwin", GOARCH: "arm64"},
|
||||||
{GOOS: "windows", GOARCH: "amd64"},
|
{GOOS: "windows", GOARCH: "amd64"},
|
||||||
{GOOS: "windows", GOARCH: "arm64"},
|
{GOOS: "windows", GOARCH: "arm64"},
|
||||||
{GOOS: "wasip1", GOARCH: "wasm"},
|
|
||||||
} {
|
} {
|
||||||
name := "GOOS=" + options.GOOS + ",GOARCH=" + options.GOARCH
|
name := "GOOS=" + options.GOOS + ",GOARCH=" + options.GOARCH
|
||||||
if options.GOARCH == "arm" {
|
if options.GOARCH == "arm" {
|
||||||
|
|||||||
+3
-28
@@ -356,17 +356,7 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
|
|||||||
return nil, fmt.Errorf("invalid GOMIPS=%s: must be hardfloat or softfloat", options.GOMIPS)
|
return nil, fmt.Errorf("invalid GOMIPS=%s: must be hardfloat or softfloat", options.GOMIPS)
|
||||||
}
|
}
|
||||||
case "wasm":
|
case "wasm":
|
||||||
llvmarch = "wasm32"
|
return nil, fmt.Errorf("GOARCH=wasm but GOOS is unset. Please set GOOS to wasm, wasip1, or wasip2.")
|
||||||
spec.CPU = "generic"
|
|
||||||
spec.Features = "+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types"
|
|
||||||
spec.BuildTags = append(spec.BuildTags, "tinygo.wasm")
|
|
||||||
spec.CFlags = append(spec.CFlags,
|
|
||||||
"-mbulk-memory",
|
|
||||||
"-mnontrapping-fptoint",
|
|
||||||
"-mno-multivalue",
|
|
||||||
"-mno-reference-types",
|
|
||||||
"-msign-ext",
|
|
||||||
)
|
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown GOARCH=%s", options.GOARCH)
|
return nil, fmt.Errorf("unknown GOARCH=%s", options.GOARCH)
|
||||||
}
|
}
|
||||||
@@ -446,23 +436,8 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
|
|||||||
"--no-insert-timestamp",
|
"--no-insert-timestamp",
|
||||||
"--no-dynamicbase",
|
"--no-dynamicbase",
|
||||||
)
|
)
|
||||||
case "wasip1":
|
case "wasm", "wasip1", "wasip2":
|
||||||
spec.GC = "" // use default GC
|
return nil, fmt.Errorf("GOOS=%s but GOARCH is unset. Please set GOARCH to wasm", options.GOOS)
|
||||||
spec.Scheduler = "asyncify"
|
|
||||||
spec.Linker = "wasm-ld"
|
|
||||||
spec.RTLib = "compiler-rt"
|
|
||||||
spec.Libc = "wasi-libc"
|
|
||||||
spec.DefaultStackSize = 1024 * 64 // 64kB
|
|
||||||
spec.LDFlags = append(spec.LDFlags,
|
|
||||||
"--stack-first",
|
|
||||||
"--no-demangle",
|
|
||||||
)
|
|
||||||
spec.Emulator = "wasmtime run --dir={tmpDir}::/tmp {}"
|
|
||||||
spec.ExtraFiles = append(spec.ExtraFiles,
|
|
||||||
"src/runtime/asm_tinygowasm.S",
|
|
||||||
"src/internal/task/task_asyncify_wasm.S",
|
|
||||||
)
|
|
||||||
llvmos = "wasi"
|
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown GOOS=%s", options.GOOS)
|
return nil, fmt.Errorf("unknown GOOS=%s", options.GOOS)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1684,8 +1684,24 @@ func main() {
|
|||||||
usage(command)
|
usage(command)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if options.Target == "" && filepath.Ext(outpath) == ".wasm" {
|
if options.Target == "" {
|
||||||
options.Target = "wasm"
|
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)
|
err := Build(pkgName, outpath, options)
|
||||||
|
|||||||
Reference in New Issue
Block a user