Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for NetBSD #268

Merged
merged 61 commits into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
10556e5
CGO support for Netbsd
TotallyGamerJet Aug 16, 2024
5068751
missing build tag
TotallyGamerJet Aug 16, 2024
92769ac
syscallArgs
TotallyGamerJet Aug 16, 2024
000117c
syscall15Args
TotallyGamerJet Aug 16, 2024
b23644e
some more
TotallyGamerJet Aug 16, 2024
68d652c
build tag
TotallyGamerJet Aug 16, 2024
cf0745d
test
TotallyGamerJet Aug 16, 2024
3c3731e
build tag for netbsd
TotallyGamerJet Aug 16, 2024
e87d728
some more stuff needed fixing
TotallyGamerJet Aug 17, 2024
0b92ec5
ignore tests
TotallyGamerJet Aug 17, 2024
68c9fa4
github actions
TotallyGamerJet Aug 18, 2024
4d82012
include go
TotallyGamerJet Aug 18, 2024
f37da23
examples/window: replace deprecated functions (#269)
hajimehoshi Aug 22, 2024
f8c7742
all: remove dependencies on golang.org/x/sys (#271)
hajimehoshi Aug 22, 2024
128551e
Clarify Example section and Dl* windows equivalents (#274)
TotallyGamerJet Aug 25, 2024
5ad9415
purego: mention LoadLibraryEx at Dlopen (#275)
hajimehoshi Aug 25, 2024
c3f4c9c
examples: remove depdencies on golang.org/x/sys/windows (#278)
hajimehoshi Sep 3, 2024
f091b66
all: release v0.9.0-alpha
hajimehoshi Sep 23, 2024
570751c
test
TotallyGamerJet Aug 25, 2024
4b324b2
fix install Go on freebsd
TotallyGamerJet Oct 14, 2024
7ab8812
fix install Go on freebsd
TotallyGamerJet Oct 14, 2024
3b55709
fix install Go
TotallyGamerJet Oct 15, 2024
ec53690
remove Go versions that dl doesn't have downloads for
TotallyGamerJet Oct 15, 2024
49cf092
mkdir
TotallyGamerJet Oct 15, 2024
ae1d516
specify default shell
TotallyGamerJet Oct 15, 2024
6c57d3f
disabled syncing to host VM
TotallyGamerJet Oct 15, 2024
ed60fb8
try installing bash
TotallyGamerJet Oct 15, 2024
c5caadb
prefix pkg_add
TotallyGamerJet Oct 15, 2024
d668211
try bash
TotallyGamerJet Oct 15, 2024
85a72ad
remove some bash references
TotallyGamerJet Oct 15, 2024
7773c24
go plugin not supported on netbsd
TotallyGamerJet Oct 15, 2024
9ddd066
remove echo
TotallyGamerJet Oct 15, 2024
ea999fd
Merge branch 'refs/heads/main' into issue-249_netbsd
TotallyGamerJet Oct 15, 2024
2a940f5
No Cgo on NetBSD?
TotallyGamerJet Mar 6, 2025
83c4528
Merge branch 'main' into issue-249_netbsd
TotallyGamerJet Mar 6, 2025
daa834c
add netbsd to build tag in examples/libc
TotallyGamerJet Mar 6, 2025
2a19c6e
update pipeline
TotallyGamerJet Mar 6, 2025
e7e52fe
enable tests
TotallyGamerJet Mar 6, 2025
19cebb4
make code more in line with runtime/cgo
TotallyGamerJet Mar 8, 2025
7d59f39
use -fPIC on all platforms
TotallyGamerJet Mar 8, 2025
bc9050f
build tags and copyright years
TotallyGamerJet Mar 8, 2025
3e44d74
try merging freebsd and netbsd
TotallyGamerJet Mar 8, 2025
d1cfb86
another attempt at merging workflow
TotallyGamerJet Mar 8, 2025
d649054
fix spacing
TotallyGamerJet Mar 8, 2025
7b5d581
try separate test script
TotallyGamerJet Mar 8, 2025
25f17fc
fix misspelling
TotallyGamerJet Mar 8, 2025
2a6247c
ls to debug
TotallyGamerJet Mar 8, 2025
3b59667
ensure it is executable and then bash directly
TotallyGamerJet Mar 8, 2025
75cbcfc
newline and license
TotallyGamerJet Mar 8, 2025
b0aba43
use "go version" for retrieving version
TotallyGamerJet Mar 8, 2025
e7e4a0e
fix misspelling
TotallyGamerJet Mar 8, 2025
5fda596
don't run on version that aren't downloadable
TotallyGamerJet Mar 8, 2025
9616e78
ls everything
TotallyGamerJet Mar 8, 2025
f6b5e0a
ls for freebsd
TotallyGamerJet Mar 8, 2025
d7c63f1
$GITHUB_WORKSPACE/
TotallyGamerJet Mar 8, 2025
a5d18b0
remove bash
TotallyGamerJet Mar 8, 2025
d0a90a9
ls inside "run:"
TotallyGamerJet Mar 8, 2025
f2e19f3
updates for freebsd
TotallyGamerJet Mar 8, 2025
961e360
try bash again
TotallyGamerJet Mar 8, 2025
19e4a72
yes install bash
TotallyGamerJet Mar 8, 2025
74c6bf6
sh
TotallyGamerJet Mar 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/00-bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ body:
- label: macOS
- label: Linux
- label: FreeBSD
- label: NetBSD
- label: Android
- label: iOS
validations:
Expand Down
81 changes: 81 additions & 0 deletions .github/scripts/bsd_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/sh

# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2025 The Ebitengine Authors

Copy link
Member

@hajimehoshi hajimehoshi Mar 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add set -e to abort this script whenever any command fails.

EDIT: Hmm this might work only with Bash.

# FreeBSD & NetBSD tests run within QEMU on Ubuntu.
# vmactions/freebsd-vm only supports a single "step" where it
# brings down the VM at the end of the step, so all
# the commands to run need to be put into this single block.

echo "Running tests on $(uname -a) at $PWD"

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 ./...

# Check cross-compiling NetBSD binaries.
env GOOS=netbsd GOARCH=amd64 go build -v ./...
env GOOS=netbsd GOARCH=arm64 go build -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 .

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 ./...

echo "=> go test CGO_ENABLED=0 w/o optimization"
env CGO_ENABLED=0 go test "-gcflags=all=-N -l" -v ./...

echo "=> go test CGO_ENABLED=1 w/o optimization"
env CGO_ENABLED=1 go test "-gcflags=all=-N -l" -v ./...

if [ -z "$(go version | grep '^1.1')" ]; then
echo "=> go test race"
go test -race -shuffle=on -v -count=10 ./...
fi
99 changes: 25 additions & 74 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ jobs:
# gcflags -std is necessary to make fakecgo the Cgo for
# FreeBSD to add the symbols that libc.so depends on.
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 ./...
env GOOS=freebsd GOARCH=arm64 go build -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -v ./...

# Check cross-compiling NetBSD binaries.
env GOOS=netbsd GOARCH=amd64 go build -v ./...
env GOOS=netbsd GOARCH=arm64 go build -v ./...

- name: go build (plugin)
if: runner.os == 'Linux' || runner.os == 'macOS'
Expand Down Expand Up @@ -134,93 +138,40 @@ jobs:
run: |
go test -race -shuffle=on -v -count=10 ./...

freebsd:
bsd:
strategy:
matrix:
os: ['FreeBSD', 'NetBSD']
go: ['1.18.10', '1.19.13', '1.20.14', '1.21.13', '1.22.12', '1.23.6', '1.24.0']
name: Test with Go ${{ matrix.go }} on FreeBSD
name: Test with Go ${{ matrix.go }} on ${{ matrix.os }}
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- name: Run in freebsd
if: matrix.os == 'FreeBSD'
uses: vmactions/freebsd-vm@v1
with:
usesh: true
prepare: |
fetch https://go.dev/dl/go${{matrix.go}}.freebsd-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: |
# FreeBSD tests run within QEMU on Ubuntu.
# vmactions/freebsd-vm only supports a single "step" where it
# brings down the VM at the end of the step, so all
# the commands to run need to be put into this single block.

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 .

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 ./...

echo "=> go test CGO_ENABLED=0 w/o optimization"
env CGO_ENABLED=0 go test "-gcflags=all=-N -l" -v ./...

echo "=> go test CGO_ENABLED=1 w/o optimization"
env CGO_ENABLED=1 go test "-gcflags=all=-N -l" -v ./...

if [ -z "$(echo ${{matrix.go}} | grep '^1.1')" ]; then
echo "=> go test race"
go test -race -shuffle=on -v -count=10 ./...
fi
chmod +x $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh
run: $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh
- name: Run in netbsd
# there are no prebuilt download links for these versions of Go for NetBSD
if: matrix.os == 'NetBSD' && !startsWith(matrix.go, '1.18.') && !startsWith(matrix.go, '1.19.') && !startsWith(matrix.go, '1.20.')
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
chmod +x $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh
run: $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ This is a list of the copied files:
* `internal/fakecgo/iscgo.go` from package `runtime/cgo`
* `internal/fakecgo/setenv.go` from package `runtime/cgo`
* `internal/fakecgo/freebsd.go` from package `runtime/cgo`
* `internal/fakecgo/netbsd.go` from package `runtime/cgo`

The files `abi_*.h` and `internal/fakecgo/abi_*.h` are the same because Bazel does not support cross-package use of
`#include` so we need each one once per package. (cf. [issue](https://github.com/bazelbuild/rules_go/issues/3636))
2 changes: 1 addition & 1 deletion cgo.go
Original file line number Diff line number Diff line change
@@ -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 || linux || netbsd)

package purego

Expand Down
2 changes: 1 addition & 1 deletion dlerror.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion dlfcn.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors

//go:build (darwin || freebsd || linux) && !android && !faketime
//go:build (darwin || freebsd || linux || netbsd) && !android && !faketime

package purego

Expand Down
15 changes: 15 additions & 0 deletions dlfcn_netbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2025 The Ebitengine Authors

package purego

// 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<<intSize - 2 // Pseudo-handle for dlsym so search for any loaded symbol
RTLD_LAZY = 0x00000001 // Relocations are performed at an implementation-dependent time.
RTLD_NOW = 0x00000002 // Relocations are performed when the object is loaded.
RTLD_LOCAL = 0x00000000 // All symbols are not made available for relocation processing by other modules.
RTLD_GLOBAL = 0x00000100 // All symbols are available for relocation processing of other modules.
)
9 changes: 9 additions & 0 deletions dlfcn_nocgo_netbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2025 The Ebitengine Authors

package purego

//go:cgo_import_dynamic purego_dlopen dlopen "libc.so"
//go:cgo_import_dynamic purego_dlsym dlsym "libc.so"
//go:cgo_import_dynamic purego_dlerror dlerror "libc.so"
//go:cgo_import_dynamic purego_dlclose dlclose "libc.so"
2 changes: 1 addition & 1 deletion dlfcn_stubs.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors

//go:build darwin || !cgo && (freebsd || linux) && !faketime
//go:build darwin || !cgo && (freebsd || linux || netbsd) && !faketime

#include "textflag.h"

Expand Down
9 changes: 2 additions & 7 deletions dlfcn_test.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -53,12 +53,7 @@ func buildSharedLib(compilerEnv, libFile string, sources ...string) error {
return errors.New("compiler not found")
}

var args []string
if runtime.GOOS == "freebsd" {
args = []string{"-shared", "-Wall", "-Werror", "-fPIC", "-o", libFile}
} else {
args = []string{"-shared", "-Wall", "-Werror", "-o", libFile}
}
args := []string{"-shared", "-Wall", "-Werror", "-fPIC", "-o", libFile}
if runtime.GOARCH == "386" {
args = append(args, "-m32")
}
Expand Down
4 changes: 3 additions & 1 deletion examples/libc/main.go
Original file line number Diff line number Diff line change
@@ -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 main

Expand All @@ -20,6 +20,8 @@ func getSystemLibrary() string {
return "libc.so.6"
case "freebsd":
return "libc.so.7"
case "netbsd":
return "libc.so"
case "windows":
return "ucrtbase.dll"
default:
Expand Down
2 changes: 1 addition & 1 deletion examples/libc/main_unix.go
Original file line number Diff line number Diff line change
@@ -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 main

Expand Down
2 changes: 1 addition & 1 deletion func.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 4 additions & 2 deletions func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ 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 "linux":
return "libc.so.6", nil
case "netbsd":
return "libc.so", nil
case "windows":
return "ucrtbase.dll", nil
default:
Expand Down
2 changes: 1 addition & 1 deletion go_runtime.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions internal/cgo/dlfcn_cgo_unix.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2024 The Ebitengine Authors

//go:build freebsd || linux
//go:build freebsd || linux || netbsd

package cgo

/*
#cgo LDFLAGS: -ldl
#cgo !netbsd LDFLAGS: -ldl

#include <dlfcn.h>
#include <stdlib.h>
Expand Down
Loading