From 10556e53f26a40c3f2af7892b90b97d45c8fe687 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Thu, 15 Aug 2024 22:31:11 -0400 Subject: [PATCH 01/32] CGO support for Netbsd --- dlfcn_netbsd.go | 33 ++++++++++++++++++++++++++++++++ examples/libc/main.go | 2 ++ examples/libc/main_unix.go | 2 +- internal/cgo/dlfcn_cgo_unix.go | 2 +- internal/cgo/syscall_cgo_unix.go | 2 +- 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 dlfcn_netbsd.go diff --git a/dlfcn_netbsd.go b/dlfcn_netbsd.go new file mode 100644 index 00000000..ddb95e07 --- /dev/null +++ b/dlfcn_netbsd.go @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2024 The Ebitengine Authors + +package purego + +import "github.com/ebitengine/purego/internal/cgo" + +// Source for constants: https://github.com/NetBSD/src/blob/trunk/include/dlfcn.h + +const ( + intSize = 32 << (^uint(0) >> 63) // 32 or 64 + RTLD_DEFAULT = 1< Date: Thu, 15 Aug 2024 22:32:27 -0400 Subject: [PATCH 02/32] missing build tag --- internal/load/load_unix.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/load/load_unix.go b/internal/load/load_unix.go index 024c591e..2fbd3830 100644 --- a/internal/load/load_unix.go +++ b/internal/load/load_unix.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2024 The Ebitengine Authors -//go:build darwin || freebsd || linux +//go:build darwin || freebsd || linux || netbsd package load From 92769ac5933aa5f725ffe8e0f60af112be64118b Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Fri, 16 Aug 2024 07:09:40 -0400 Subject: [PATCH 03/32] syscallArgs --- syscall_cgo_netbsd.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 syscall_cgo_netbsd.go diff --git a/syscall_cgo_netbsd.go b/syscall_cgo_netbsd.go new file mode 100644 index 00000000..db5f8b90 --- /dev/null +++ b/syscall_cgo_netbsd.go @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2024 The Ebitengine Authors + +//go:build cgo + +package purego + +import ( + "github.com/ebitengine/purego/internal/cgo" +) + +var syscall15XABI0 = uintptr(cgo.Syscall15XABI0) + +//go:nosplit +func syscall_syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 uintptr) (r1, r2, err uintptr) { + return cgo.Syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) +} + +func NewCallback(_ interface{}) uintptr { + panic("purego: NewCallback on Linux is only supported on amd64/arm64") +} From 000117cfbc56e9ebd02fe5a087bf2d490ced5dcf Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Fri, 16 Aug 2024 07:26:29 -0400 Subject: [PATCH 04/32] syscall15Args --- syscall.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syscall.go b/syscall.go index c30688dd..0a730311 100644 --- a/syscall.go +++ b/syscall.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors -//go:build darwin || freebsd || linux || windows +//go:build darwin || freebsd || linux || netbsd || windows package purego From b23644e179533b3c179e2b27b209dbf9054faf40 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Fri, 16 Aug 2024 07:44:55 -0400 Subject: [PATCH 05/32] some more --- func.go | 2 +- go_runtime.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/func.go b/func.go index a8a3d620..fa91b8fe 100644 --- a/func.go +++ b/func.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors -//go:build darwin || freebsd || linux || windows +//go:build darwin || freebsd || linux || netbsd || windows package purego diff --git a/go_runtime.go b/go_runtime.go index 13671ff2..b327f786 100644 --- a/go_runtime.go +++ b/go_runtime.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors -//go:build darwin || freebsd || linux || windows +//go:build darwin || freebsd || linux || netbsd || windows package purego From 68d652cde3ad46c301b697e79cc0532254efe6ac Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Fri, 16 Aug 2024 07:45:19 -0400 Subject: [PATCH 06/32] build tag --- cgo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cgo.go b/cgo.go index 7d5abef3..31dc8f19 100644 --- a/cgo.go +++ b/cgo.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors -//go:build cgo && (darwin || freebsd || linux) +//go:build cgo && (darwin || freebsd || netbsd || linux) package purego From cf0745db2deefad23e886fb015145fba2db56a15 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Fri, 16 Aug 2024 07:46:15 -0400 Subject: [PATCH 07/32] test --- dlfcn_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dlfcn_test.go b/dlfcn_test.go index 6ffab82c..9eddeb9a 100644 --- a/dlfcn_test.go +++ b/dlfcn_test.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2023 The Ebitengine Authors -//go:build darwin || freebsd || linux +//go:build darwin || freebsd || linux || netbsd package purego_test From 3c3731e9ae8e0e21f7418648cb0a83144cdd3e79 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Fri, 16 Aug 2024 10:56:18 -0400 Subject: [PATCH 08/32] build tag for netbsd --- internal/cgo/dlfcn_cgo_unix.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cgo/dlfcn_cgo_unix.go b/internal/cgo/dlfcn_cgo_unix.go index f8b180b3..14d09d73 100644 --- a/internal/cgo/dlfcn_cgo_unix.go +++ b/internal/cgo/dlfcn_cgo_unix.go @@ -6,7 +6,7 @@ package cgo /* - #cgo LDFLAGS: -ldl + #cgo !netbsd LDFLAGS: -ldl #include #include From e87d728fadf61d3a7429e615b460c3a9b9212bb6 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Fri, 16 Aug 2024 20:10:13 -0400 Subject: [PATCH 09/32] some more stuff needed fixing --- dlfcn_test.go | 2 +- func_test.go | 4 +++- internal/cgo/dlfcn_cgo_unix.go | 2 +- internal/cgo/syscall_cgo_unix.go | 2 +- syscall_cgo_netbsd.go | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/dlfcn_test.go b/dlfcn_test.go index 9eddeb9a..02e9a243 100644 --- a/dlfcn_test.go +++ b/dlfcn_test.go @@ -54,7 +54,7 @@ func buildSharedLib(compilerEnv, libFile string, sources ...string) error { } var args []string - if runtime.GOOS == "freebsd" { + if runtime.GOOS == "freebsd" || runtime.GOOS == "netbsd" { args = []string{"-shared", "-Wall", "-Werror", "-fPIC", "-o", libFile} } else { args = []string{"-shared", "-Wall", "-Werror", "-o", libFile} diff --git a/func_test.go b/func_test.go index bb8e2159..dc62ef9e 100644 --- a/func_test.go +++ b/func_test.go @@ -23,6 +23,8 @@ func getSystemLibrary() (string, error) { return "libc.so.7", nil case "windows": return "ucrtbase.dll", nil + case "netbsd": + return "libc.so", nil default: return "", fmt.Errorf("GOOS=%s is not supported", runtime.GOOS) } @@ -111,7 +113,7 @@ func TestRegisterFunc_Floats(t *testing.T) { } func TestRegisterLibFunc_Bool(t *testing.T) { - if runtime.GOARCH != "arm64" && runtime.GOARCH != "amd64" { + if runtime.GOARCH != "arm64" && runtime.GOARCH != "amd64" || runtime.GOOS == "netbsd" { t.Skip("Platform doesn't support callbacks") return } diff --git a/internal/cgo/dlfcn_cgo_unix.go b/internal/cgo/dlfcn_cgo_unix.go index 14d09d73..6d0571ab 100644 --- a/internal/cgo/dlfcn_cgo_unix.go +++ b/internal/cgo/dlfcn_cgo_unix.go @@ -6,7 +6,7 @@ package cgo /* - #cgo !netbsd LDFLAGS: -ldl +#cgo !netbsd LDFLAGS: -ldl #include #include diff --git a/internal/cgo/syscall_cgo_unix.go b/internal/cgo/syscall_cgo_unix.go index 072ea11c..6b2c4989 100644 --- a/internal/cgo/syscall_cgo_unix.go +++ b/internal/cgo/syscall_cgo_unix.go @@ -9,7 +9,7 @@ package cgo // because Cgo and assembly files can't be in the same package. /* - #cgo LDFLAGS: -ldl +#cgo !netbsd LDFLAGS: -ldl #include #include diff --git a/syscall_cgo_netbsd.go b/syscall_cgo_netbsd.go index db5f8b90..c964864d 100644 --- a/syscall_cgo_netbsd.go +++ b/syscall_cgo_netbsd.go @@ -17,5 +17,5 @@ func syscall_syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a } func NewCallback(_ interface{}) uintptr { - panic("purego: NewCallback on Linux is only supported on amd64/arm64") + panic("purego: NewCallback is not supported on NetBSD") } From 0b92ec5b3adc77595af142c63e34252f37adb565 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Sat, 17 Aug 2024 07:48:01 -0400 Subject: [PATCH 10/32] ignore tests --- func_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/func_test.go b/func_test.go index dc62ef9e..048eebb3 100644 --- a/func_test.go +++ b/func_test.go @@ -17,14 +17,14 @@ func getSystemLibrary() (string, error) { switch runtime.GOOS { case "darwin": return "/usr/lib/libSystem.B.dylib", nil - case "linux": - return "libc.so.6", nil case "freebsd": return "libc.so.7", nil - case "windows": - return "ucrtbase.dll", nil + case "linux": + return "libc.so.6", nil case "netbsd": return "libc.so", nil + case "windows": + return "ucrtbase.dll", nil default: return "", fmt.Errorf("GOOS=%s is not supported", runtime.GOOS) } @@ -45,7 +45,7 @@ func TestRegisterFunc(t *testing.T) { } func Test_qsort(t *testing.T) { - if runtime.GOARCH != "arm64" && runtime.GOARCH != "amd64" { + if runtime.GOARCH != "arm64" && runtime.GOARCH != "amd64" || runtime.GOOS == "netbsd" { t.Skip("Platform doesn't support Floats") return } @@ -74,7 +74,7 @@ func Test_qsort(t *testing.T) { } func TestRegisterFunc_Floats(t *testing.T) { - if runtime.GOARCH != "arm64" && runtime.GOARCH != "amd64" { + if runtime.GOARCH != "arm64" && runtime.GOARCH != "amd64" || runtime.GOOS == "netbsd" { t.Skip("Platform doesn't support Floats") return } From 68c9fa4b51986d9281229549b251aa97db3b7789 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Sun, 18 Aug 2024 13:32:06 -0400 Subject: [PATCH 11/32] github actions --- .github/workflows/test.yml | 75 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d1adf8fc..621ee32d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -209,6 +209,81 @@ jobs: echo "=> go test CGO_ENABLED=1" env CGO_ENABLED=1 go test -shuffle=on -v -count=10 ./... + if [ -z "$(echo ${{matrix.go}} | grep '^1.1')" ]; then + echo "=> go test race" + go test -race -shuffle=on -v -count=10 ./... + fi + netbsd: + strategy: + matrix: + go: ['1.18.10', '1.19.13', '1.20.14', '1.21.13', '1.22.6', '1.23.0'] + name: Test with Go ${{ matrix.go }} on NetBSD + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - name: Run in netbsd + uses: vmactions/netbsd-vm@v1 + with: + usesh: true + prepare: | + /usr/sbin/pkg_add curl + run: | + echo "Running tests on $(uname -a) at $PWD" + + # verify Go is available + go version + + echo "=> go build" + go build -v ./... + # Compile without optimization to check potential stack overflow. + # The option '-gcflags=all=-N -l' is often used at Visual Studio Code. + # See also https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#launch and the issue hajimehoshi/ebiten#2120. + go build "-gcflags=all=-N -l" -v ./... + + # Check cross-compiling Windows binaries. + env GOOS=windows GOARCH=386 go build -v ./... + env GOOS=windows GOARCH=amd64 go build -v ./... + env GOOS=windows GOARCH=arm go build -v ./... + env GOOS=windows GOARCH=arm64 go build -v ./... + + # Check cross-compiling macOS binaries. + env GOOS=darwin GOARCH=amd64 go build -v ./... + env GOOS=darwin GOARCH=arm64 go build -v ./... + + # Check cross-compiling Linux binaries. + env GOOS=linux GOARCH=amd64 go build -v ./... + env GOOS=linux GOARCH=arm64 go build -v ./... + + # Check cross-compiling FreeBSD binaries. + env GOOS=freebsd GOARCH=amd64 go build -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -v ./... + env GOOS=freebsd GOARCH=arm64 go build -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -v ./... + + echo "=> go build (plugin)" + # Make sure that plugin buildmode works since we save the R15 register (#254) + go build -buildmode=plugin ./examples/libc + + echo "=> go mod vendor" + mkdir /tmp/vendoring + cd /tmp/vendoring + go mod init foo + echo 'package main' > main.go + echo 'import (' >> main.go + echo ' _ "github.com/ebitengine/purego"' >> main.go + echo ')' >> main.go + echo 'func main() {}' >> main.go + go mod edit -replace github.com/ebitengine/purego=$GITHUB_WORKSPACE + go mod tidy + go mod vendor + go build -v . + + # TODO: uncomment once Cgo is not required for FreeBSD + # cd $GITHUB_WORKSPACE + # echo "=> go test CGO_ENABLED=0" + # env CGO_ENABLED=0 go test -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -shuffle=on -v -count=10 ./... + + echo "=> go test CGO_ENABLED=1" + env CGO_ENABLED=1 go test -shuffle=on -v -count=10 ./... + if [ -z "$(echo ${{matrix.go}} | grep '^1.1')" ]; then echo "=> go test race" go test -race -shuffle=on -v -count=10 ./... From 4d8201204783845c3a3d7a11c3e74f82e11aff71 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Sun, 18 Aug 2024 13:55:04 -0400 Subject: [PATCH 12/32] include go --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 621ee32d..324746ef 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -227,6 +227,9 @@ jobs: usesh: true prepare: | /usr/sbin/pkg_add curl + fetch https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz + rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.freebsd-amd64.tar.gz + ln -s /usr/local/go/bin/go /usr/local/bin run: | echo "Running tests on $(uname -a) at $PWD" From f37da236922d364b882d9f6d175b37f4d6a7144b Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 22 Aug 2024 20:35:35 +0900 Subject: [PATCH 13/32] examples/window: replace deprecated functions (#269) --- examples/window/main_windows.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/window/main_windows.go b/examples/window/main_windows.go index 5d81dcd1..6e7d91bd 100644 --- a/examples/window/main_windows.go +++ b/examples/window/main_windows.go @@ -96,7 +96,10 @@ func init() { } func main() { - className := windows.StringToUTF16Ptr("Sample Window Class") + className, err := windows.UTF16PtrFromString("Sample Window Class") + if err != nil { + panic(err) + } inst := GetModuleHandle(className) wc := WNDCLASSEX{ @@ -114,10 +117,14 @@ func main() { Right: 320, Bottom: 240, } + title, err := windows.UTF16PtrFromString("My Title") + if err != nil { + panic(err) + } AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, false) hwnd := CreateWindowEx( 0, className, - windows.StringToUTF16Ptr("My Title"), + title, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, int(wr.Right-wr.Left), int(wr.Bottom-wr.Top), 0, 0, inst, nil, From f8c77421835650ec1f408ad4281da1d76583d6b0 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 22 Aug 2024 22:03:01 +0900 Subject: [PATCH 14/32] all: remove dependencies on golang.org/x/sys (#271) The example still has the dependency on golang.org/x/sys. Updates #270 --- internal/load/load_windows.go | 8 +++++--- syscall_windows.go | 4 +--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/load/load_windows.go b/internal/load/load_windows.go index b8593d7c..713aac48 100644 --- a/internal/load/load_windows.go +++ b/internal/load/load_windows.go @@ -3,13 +3,15 @@ package load -import "golang.org/x/sys/windows" +import ( + "syscall" +) func OpenLibrary(name string) (uintptr, error) { - handle, err := windows.LoadLibrary(name) + handle, err := syscall.LoadLibrary(name) return uintptr(handle), err } func OpenSymbol(lib uintptr, name string) (uintptr, error) { - return windows.GetProcAddress(windows.Handle(lib), name) + return syscall.GetProcAddress(syscall.Handle(lib), name) } diff --git a/syscall_windows.go b/syscall_windows.go index 708948bb..5fbfcabf 100644 --- a/syscall_windows.go +++ b/syscall_windows.go @@ -6,8 +6,6 @@ package purego import ( "reflect" "syscall" - - "golang.org/x/sys/windows" ) var syscall15XABI0 uintptr @@ -44,5 +42,5 @@ func NewCallback(fn interface{}) uintptr { } func loadSymbol(handle uintptr, name string) (uintptr, error) { - return windows.GetProcAddress(windows.Handle(handle), name) + return syscall.GetProcAddress(syscall.Handle(handle), name) } From 128551e7e45ca3932e5ab5af35a89b1b340b4859 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Sun, 25 Aug 2024 09:00:14 -0400 Subject: [PATCH 15/32] Clarify Example section and Dl* windows equivalents (#274) --- README.md | 3 ++- dlerror.go | 2 ++ dlfcn.go | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d783be6b..f1ff9053 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,8 @@ except for float arguments and return values. ## Example -This example only works on macOS and Linux. For a complete example look at [libc](https://github.com/ebitengine/purego/tree/main/examples/libc) which supports Windows and FreeBSD. +The example below only showcases purego use for macOS and Linux. The other platforms require special handling which can +be seen in the complete example at [examples/libc](https://github.com/ebitengine/purego/tree/main/examples/libc) which supports Windows and FreeBSD. ```go package main diff --git a/dlerror.go b/dlerror.go index cf4c0505..95cdfe16 100644 --- a/dlerror.go +++ b/dlerror.go @@ -6,6 +6,8 @@ package purego // Dlerror represents an error value returned from Dlopen, Dlsym, or Dlclose. +// +// This type is not available on Windows as there is no counterpart to it on Windows. type Dlerror struct { s string } diff --git a/dlfcn.go b/dlfcn.go index 8fe31e1c..87ddd6f2 100644 --- a/dlfcn.go +++ b/dlfcn.go @@ -33,6 +33,10 @@ func init() { // A second call to Dlopen with the same path will return the same handle, but the internal // reference count for the handle will be incremented. Therefore, all // Dlopen calls should be balanced with a Dlclose call. +// +// This function is not available on Windows. +// Use [golang.org/x/sys/windows.LoadLibrary], [golang.org/x/sys/windows.NewLazyDLL], or +// [golang.org/x/sys/windows.NewLazySystemDLL] for Windows instead. func Dlopen(path string, mode int) (uintptr, error) { u := fnDlopen(path, mode) if u == 0 { @@ -45,6 +49,9 @@ func Dlopen(path string, mode int) (uintptr, error) { // It returns the address where that symbol is loaded into memory. If the symbol is not found, // in the specified library or any of the libraries that were automatically loaded by Dlopen // when that library was loaded, Dlsym returns zero. +// +// This function is not available on Windows. +// Use [golang.org/x/sys/windows.GetProcAddress] for Windows instead. func Dlsym(handle uintptr, name string) (uintptr, error) { u := fnDlsym(handle, name) if u == 0 { @@ -56,6 +63,9 @@ func Dlsym(handle uintptr, name string) (uintptr, error) { // Dlclose decrements the reference count on the dynamic library handle. // If the reference count drops to zero and no other loaded libraries // use symbols in it, then the dynamic library is unloaded. +// +// This function is not available on Windows. +// Use [golang.org/x/sys/windows.FreeLibrary] for Windows instead. func Dlclose(handle uintptr) error { if fnDlclose(handle) { return Dlerror{fnDlerror()} From 5ad94152a5e01e3c061dfc6348e1a9b51f450aed Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 25 Aug 2024 22:23:03 +0900 Subject: [PATCH 16/32] purego: mention LoadLibraryEx at Dlopen (#275) Updates #273 --- dlfcn.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dlfcn.go b/dlfcn.go index 87ddd6f2..f70a2458 100644 --- a/dlfcn.go +++ b/dlfcn.go @@ -35,8 +35,8 @@ func init() { // Dlopen calls should be balanced with a Dlclose call. // // This function is not available on Windows. -// Use [golang.org/x/sys/windows.LoadLibrary], [golang.org/x/sys/windows.NewLazyDLL], or -// [golang.org/x/sys/windows.NewLazySystemDLL] for Windows instead. +// Use [golang.org/x/sys/windows.LoadLibrary], [golang.org/x/sys/windows.LoadLibraryEx], +// [golang.org/x/sys/windows.NewLazyDLL], or [golang.org/x/sys/windows.NewLazySystemDLL] for Windows instead. func Dlopen(path string, mode int) (uintptr, error) { u := fnDlopen(path, mode) if u == 0 { From c3f4c9c274c333112cd6901e5c2be717f517ef89 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 4 Sep 2024 00:08:04 +0900 Subject: [PATCH 17/32] examples: remove depdencies on golang.org/x/sys/windows (#278) Closes #270 --- examples/libc/main_windows.go | 6 ++++-- examples/window/main_windows.go | 19 +++++++++++-------- go.mod | 2 -- go.sum | 2 -- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/examples/libc/main_windows.go b/examples/libc/main_windows.go index b120ea50..3f3270a4 100644 --- a/examples/libc/main_windows.go +++ b/examples/libc/main_windows.go @@ -3,9 +3,11 @@ package main -import "golang.org/x/sys/windows" +import "syscall" func openLibrary(name string) (uintptr, error) { - handle, err := windows.LoadLibrary(name) + // Use [syscall.LoadLibrary] here to avoid external dependencies (#270). + // For actual use cases, [golang.org/x/sys/windows.NewLazySystemDLL] is recommended. + handle, err := syscall.LoadLibrary(name) return uintptr(handle), err } diff --git a/examples/window/main_windows.go b/examples/window/main_windows.go index 6e7d91bd..1f3d9412 100644 --- a/examples/window/main_windows.go +++ b/examples/window/main_windows.go @@ -5,10 +5,9 @@ package main import ( "runtime" + "syscall" "unsafe" - "golang.org/x/sys/windows" - "github.com/ebitengine/purego" ) @@ -78,10 +77,14 @@ var ( ) func init() { - kernel32 := windows.NewLazySystemDLL("kernel32.dll").Handle() + // Use [syscall.NewLazyDLL] here to avoid external dependencies (#270). + // For actual use cases, [golang.org/x/sys/windows.NewLazySystemDLL] is recommended. + kernel32 := syscall.NewLazyDLL("kernel32.dll").Handle() purego.RegisterLibFunc(&GetModuleHandle, kernel32, "GetModuleHandleW") - user32 := windows.NewLazySystemDLL("user32.dll").Handle() + // Use [syscall.NewLazyDLL] here to avoid external dependencies (#270). + // For actual use cases, [golang.org/x/sys/windows.NewLazySystemDLL] is recommended. + user32 := syscall.NewLazyDLL("user32.dll").Handle() purego.RegisterLibFunc(&RegisterClassEx, user32, "RegisterClassExW") purego.RegisterLibFunc(&CreateWindowEx, user32, "CreateWindowExW") purego.RegisterLibFunc(&AdjustWindowRect, user32, "AdjustWindowRect") @@ -96,7 +99,7 @@ func init() { } func main() { - className, err := windows.UTF16PtrFromString("Sample Window Class") + className, err := syscall.UTF16PtrFromString("Sample Window Class") if err != nil { panic(err) } @@ -104,7 +107,7 @@ func main() { wc := WNDCLASSEX{ Size: uint32(unsafe.Sizeof(WNDCLASSEX{})), - WndProc: windows.NewCallback(wndProc), + WndProc: syscall.NewCallback(wndProc), Instance: inst, ClassName: className, } @@ -117,7 +120,7 @@ func main() { Right: 320, Bottom: 240, } - title, err := windows.UTF16PtrFromString("My Title") + title, err := syscall.UTF16PtrFromString("My Title") if err != nil { panic(err) } @@ -130,7 +133,7 @@ func main() { 0, 0, inst, nil, ) if hwnd == 0 { - panic(windows.GetLastError()) + panic(syscall.GetLastError()) } ShowWindow(hwnd, SW_SHOW) diff --git a/go.mod b/go.mod index bdab0415..ea4133e8 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,3 @@ module github.com/ebitengine/purego go 1.18 - -require golang.org/x/sys v0.23.0 diff --git a/go.sum b/go.sum index d9ec23b2..e69de29b 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +0,0 @@ -golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= -golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= From f091b66cf7d42bad14c086015dce69a904cddbc0 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 24 Sep 2024 00:23:10 +0900 Subject: [PATCH 18/32] all: release v0.9.0-alpha From 570751ca5a78aef97c831007592579df75f7bf53 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Sun, 25 Aug 2024 08:15:14 -0400 Subject: [PATCH 19/32] test --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 324746ef..a42eaccd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -228,7 +228,7 @@ jobs: prepare: | /usr/sbin/pkg_add curl fetch https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz - rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.freebsd-amd64.tar.gz + rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.netbsd-amd64.tar.gz ln -s /usr/local/go/bin/go /usr/local/bin run: | echo "Running tests on $(uname -a) at $PWD" From 4b324b2bb88f043a152af6e4d2ee0f5edfa6f7ca Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Mon, 14 Oct 2024 19:51:48 -0400 Subject: [PATCH 20/32] fix install Go on freebsd --- .github/ISSUE_TEMPLATE/00-bug.yml | 1 + .github/workflows/test.yml | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/00-bug.yml b/.github/ISSUE_TEMPLATE/00-bug.yml index 91350864..c5dc1b80 100644 --- a/.github/ISSUE_TEMPLATE/00-bug.yml +++ b/.github/ISSUE_TEMPLATE/00-bug.yml @@ -17,6 +17,7 @@ body: - label: macOS - label: Linux - label: FreeBSD + - label: NetBSD - label: Android - label: iOS validations: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a42eaccd..de2c982c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -226,8 +226,7 @@ jobs: with: usesh: true prepare: | - /usr/sbin/pkg_add curl - fetch https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz + pkg_add -v https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.netbsd-amd64.tar.gz ln -s /usr/local/go/bin/go /usr/local/bin run: | @@ -279,7 +278,7 @@ jobs: go mod vendor go build -v . - # TODO: uncomment once Cgo is not required for FreeBSD + # TODO: uncomment once Cgo is not required for NetBSD # cd $GITHUB_WORKSPACE # echo "=> go test CGO_ENABLED=0" # env CGO_ENABLED=0 go test -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -shuffle=on -v -count=10 ./... From 7ab881212ecba248af97d2f876ee3b39a513b1b2 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Mon, 14 Oct 2024 19:58:16 -0400 Subject: [PATCH 21/32] fix install Go on freebsd --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index de2c982c..6d071640 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -226,7 +226,7 @@ jobs: with: usesh: true prepare: | - pkg_add -v https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz + /usr/sbin/pkg_add -v https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.netbsd-amd64.tar.gz ln -s /usr/local/go/bin/go /usr/local/bin run: | From 3b55709edf6832854987b985dae2fcb82876add0 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Tue, 15 Oct 2024 07:33:31 -0400 Subject: [PATCH 22/32] fix install Go --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6d071640..674b29f4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -226,7 +226,7 @@ jobs: with: usesh: true prepare: | - /usr/sbin/pkg_add -v https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz + ftp https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.netbsd-amd64.tar.gz ln -s /usr/local/go/bin/go /usr/local/bin run: | From ec53690b29dbce69136800acd7ac95bdb7e948b0 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Tue, 15 Oct 2024 07:53:11 -0400 Subject: [PATCH 23/32] remove Go versions that dl doesn't have downloads for --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 674b29f4..0cc8421f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -216,7 +216,7 @@ jobs: netbsd: strategy: matrix: - go: ['1.18.10', '1.19.13', '1.20.14', '1.21.13', '1.22.6', '1.23.0'] + go: ['1.21.13', '1.22.6', '1.23.0'] name: Test with Go ${{ matrix.go }} on NetBSD runs-on: ubuntu-22.04 steps: From 49cf092fc3d85ee22480871bcbb6486f06681772 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Tue, 15 Oct 2024 09:51:35 -0400 Subject: [PATCH 24/32] mkdir --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0cc8421f..8d179335 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -227,6 +227,7 @@ jobs: usesh: true prepare: | ftp https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz + mkdir /usr/local rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.netbsd-amd64.tar.gz ln -s /usr/local/go/bin/go /usr/local/bin run: | From ae1d516120c7475d0b5e4bc43fa82e52c1c7f09f Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Tue, 15 Oct 2024 10:31:14 -0400 Subject: [PATCH 25/32] specify default shell --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8d179335..0b2d1e7a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -219,6 +219,9 @@ jobs: go: ['1.21.13', '1.22.6', '1.23.0'] name: Test with Go ${{ matrix.go }} on NetBSD runs-on: ubuntu-22.04 + defaults: + run: + shell: sh steps: - uses: actions/checkout@v4 - name: Run in netbsd From 6c57d3f7efb597e50fa31fe0b598986d6917d3e8 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Tue, 15 Oct 2024 10:50:56 -0400 Subject: [PATCH 26/32] disabled syncing to host VM --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0b2d1e7a..06b5c241 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -228,6 +228,7 @@ jobs: uses: vmactions/netbsd-vm@v1 with: usesh: true + sync: no prepare: | ftp https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz mkdir /usr/local From ed60fb80d93d11eeede08b09e9ccc1c7aed1c214 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Tue, 15 Oct 2024 10:56:38 -0400 Subject: [PATCH 27/32] try installing bash --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 06b5c241..3a3799d9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -230,6 +230,7 @@ jobs: usesh: true sync: no prepare: | + pkg_add -v bash ftp https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz mkdir /usr/local rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.netbsd-amd64.tar.gz From c5caadb655fef92334d93ad84d23cb2cc4a7b05d Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Tue, 15 Oct 2024 11:00:48 -0400 Subject: [PATCH 28/32] prefix pkg_add --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3a3799d9..d3832104 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -230,7 +230,7 @@ jobs: usesh: true sync: no prepare: | - pkg_add -v bash + /usr/sbin/pkg_add -v bash ftp https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz mkdir /usr/local rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.netbsd-amd64.tar.gz From d66821117bb1c485ee4d73aba2cd033da50c3849 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Tue, 15 Oct 2024 11:07:46 -0400 Subject: [PATCH 29/32] try bash --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d3832104..c9b8d6d1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -221,7 +221,7 @@ jobs: runs-on: ubuntu-22.04 defaults: run: - shell: sh + shell: bash steps: - uses: actions/checkout@v4 - name: Run in netbsd @@ -237,6 +237,8 @@ jobs: ln -s /usr/local/go/bin/go /usr/local/bin run: | echo "Running tests on $(uname -a) at $PWD" + + export PATH=$PATH:/usr/local/bin # verify Go is available go version From 85a72ad55e063ff3a8308030ecb1ae39107d9bd0 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Tue, 15 Oct 2024 11:15:23 -0400 Subject: [PATCH 30/32] remove some bash references --- .github/workflows/test.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c9b8d6d1..a5d27656 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -219,16 +219,12 @@ jobs: go: ['1.21.13', '1.22.6', '1.23.0'] name: Test with Go ${{ matrix.go }} on NetBSD runs-on: ubuntu-22.04 - defaults: - run: - shell: bash steps: - uses: actions/checkout@v4 - name: Run in netbsd uses: vmactions/netbsd-vm@v1 with: usesh: true - sync: no prepare: | /usr/sbin/pkg_add -v bash ftp https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz @@ -238,7 +234,8 @@ jobs: run: | echo "Running tests on $(uname -a) at $PWD" - export PATH=$PATH:/usr/local/bin + export PATH=$PATH:/usr/local/go/bin/ + echo $PATH # verify Go is available go version From 7773c24ad617e0219dc6af004aa81081f3717a1c Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Tue, 15 Oct 2024 11:20:01 -0400 Subject: [PATCH 31/32] go plugin not supported on netbsd --- .github/workflows/test.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a5d27656..6fca1ac6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -265,10 +265,6 @@ jobs: env GOOS=freebsd GOARCH=amd64 go build -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -v ./... env GOOS=freebsd GOARCH=arm64 go build -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -v ./... - echo "=> go build (plugin)" - # Make sure that plugin buildmode works since we save the R15 register (#254) - go build -buildmode=plugin ./examples/libc - echo "=> go mod vendor" mkdir /tmp/vendoring cd /tmp/vendoring From 9ddd0665385805f4b47bc51b5cab866f220e5a39 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Tue, 15 Oct 2024 11:21:58 -0400 Subject: [PATCH 32/32] remove echo --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6fca1ac6..b7287078 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -235,7 +235,6 @@ jobs: echo "Running tests on $(uname -a) at $PWD" export PATH=$PATH:/usr/local/go/bin/ - echo $PATH # verify Go is available go version