@@ -191,12 +191,15 @@ func LoadTarget(options *Options) (*TargetSpec, error) {
191191 default :
192192 return nil , fmt .Errorf ("invalid GOARM=%s, must be 5, 6, or 7" , options .GOARM )
193193 }
194+ case "wasm" :
195+ llvmarch = "wasm32"
194196 default :
195197 llvmarch = options .GOARCH
196198 }
197199 llvmvendor := "unknown"
198200 llvmos := options .GOOS
199- if llvmos == "darwin" {
201+ switch llvmos {
202+ case "darwin" :
200203 // Use macosx* instead of darwin, otherwise darwin/arm64 will refer
201204 // to iOS!
202205 llvmos = "macosx10.12.0"
@@ -207,6 +210,8 @@ func LoadTarget(options *Options) (*TargetSpec, error) {
207210 llvmos = "macosx11.0.0"
208211 }
209212 llvmvendor = "apple"
213+ case "wasip1" :
214+ llvmos = "wasi"
210215 }
211216 // Target triples (which actually have four components, but are called
212217 // triples for historical reasons) have the form:
@@ -277,6 +282,15 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
277282 case "arm64" :
278283 spec .CPU = "generic"
279284 spec .Features = "+neon"
285+ case "wasm" :
286+ spec .CPU = "generic"
287+ spec .Features = "+bulk-memory,+nontrapping-fptoint,+sign-ext"
288+ spec .BuildTags = append (spec .BuildTags , "tinygo.wasm" )
289+ spec .CFlags = append (spec .CFlags ,
290+ "-mbulk-memory" ,
291+ "-mnontrapping-fptoint" ,
292+ "-msign-ext" ,
293+ )
280294 }
281295 if goos == "darwin" {
282296 spec .Linker = "ld.lld"
@@ -320,6 +334,22 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
320334 "--no-insert-timestamp" ,
321335 "--no-dynamicbase" ,
322336 )
337+ } else if goos == "wasip1" {
338+ spec .GC = "" // use default GC
339+ spec .Scheduler = "asyncify"
340+ spec .Linker = "wasm-ld"
341+ spec .RTLib = "compiler-rt"
342+ spec .Libc = "wasi-libc"
343+ spec .DefaultStackSize = 1024 * 16 // 16kB
344+ spec .LDFlags = append (spec .LDFlags ,
345+ "--stack-first" ,
346+ "--no-demangle" ,
347+ )
348+ spec .Emulator = "wasmtime --mapdir=/tmp::{tmpDir} {}"
349+ spec .ExtraFiles = append (spec .ExtraFiles ,
350+ "src/runtime/asm_tinygowasm.S" ,
351+ "src/internal/task/task_asyncify_wasm.S" ,
352+ )
323353 } else {
324354 spec .LDFlags = append (spec .LDFlags , "-no-pie" , "-Wl,--gc-sections" ) // WARNING: clang < 5.0 requires -nopie
325355 }
0 commit comments