]> Cypherpunks repositories - gostls13.git/commitdiff
time: add wasip1 support
authorJohan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Sat, 8 Apr 2023 01:26:50 +0000 (18:26 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 11 Apr 2023 20:56:10 +0000 (20:56 +0000)
Fixes #58141

Co-authored-by: Richard Musiol <neelance@gmail.com>
Co-authored-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Julien Fabre <ju.pryz@gmail.com>
Co-authored-by: Evan Phoenix <evan@phx.io>
Change-Id: I51dabbf17b8f5540c964f90223d18457f6f9fbef
Reviewed-on: https://go-review.googlesource.com/c/go/+/483236
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/time/sys_unix.go
src/time/zoneinfo_wasip1.go [new file with mode: 0644]

index 0f06aa6ccd7dcd3c91b930b41e26a37461996a35..63634ace7cc1c58c9b67e2796d896cd7a8892160 100644 (file)
@@ -2,18 +2,26 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build unix || (js && wasm)
+//go:build unix || (js && wasm) || wasip1
 
 package time
 
 import (
        "errors"
+       "runtime"
        "syscall"
 )
 
 // for testing: whatever interrupts a sleep
 func interrupt() {
-       syscall.Kill(syscall.Getpid(), syscall.SIGCHLD)
+       // There is no mechanism in wasi to interrupt the call to poll_oneoff
+       // used to implement runtime.usleep so this function does nothing, which
+       // somewhat defeats the purpose of TestSleep but we are still better off
+       // validating that time elapses when the process calls time.Sleep than
+       // skipping the test altogether.
+       if runtime.GOOS != "wasip1" {
+               syscall.Kill(syscall.Getpid(), syscall.SIGCHLD)
+       }
 }
 
 func open(name string) (uintptr, error) {
diff --git a/src/time/zoneinfo_wasip1.go b/src/time/zoneinfo_wasip1.go
new file mode 100644 (file)
index 0000000..b6c8bbc
--- /dev/null
@@ -0,0 +1,12 @@
+// Copyright 2023 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package time
+
+// in wasip1 zoneinfo is managed by the runtime.
+var platformZoneSources = []string{}
+
+func initLocal() {
+       localLoc.name = "Local"
+}