aboutsummaryrefslogtreecommitdiffhomepage
path: root/compileopts/target.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2023-08-10 22:36:35 +0200
committerRon Evans <[email protected]>2023-08-17 18:16:54 +0200
commita545f17d2ea55807de4b97cf4f52f01d5d4f1815 (patch)
tree075ea83380859d7604f67ca4dbaafc7ff76f4e90 /compileopts/target.go
parentf4375d045213c416fad2d19773e7700b6b02f685 (diff)
downloadtinygo-a545f17d2ea55807de4b97cf4f52f01d5d4f1815.tar.gz
tinygo-a545f17d2ea55807de4b97cf4f52f01d5d4f1815.zip
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.
Diffstat (limited to 'compileopts/target.go')
-rw-r--r--compileopts/target.go32
1 files changed, 31 insertions, 1 deletions
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
}