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 d1adf8fc..b7287078 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -209,6 +209,83 @@ 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.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 -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 + ln -s /usr/local/go/bin/go /usr/local/bin + run: | + echo "Running tests on $(uname -a) at $PWD" + + export PATH=$PATH:/usr/local/go/bin/ + + # 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 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 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 ./... + + 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 ./... 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 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< #include diff --git a/internal/cgo/syscall_cgo_unix.go b/internal/cgo/syscall_cgo_unix.go index 37ff24d5..6b2c4989 100644 --- a/internal/cgo/syscall_cgo_unix.go +++ b/internal/cgo/syscall_cgo_unix.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2022 The Ebitengine Authors -//go:build freebsd || (linux && !(arm64 || amd64)) +//go:build freebsd || (linux && !(arm64 || amd64)) || netbsd package cgo @@ -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/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 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 diff --git a/syscall_cgo_netbsd.go b/syscall_cgo_netbsd.go new file mode 100644 index 00000000..c964864d --- /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 is not supported on NetBSD") +}