Skip to content

Commit 453a1d3

Browse files
authored
compiler, runtime: enable go:wasmexport for wasip2 (#4499)
* compiler: prefer go:wasmexport over go:export * runtime, targets/wasip2: enable -buildmode=c-shared for wasip2 * runtime: rename import from wasi_run to wasiclirun (PR feedback)
1 parent 9da8b5c commit 453a1d3

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

compiler/symbol.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,13 @@ func (c *compilerContext) parsePragmas(info *functionInfo, f *ssa.Function) {
389389
}
390390
}
391391
}
392+
393+
// If both //go:wasmexport and //go:export or //export are declared,
394+
// only honor go:wasmexport.
395+
if info.wasmExport != "" {
396+
// TODO: log warning?
397+
info.exported = false
398+
}
392399
}
393400

394401
// Check whether this function can be used in //go:wasmimport or

src/runtime/runtime_wasm_wasip2.go renamed to src/runtime/runtime_wasip2.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ import (
66
"unsafe"
77

88
"internal/wasi/cli/v0.2.0/environment"
9+
wasiclirun "internal/wasi/cli/v0.2.0/run"
910
monotonicclock "internal/wasi/clocks/v0.2.0/monotonic-clock"
11+
12+
"internal/cm"
1013
)
1114

1215
type timeUnit int64
1316

14-
//export wasi:cli/run@0.2.0#run
15-
func __wasi_cli_run_run() uint32 {
16-
// These need to be initialized early so that the heap can be initialized.
17-
heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
18-
heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)
19-
run()
20-
return 0
17+
func init() {
18+
wasiclirun.Exports.Run = func() cm.BoolResult {
19+
callMain()
20+
return false
21+
}
2122
}
2223

2324
var args []string
@@ -51,3 +52,6 @@ func sleepTicks(d timeUnit) {
5152
func ticks() timeUnit {
5253
return timeUnit(monotonicclock.Now())
5354
}
55+
56+
func beforeExit() {
57+
}

src/runtime/runtime_wasmentry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build tinygo.wasm && !wasip2 && !js
1+
//go:build tinygo.wasm && !js
22

33
package runtime
44

targets/wasip2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"cpu": "generic",
44
"features": "+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext",
55
"build-tags": ["tinygo.wasm", "wasip2"],
6+
"buildmode": "c-shared",
67
"goos": "linux",
78
"goarch": "arm",
89
"linker": "wasm-ld",

0 commit comments

Comments
 (0)