@@ -191,12 +191,15 @@ func LoadTarget(options *Options) (*TargetSpec, error) {
191
191
default :
192
192
return nil , fmt .Errorf ("invalid GOARM=%s, must be 5, 6, or 7" , options .GOARM )
193
193
}
194
+ case "wasm" :
195
+ llvmarch = "wasm32"
194
196
default :
195
197
llvmarch = options .GOARCH
196
198
}
197
199
llvmvendor := "unknown"
198
200
llvmos := options .GOOS
199
- if llvmos == "darwin" {
201
+ switch llvmos {
202
+ case "darwin" :
200
203
// Use macosx* instead of darwin, otherwise darwin/arm64 will refer
201
204
// to iOS!
202
205
llvmos = "macosx10.12.0"
@@ -207,6 +210,8 @@ func LoadTarget(options *Options) (*TargetSpec, error) {
207
210
llvmos = "macosx11.0.0"
208
211
}
209
212
llvmvendor = "apple"
213
+ case "wasip1" :
214
+ llvmos = "wasi"
210
215
}
211
216
// Target triples (which actually have four components, but are called
212
217
// triples for historical reasons) have the form:
@@ -277,6 +282,15 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
277
282
case "arm64" :
278
283
spec .CPU = "generic"
279
284
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
+ )
280
294
}
281
295
if goos == "darwin" {
282
296
spec .Linker = "ld.lld"
@@ -320,6 +334,22 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
320
334
"--no-insert-timestamp" ,
321
335
"--no-dynamicbase" ,
322
336
)
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
+ )
323
353
} else {
324
354
spec .LDFlags = append (spec .LDFlags , "-no-pie" , "-Wl,--gc-sections" ) // WARNING: clang < 5.0 requires -nopie
325
355
}
0 commit comments