mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-10 05:53:39 +00:00
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)
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
//go:build wasip2
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"internal/wasi/cli/v0.2.0/environment"
|
||||
wasiclirun "internal/wasi/cli/v0.2.0/run"
|
||||
monotonicclock "internal/wasi/clocks/v0.2.0/monotonic-clock"
|
||||
|
||||
"internal/cm"
|
||||
)
|
||||
|
||||
type timeUnit int64
|
||||
|
||||
func init() {
|
||||
wasiclirun.Exports.Run = func() cm.BoolResult {
|
||||
callMain()
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
var args []string
|
||||
|
||||
//go:linkname os_runtime_args os.runtime_args
|
||||
func os_runtime_args() []string {
|
||||
if args == nil {
|
||||
args = environment.GetArguments().Slice()
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
//export cabi_realloc
|
||||
func cabi_realloc(ptr, oldsize, align, newsize unsafe.Pointer) unsafe.Pointer {
|
||||
return realloc(ptr, uintptr(newsize))
|
||||
}
|
||||
|
||||
func ticksToNanoseconds(ticks timeUnit) int64 {
|
||||
return int64(ticks)
|
||||
}
|
||||
|
||||
func nanosecondsToTicks(ns int64) timeUnit {
|
||||
return timeUnit(ns)
|
||||
}
|
||||
|
||||
func sleepTicks(d timeUnit) {
|
||||
p := monotonicclock.SubscribeDuration(monotonicclock.Duration(d))
|
||||
p.Block()
|
||||
}
|
||||
|
||||
func ticks() timeUnit {
|
||||
return timeUnit(monotonicclock.Now())
|
||||
}
|
||||
|
||||
func beforeExit() {
|
||||
}
|
||||
Reference in New Issue
Block a user