From c82d1ed3faaa75af38bf09f0678170d12a9dd0b6 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Mon, 2 Dec 2024 13:48:52 +0100 Subject: [PATCH 1/2] fix: allow nintendoswitch target to compile Signed-off-by: deadprogram --- src/os/dir_other.go | 2 +- src/os/dir_unix.go | 2 +- src/os/dirent_linux.go | 2 +- src/os/exec_linux.go | 2 +- src/os/exec_other.go | 2 +- src/os/file_anyos.go | 2 +- src/os/file_other.go | 2 +- src/os/file_unix.go | 2 +- src/os/osexec.go | 2 +- src/os/removeall_noat.go | 2 +- src/os/removeall_other.go | 2 +- src/os/stat_linuxlike.go | 2 +- src/os/stat_other.go | 2 +- src/os/stat_unix.go | 2 +- src/os/types_anyos.go | 2 +- src/os/types_unix.go | 2 +- src/runtime/nonhosted.go | 2 +- src/runtime/runtime_nintendoswitch.go | 21 +++++++++++++++++++++ src/runtime/runtime_unix.go | 2 +- src/syscall/proc_emulated.go | 2 +- src/syscall/proc_hosted.go | 2 +- 21 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/os/dir_other.go b/src/os/dir_other.go index 60cd9f8e6a..0f32a12e4d 100644 --- a/src/os/dir_other.go +++ b/src/os/dir_other.go @@ -1,4 +1,4 @@ -//go:build baremetal || js || windows || wasm_unknown +//go:build baremetal || js || windows || wasm_unknown || nintendoswitch // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/src/os/dir_unix.go b/src/os/dir_unix.go index 03624e9cff..7ff92d2318 100644 --- a/src/os/dir_unix.go +++ b/src/os/dir_unix.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 linux && !baremetal && !wasip1 && !wasip2 && !wasm_unknown +//go:build linux && !baremetal && !wasip1 && !wasip2 && !wasm_unknown && !nintendoswitch package os diff --git a/src/os/dirent_linux.go b/src/os/dirent_linux.go index 92e2b3a65b..9c2f611089 100644 --- a/src/os/dirent_linux.go +++ b/src/os/dirent_linux.go @@ -1,4 +1,4 @@ -//go:build !baremetal && !js && !wasip1 && !wasip2 && !wasm_unknown +//go:build !baremetal && !js && !wasip1 && !wasip2 && !wasm_unknown && !nintendoswitch // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/src/os/exec_linux.go b/src/os/exec_linux.go index 58ee79cc81..6914a2c285 100644 --- a/src/os/exec_linux.go +++ b/src/os/exec_linux.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 linux && !baremetal && !tinygo.wasm +//go:build linux && !baremetal && !tinygo.wasm && !nintendoswitch package os diff --git a/src/os/exec_other.go b/src/os/exec_other.go index 5494f08968..b05e2830db 100644 --- a/src/os/exec_other.go +++ b/src/os/exec_other.go @@ -1,4 +1,4 @@ -//go:build (!aix && !android && !freebsd && !linux && !netbsd && !openbsd && !plan9 && !solaris) || baremetal || tinygo.wasm +//go:build (!aix && !android && !freebsd && !linux && !netbsd && !openbsd && !plan9 && !solaris) || baremetal || tinygo.wasm || nintendoswitch package os diff --git a/src/os/file_anyos.go b/src/os/file_anyos.go index da70d72847..593512cb5a 100644 --- a/src/os/file_anyos.go +++ b/src/os/file_anyos.go @@ -1,4 +1,4 @@ -//go:build !baremetal && !js && !wasm_unknown +//go:build !baremetal && !js && !wasm_unknown && !nintendoswitch // Portions copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/src/os/file_other.go b/src/os/file_other.go index 977fcac12d..4e8f859b7a 100644 --- a/src/os/file_other.go +++ b/src/os/file_other.go @@ -1,4 +1,4 @@ -//go:build baremetal || (tinygo.wasm && !wasip1 && !wasip2) +//go:build baremetal || (tinygo.wasm && !wasip1 && !wasip2) || nintendoswitch package os diff --git a/src/os/file_unix.go b/src/os/file_unix.go index 76d35a62cc..d94b80cc3d 100644 --- a/src/os/file_unix.go +++ b/src/os/file_unix.go @@ -1,4 +1,4 @@ -//go:build darwin || (linux && !baremetal && !wasm_unknown) || wasip1 || wasip2 +//go:build darwin || (linux && !baremetal && !wasm_unknown && !nintendoswitch) || wasip1 || wasip2 // target wasi sets GOOS=linux and thus the +linux build tag, // even though it doesn't show up in "tinygo info target -wasi" diff --git a/src/os/osexec.go b/src/os/osexec.go index 65e3ab6952..57139d1b64 100644 --- a/src/os/osexec.go +++ b/src/os/osexec.go @@ -1,4 +1,4 @@ -//go:build linux && !baremetal && !tinygo.wasm +//go:build linux && !baremetal && !tinygo.wasm && !nintendoswitch package os diff --git a/src/os/removeall_noat.go b/src/os/removeall_noat.go index 40fc801379..4b37b3bab6 100644 --- a/src/os/removeall_noat.go +++ b/src/os/removeall_noat.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 && !js && !wasip1 && !wasip2 && !wasm_unknown +//go:build !baremetal && !js && !wasip1 && !wasip2 && !wasm_unknown && !nintendoswitch package os diff --git a/src/os/removeall_other.go b/src/os/removeall_other.go index dc65aaab20..bf3265dee8 100644 --- a/src/os/removeall_other.go +++ b/src/os/removeall_other.go @@ -1,4 +1,4 @@ -//go:build baremetal || js || wasip1 || wasip2 || wasm_unknown +//go:build baremetal || js || wasip1 || wasip2 || wasm_unknown || nintendoswitch // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/src/os/stat_linuxlike.go b/src/os/stat_linuxlike.go index 7c512ec049..c9cfd396ff 100644 --- a/src/os/stat_linuxlike.go +++ b/src/os/stat_linuxlike.go @@ -1,4 +1,4 @@ -//go:build (linux && !baremetal && !wasm_unknown) || wasip1 || wasip2 +//go:build (linux && !baremetal && !wasm_unknown && !nintendoswitch) || wasip1 || wasip2 // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/src/os/stat_other.go b/src/os/stat_other.go index 234c59db21..59331bc510 100644 --- a/src/os/stat_other.go +++ b/src/os/stat_other.go @@ -1,4 +1,4 @@ -//go:build baremetal || (tinygo.wasm && !wasip1 && !wasip2) +//go:build baremetal || (tinygo.wasm && !wasip1 && !wasip2) || nintendoswitch // Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/src/os/stat_unix.go b/src/os/stat_unix.go index af5110cf8e..9882608d65 100644 --- a/src/os/stat_unix.go +++ b/src/os/stat_unix.go @@ -1,4 +1,4 @@ -//go:build darwin || (linux && !baremetal && !wasm_unknown) || wasip1 || wasip2 +//go:build darwin || (linux && !baremetal && !wasm_unknown && !nintendoswitch) || wasip1 || wasip2 // Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/src/os/types_anyos.go b/src/os/types_anyos.go index 939c00967c..9109fa6177 100644 --- a/src/os/types_anyos.go +++ b/src/os/types_anyos.go @@ -1,4 +1,4 @@ -//go:build !baremetal && !js && !wasm_unknown +//go:build !baremetal && !js && !wasm_unknown && !nintendoswitch // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/src/os/types_unix.go b/src/os/types_unix.go index 0629b3bbcf..54c5c4969b 100644 --- a/src/os/types_unix.go +++ b/src/os/types_unix.go @@ -1,4 +1,4 @@ -//go:build darwin || (linux && !baremetal && !wasm_unknown) || wasip1 || wasip2 +//go:build darwin || (linux && !baremetal && !wasm_unknown && !nintendoswitch) || wasip1 || wasip2 // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/src/runtime/nonhosted.go b/src/runtime/nonhosted.go index ca5ab4c3c8..9f01a7621a 100644 --- a/src/runtime/nonhosted.go +++ b/src/runtime/nonhosted.go @@ -1,4 +1,4 @@ -//go:build baremetal || js || wasm_unknown +//go:build baremetal || js || wasm_unknown || nintendoswitch package runtime diff --git a/src/runtime/runtime_nintendoswitch.go b/src/runtime/runtime_nintendoswitch.go index d2567b1ccf..2d3677bf05 100644 --- a/src/runtime/runtime_nintendoswitch.go +++ b/src/runtime/runtime_nintendoswitch.go @@ -84,6 +84,19 @@ func ticks() timeUnit { return timeUnit(ticksToNanoseconds(timeUnit(getArmSystemTick()))) } +// timeOffset is how long the monotonic clock started after the Unix epoch. It +// should be a positive integer under normal operation or zero when it has not +// been set. +var timeOffset int64 + +//go:linkname now time.now +func now() (sec int64, nsec int32, mono int64) { + mono = nanotime() + sec = (mono + timeOffset) / (1000 * 1000 * 1000) + nsec = int32((mono + timeOffset) - sec*(1000*1000*1000)) + return +} + var stdoutBuffer = make([]byte, 120) var position = 0 @@ -98,6 +111,14 @@ func putchar(c byte) { position++ } +func buffered() int { + return 0 +} + +func getchar() byte { + return 0 +} + func abort() { for { exit(1) diff --git a/src/runtime/runtime_unix.go b/src/runtime/runtime_unix.go index e6f81778de..08e3e74269 100644 --- a/src/runtime/runtime_unix.go +++ b/src/runtime/runtime_unix.go @@ -1,4 +1,4 @@ -//go:build (darwin || (linux && !baremetal && !wasip1 && !wasm_unknown && !wasip2)) && !nintendoswitch +//go:build darwin || (linux && !baremetal && !wasip1 && !wasm_unknown && !wasip2 && !nintendoswitch) package runtime diff --git a/src/syscall/proc_emulated.go b/src/syscall/proc_emulated.go index d8e7ff7a92..bcf8eabe94 100644 --- a/src/syscall/proc_emulated.go +++ b/src/syscall/proc_emulated.go @@ -1,4 +1,4 @@ -//go:build baremetal || tinygo.wasm +//go:build baremetal || tinygo.wasm || nintendoswitch // This file emulates some process-related functions that are only available // under a real operating system. diff --git a/src/syscall/proc_hosted.go b/src/syscall/proc_hosted.go index 05c509e6ff..8b8f1fafd5 100644 --- a/src/syscall/proc_hosted.go +++ b/src/syscall/proc_hosted.go @@ -1,4 +1,4 @@ -//go:build !baremetal && !tinygo.wasm +//go:build !baremetal && !tinygo.wasm && !nintendoswitch // This file assumes there is a libc available that runs on a real operating // system. From df6d0dae6fed4d66b386382b44738d9cbab20613 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Wed, 4 Dec 2024 13:59:36 +0100 Subject: [PATCH 2/2] make: modify smoketest for nintendoswitch target to build something that includes the 'os' package Signed-off-by: deadprogram --- GNUmakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GNUmakefile b/GNUmakefile index 5f82599e79..8daad25fb9 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -867,7 +867,7 @@ endif @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=pca10040 -serial=rtt examples/echo @$(MD5SUM) test.hex - $(TINYGO) build -o test.nro -target=nintendoswitch examples/serial + $(TINYGO) build -o test.nro -target=nintendoswitch examples/echo2 @$(MD5SUM) test.nro $(TINYGO) build -size short -o test.hex -target=pca10040 -opt=0 ./testdata/stdlib.go @$(MD5SUM) test.hex