From a545f17d2ea55807de4b97cf4f52f01d5d4f1815 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 10 Aug 2023 22:36:35 +0200 Subject: wasm: add support for GOOS=wasip1 This adds true GOOS=wasip1 support in addition to our existing -target=wasi support. The old support for WASI isn't removed, but should be treated as deprecated and will likely be removed eventually to reduce the test burden. --- compileopts/target.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'compileopts') diff --git a/compileopts/target.go b/compileopts/target.go index 7545f458c..f83464b27 100644 --- a/compileopts/target.go +++ b/compileopts/target.go @@ -191,12 +191,15 @@ func LoadTarget(options *Options) (*TargetSpec, error) { default: return nil, fmt.Errorf("invalid GOARM=%s, must be 5, 6, or 7", options.GOARM) } + case "wasm": + llvmarch = "wasm32" default: llvmarch = options.GOARCH } llvmvendor := "unknown" llvmos := options.GOOS - if llvmos == "darwin" { + switch llvmos { + case "darwin": // Use macosx* instead of darwin, otherwise darwin/arm64 will refer // to iOS! llvmos = "macosx10.12.0" @@ -207,6 +210,8 @@ func LoadTarget(options *Options) (*TargetSpec, error) { llvmos = "macosx11.0.0" } llvmvendor = "apple" + case "wasip1": + llvmos = "wasi" } // Target triples (which actually have four components, but are called // triples for historical reasons) have the form: @@ -277,6 +282,15 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { case "arm64": spec.CPU = "generic" spec.Features = "+neon" + case "wasm": + spec.CPU = "generic" + spec.Features = "+bulk-memory,+nontrapping-fptoint,+sign-ext" + spec.BuildTags = append(spec.BuildTags, "tinygo.wasm") + spec.CFlags = append(spec.CFlags, + "-mbulk-memory", + "-mnontrapping-fptoint", + "-msign-ext", + ) } if goos == "darwin" { spec.Linker = "ld.lld" @@ -320,6 +334,22 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { "--no-insert-timestamp", "--no-dynamicbase", ) + } else if goos == "wasip1" { + spec.GC = "" // use default GC + spec.Scheduler = "asyncify" + spec.Linker = "wasm-ld" + spec.RTLib = "compiler-rt" + spec.Libc = "wasi-libc" + spec.DefaultStackSize = 1024 * 16 // 16kB + spec.LDFlags = append(spec.LDFlags, + "--stack-first", + "--no-demangle", + ) + spec.Emulator = "wasmtime --mapdir=/tmp::{tmpDir} {}" + spec.ExtraFiles = append(spec.ExtraFiles, + "src/runtime/asm_tinygowasm.S", + "src/internal/task/task_asyncify_wasm.S", + ) } else { spec.LDFlags = append(spec.LDFlags, "-no-pie", "-Wl,--gc-sections") // WARNING: clang < 5.0 requires -nopie } -- cgit v1.2.3