From 67b45dd14d8794cb7c95ee449cf423a0b44edf0e Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 11 Sep 2024 12:16:53 +0200 Subject: [PATCH] wasm/js: use standard library syscall package This switches -target=wasm (browser wasm) over from our own syscall package to the one used in the Go standard library. While this doesn't remove any code (so we can't simplify anything), the idea is that this improves compatibility with existing code a bit more. So It's a similar reasoning as for https://github.com/tinygo-org/tinygo/pull/4417. --- interp/interpreter.go | 3 ++- loader/goroot.go | 2 +- src/syscall/file_emulated.go | 2 +- src/syscall/file_hosted.go | 2 +- src/syscall/syscall_nonhosted.go | 2 +- src/syscall/tables_nonhosted.go | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/interp/interpreter.go b/interp/interpreter.go index 512d93eb7..fb55e5686 100644 --- a/interp/interpreter.go +++ b/interp/interpreter.go @@ -239,7 +239,8 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent // already be emitted in initAll. continue case strings.HasPrefix(callFn.name, "runtime.print") || callFn.name == "runtime._panic" || callFn.name == "runtime.hashmapGet" || callFn.name == "runtime.hashmapInterfaceHash" || - callFn.name == "os.runtime_args" || callFn.name == "internal/task.start" || callFn.name == "internal/task.Current" || + callFn.name == "os.runtime_args" || callFn.name == "syscall.runtime_envs" || + callFn.name == "internal/task.start" || callFn.name == "internal/task.Current" || callFn.name == "time.startTimer" || callFn.name == "time.stopTimer" || callFn.name == "time.resetTimer": // These functions should be run at runtime. Specifically: // * Print and panic functions are best emitted directly without diff --git a/loader/goroot.go b/loader/goroot.go index c7ac029d3..f42f70926 100644 --- a/loader/goroot.go +++ b/loader/goroot.go @@ -218,7 +218,7 @@ func listGorootMergeLinks(goroot, tinygoroot string, overrides map[string]bool) // with the TinyGo version. This is the case on some targets. func needsSyscallPackage(buildTags []string) bool { for _, tag := range buildTags { - if tag == "baremetal" || tag == "nintendoswitch" || tag == "tinygo.wasm" { + if tag == "baremetal" || tag == "nintendoswitch" || tag == "wasip1" || tag == "wasip2" || tag == "wasm_unknown" { return true } } diff --git a/src/syscall/file_emulated.go b/src/syscall/file_emulated.go index 7b50d4f7e..350cd499c 100644 --- a/src/syscall/file_emulated.go +++ b/src/syscall/file_emulated.go @@ -1,4 +1,4 @@ -//go:build baremetal || (wasm && !wasip1 && !wasip2) || wasm_unknown +//go:build baremetal || wasm_unknown // This file emulates some file-related functions that are only available // under a real operating system. diff --git a/src/syscall/file_hosted.go b/src/syscall/file_hosted.go index a079f400f..136acbf90 100644 --- a/src/syscall/file_hosted.go +++ b/src/syscall/file_hosted.go @@ -1,4 +1,4 @@ -//go:build !(baremetal || (wasm && !wasip1 && !wasip2) || wasm_unknown) +//go:build !(baremetal || wasm_unknown) // This file assumes there is a libc available that runs on a real operating // system. diff --git a/src/syscall/syscall_nonhosted.go b/src/syscall/syscall_nonhosted.go index b56d71af6..0d215af08 100644 --- a/src/syscall/syscall_nonhosted.go +++ b/src/syscall/syscall_nonhosted.go @@ -1,4 +1,4 @@ -//go:build baremetal || js || wasm_unknown +//go:build baremetal || wasm_unknown package syscall diff --git a/src/syscall/tables_nonhosted.go b/src/syscall/tables_nonhosted.go index e66620cbf..a45834827 100644 --- a/src/syscall/tables_nonhosted.go +++ b/src/syscall/tables_nonhosted.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build baremetal || nintendoswitch || js || wasm_unknown +//go:build baremetal || nintendoswitch || wasm_unknown package syscall