mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-14 16:03:41 +00:00
runtime: handle GODEBUG on wasip2 (#5312)
* runtime: handle GODEBUG on wasip2 * Support env on more platforms to get GODEBUG working
This commit is contained in:
+1
-1
@@ -488,7 +488,7 @@ TEST_PACKAGES_HOST := $(TEST_PACKAGES_FAST) $(TEST_PACKAGES_WINDOWS)
|
|||||||
TEST_IOFS := false
|
TEST_IOFS := false
|
||||||
endif
|
endif
|
||||||
|
|
||||||
TEST_SKIP_FLAG := -skip='TestExtraMethods|TestParseAndBytesRoundTrip/P256/Generic|TestParseQueryLimits|TestParseStrictIpv6|TestAsValidation'
|
TEST_SKIP_FLAG := -skip='TestExtraMethods|TestParseAndBytesRoundTrip/P256/Generic|TestAsValidation'
|
||||||
TEST_ADDITIONAL_FLAGS ?=
|
TEST_ADDITIONAL_FLAGS ?=
|
||||||
|
|
||||||
# Test known-working standard library packages.
|
# Test known-working standard library packages.
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
//go:build linux || darwin || windows || wasip1
|
//go:build (linux || darwin || windows || wasip1) && !wasip2 && !baremetal && !wasm_unknown
|
||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
//go:build baremetal || js || wasm_unknown
|
||||||
|
|
||||||
|
package runtime
|
||||||
|
|
||||||
|
//go:linkname syscallSetenv syscall.runtimeSetenv
|
||||||
|
func syscallSetenv(key, value string) {
|
||||||
|
entry := key + "=" + value
|
||||||
|
for i, e := range env {
|
||||||
|
if envKey(e) == key {
|
||||||
|
env[i] = entry
|
||||||
|
if key == "GODEBUG" && godebugUpdate != nil {
|
||||||
|
godebugUpdate(key, value)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
env = append(env, entry)
|
||||||
|
if key == "GODEBUG" && godebugUpdate != nil {
|
||||||
|
godebugUpdate(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:linkname syscallUnsetenv syscall.runtimeUnsetenv
|
||||||
|
func syscallUnsetenv(key string) {
|
||||||
|
for i, e := range env {
|
||||||
|
if envKey(e) == key {
|
||||||
|
env = append(env[:i], env[i+1:]...)
|
||||||
|
if key == "GODEBUG" && godebugUpdate != nil {
|
||||||
|
godebugUpdate(key, "")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func envKey(entry string) string {
|
||||||
|
for i := 0; i < len(entry); i++ {
|
||||||
|
if entry[i] == '=' {
|
||||||
|
return entry[:i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return entry
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
//go:build wasip2
|
||||||
|
|
||||||
|
package runtime
|
||||||
|
|
||||||
|
// Notify the runtime when environment variables change.
|
||||||
|
// On wasip2, the environment is managed in Go (no C setenv), but
|
||||||
|
// internal/godebug still needs to be notified of GODEBUG changes.
|
||||||
|
|
||||||
|
//go:linkname syscallSetenv syscall.runtimeSetenv
|
||||||
|
func syscallSetenv(key, value string) {
|
||||||
|
if key == "GODEBUG" && godebugUpdate != nil {
|
||||||
|
godebugUpdate(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:linkname syscallUnsetenv syscall.runtimeUnsetenv
|
||||||
|
func syscallUnsetenv(key string) {
|
||||||
|
if key == "GODEBUG" && godebugUpdate != nil {
|
||||||
|
godebugUpdate(key, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,18 +28,38 @@ func Getenv(key string) (value string, found bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Setenv(key, val string) (err error) {
|
func Setenv(key, val string) (err error) {
|
||||||
// stub for now
|
if len(key) == 0 {
|
||||||
return ENOSYS
|
return EINVAL
|
||||||
|
}
|
||||||
|
for i := 0; i < len(key); i++ {
|
||||||
|
if key[i] == '=' || key[i] == 0 {
|
||||||
|
return EINVAL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i := 0; i < len(val); i++ {
|
||||||
|
if val[i] == 0 {
|
||||||
|
return EINVAL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
runtimeSetenv(key, val)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Unsetenv(key string) (err error) {
|
func Unsetenv(key string) (err error) {
|
||||||
// stub for now
|
runtimeUnsetenv(key)
|
||||||
return ENOSYS
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Clearenv() (err error) {
|
func Clearenv() (err error) {
|
||||||
// stub for now
|
for _, s := range Environ() {
|
||||||
return ENOSYS
|
for j := 0; j < len(s); j++ {
|
||||||
|
if s[j] == '=' {
|
||||||
|
Unsetenv(s[:j])
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func runtime_envs() []string
|
func runtime_envs() []string
|
||||||
|
|||||||
@@ -43,11 +43,13 @@ func Setenv(key, val string) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
libc_envs[key] = val
|
libc_envs[key] = val
|
||||||
|
runtimeSetenv(key, val)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Unsetenv(key string) (err error) {
|
func Unsetenv(key string) (err error) {
|
||||||
delete(libc_envs, key)
|
delete(libc_envs, key)
|
||||||
|
runtimeUnsetenv(key)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -176,3 +176,7 @@ type RawSockaddrInet4 struct {
|
|||||||
type RawSockaddrInet6 struct {
|
type RawSockaddrInet6 struct {
|
||||||
// stub
|
// stub
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These two functions are provided by the runtime.
|
||||||
|
func runtimeSetenv(key, value string)
|
||||||
|
func runtimeUnsetenv(key string)
|
||||||
|
|||||||
Reference in New Issue
Block a user