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:
Jake Bailey
2026-04-18 14:15:47 -07:00
committed by GitHub
parent ddb848816f
commit bcb191c01e
7 changed files with 98 additions and 8 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build linux || darwin || windows || wasip1
//go:build (linux || darwin || windows || wasip1) && !wasip2 && !baremetal && !wasm_unknown
package runtime
+43
View File
@@ -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
}
+21
View File
@@ -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, "")
}
}