| 1 |
name: Test |
| 2 |
|
| 3 |
on: [push, pull_request] |
| 4 |
|
| 5 |
jobs: |
| 6 |
test: |
| 7 |
strategy: |
| 8 |
matrix: |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
os: [ubuntu-latest, ubuntu-24.04-arm, macos-15, windows-latest] |
| 13 |
go: ['1.18.x', '1.19.x', '1.20.x', '1.21.x', '1.22.x', '1.23.x', '1.24.x', '1.25.x', '1.26.x'] |
| 14 |
name: Test with Go ${{ matrix.go }} on ${{ matrix.os }} |
| 15 |
runs-on: ${{ matrix.os }} |
| 16 |
defaults: |
| 17 |
run: |
| 18 |
shell: bash |
| 19 |
steps: |
| 20 |
- name: Git |
| 21 |
run: | |
| 22 |
# See actions/checkout#135 |
| 23 |
git config --global core.autocrlf false |
| 24 |
git config --global core.eol lf |
| 25 |
|
| 26 |
- name: Checkout |
| 27 |
uses: actions/checkout@v5 |
| 28 |
|
| 29 |
- name: Setup Go |
| 30 |
uses: actions/setup-go@v6 |
| 31 |
with: |
| 32 |
go-version: ${{ matrix.go }} |
| 33 |
|
| 34 |
- name: Set up the prerequisites |
| 35 |
if: runner.os == 'Windows' |
| 36 |
uses: msys2/setup-msys2@v2 |
| 37 |
|
| 38 |
- name: go vet |
| 39 |
run: | |
| 40 |
env CGO_ENABLED=0 go vet -v ./... |
| 41 |
|
| 42 |
- name: gofmt |
| 43 |
run: test -z "$(gofmt -s -l .)" |
| 44 |
|
| 45 |
- name: go build |
| 46 |
run: | |
| 47 |
go build -v ./... |
| 48 |
# Compile without optimization to check potential stack overflow. |
| 49 |
# The option '-gcflags=all=-N -l' is often used at Visual Studio Code. |
| 50 |
# See also https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#launch and the issue hajimehoshi/ebiten#2120. |
| 51 |
go build "-gcflags=all=-N -l" -v ./... |
| 52 |
|
| 53 |
# Check cross-compiling Windows binaries. |
| 54 |
env GOOS=windows GOARCH=386 go build -v ./... |
| 55 |
env GOOS=windows GOARCH=amd64 go build -v ./... |
| 56 |
env GOOS=windows GOARCH=arm64 go build -v ./... |
| 57 |
|
| 58 |
# Check cross-compiling macOS binaries. |
| 59 |
env GOOS=darwin GOARCH=amd64 go build -v ./... |
| 60 |
env GOOS=darwin GOARCH=arm64 go build -v ./... |
| 61 |
|
| 62 |
# Check cross-compiling Linux binaries. |
| 63 |
env GOOS=linux GOARCH=amd64 go build -v ./... |
| 64 |
env GOOS=linux GOARCH=arm64 go build -v ./... |
| 65 |
|
| 66 |
# Check cross-compiling FreeBSD binaries. |
| 67 |
# gcflags -std is necessary to make fakecgo the Cgo for |
| 68 |
# FreeBSD to add the symbols that libc.so depends on. |
| 69 |
env GOOS=freebsd GOARCH=amd64 go build -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -v ./... |
| 70 |
env GOOS=freebsd GOARCH=arm64 go build -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -v ./... |
| 71 |
|
| 72 |
# Check cross-compiling NetBSD binaries. |
| 73 |
env GOOS=netbsd GOARCH=amd64 go build -v ./... |
| 74 |
env GOOS=netbsd GOARCH=arm64 go build -v ./... |
| 75 |
|
| 76 |
- name: go build (Linux minor architectures) |
| 77 |
|
| 78 |
|
| 79 |
if: startsWith(matrix.go, '1.26.') |
| 80 |
run: | |
| 81 |
# Check cross-compiling Linux binaries for minor architectures. |
| 82 |
env GOOS=linux GOARCH=loong64 go build -v ./... |
| 83 |
env GOOS=linux GOARCH=ppc64le go build -v ./... |
| 84 |
env GOOS=linux GOARCH=riscv64 go build -v ./... |
| 85 |
|
| 86 |
- name: go build (plugin) |
| 87 |
if: runner.os == 'Linux' || runner.os == 'macOS' |
| 88 |
run: |
| 89 |
|
| 90 |
go build -buildmode=plugin ./examples/libc |
| 91 |
|
| 92 |
- name: go mod vendor |
| 93 |
if: runner.os != 'Linux' |
| 94 |
run: | |
| 95 |
mkdir /tmp/vendoring |
| 96 |
cd /tmp/vendoring |
| 97 |
go mod init foo |
| 98 |
echo 'package main' > main.go |
| 99 |
echo 'import (' >> main.go |
| 100 |
echo ' _ "github.com/ebitengine/purego"' >> main.go |
| 101 |
echo ')' >> main.go |
| 102 |
echo 'func main() {}' >> main.go |
| 103 |
go mod edit -replace github.com/ebitengine/purego=$GITHUB_WORKSPACE |
| 104 |
go mod tidy |
| 105 |
go mod vendor |
| 106 |
go build -v . |
| 107 |
|
| 108 |
- name: go test |
| 109 |
run: | |
| 110 |
env CGO_ENABLED=0 go test -shuffle=on -v -count=10 ./... |
| 111 |
env CGO_ENABLED=1 go test -shuffle=on -v -count=10 ./... |
| 112 |
# Compile without optimization to check potential stack overflow. |
| 113 |
# The option '-gcflags=all=-N -l' is often used at Visual Studio Code. |
| 114 |
# See also https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#launch. |
| 115 |
env CGO_ENABLED=0 go test "-gcflags=all=-N -l" -v ./... |
| 116 |
env CGO_ENABLED=1 go test "-gcflags=all=-N -l" -v ./... |
| 117 |
|
| 118 |
- name: go test (Windows 386) |
| 119 |
if: runner.os == 'Windows' |
| 120 |
run: | |
| 121 |
env CGO_ENABLED=0 GOARCH=386 go test -shuffle=on -v -count=10 ./... |
| 122 |
env CGO_ENABLED=1 GOARCH=386 go test -shuffle=on -v -count=10 ./... |
| 123 |
|
| 124 |
- name: go test (Linux 386) |
| 125 |
if: ${{ runner.os == 'Linux' && runner.arch != 'ARM64' }} |
| 126 |
run: | |
| 127 |
sudo apt-get update |
| 128 |
sudo apt-get install gcc-multilib |
| 129 |
sudo apt-get install g++-multilib |
| 130 |
env CGO_ENABLED=0 GOARCH=386 go test -shuffle=on -v -count=10 ./... |
| 131 |
env CGO_ENABLED=1 GOARCH=386 go test -shuffle=on -v -count=10 ./... |
| 132 |
|
| 133 |
- name: go test (Linux arm) |
| 134 |
if: ${{ runner.os == 'Linux' && runner.arch == 'ARM64' }} |
| 135 |
run: | |
| 136 |
sudo apt-get update |
| 137 |
sudo apt-get install -y qemu-user gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libc6-armhf-cross |
| 138 |
# Create symlink for the dynamic linker that QEMU expects |
| 139 |
sudo ln -sf /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3 /lib/ld-linux.so.3 |
| 140 |
go env -w CC=arm-linux-gnueabihf-gcc |
| 141 |
go env -w CXX=arm-linux-gnueabihf-g++ |
| 142 |
env GOOS=linux GOARCH=arm CGO_ENABLED=0 go test -c -o=purego-test-nocgo . |
| 143 |
env QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf qemu-arm ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10 |
| 144 |
env GOOS=linux GOARCH=arm CGO_ENABLED=1 go test -c -o=purego-test-cgo . |
| 145 |
env QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf qemu-arm ./purego-test-cgo -test.shuffle=on -test.v -test.count=10 |
| 146 |
go env -u CC |
| 147 |
go env -u CXX |
| 148 |
|
| 149 |
- name: go test race (no Cgo) |
| 150 |
if: ${{ runner.os == 'macOS' && !startsWith(matrix.go, '1.18.') && !startsWith(matrix.go, '1.19.') }} |
| 151 |
run: | |
| 152 |
# -race usually requires Cgo, but macOS is an exception. See https://go.dev/doc/articles/race_detector#Requirements |
| 153 |
env CGO_ENABLED=0 go test -race -shuffle=on -v -count=10 ./... |
| 154 |
|
| 155 |
- name: go test race (Cgo) |
| 156 |
if: ${{ !startsWith(matrix.go, '1.18.') && !startsWith(matrix.go, '1.19.') }} |
| 157 |
run: | |
| 158 |
env CGO_ENABLED=1 go test -race -shuffle=on -v -count=10 ./... |
| 159 |
|
| 160 |
minor-arches: |
| 161 |
strategy: |
| 162 |
matrix: |
| 163 |
|
| 164 |
go: ['1.26.x'] |
| 165 |
name: Test with Go ${{ matrix.go }} on Linux minor architectures |
| 166 |
runs-on: ubuntu-latest |
| 167 |
defaults: |
| 168 |
run: |
| 169 |
shell: bash |
| 170 |
steps: |
| 171 |
- name: Checkout |
| 172 |
uses: actions/checkout@v5 |
| 173 |
|
| 174 |
- name: Setup Go |
| 175 |
uses: actions/setup-go@v6 |
| 176 |
with: |
| 177 |
go-version: ${{ matrix.go }} |
| 178 |
|
| 179 |
- name: Set up the prerequisites |
| 180 |
run: | |
| 181 |
sudo apt-get update |
| 182 |
sudo apt-get install -y \ |
| 183 |
gcc-14-loongarch64-linux-gnu g++-14-loongarch64-linux-gnu \ |
| 184 |
gcc-powerpc64le-linux-gnu g++-powerpc64le-linux-gnu \ |
| 185 |
gcc-riscv64-linux-gnu g++-riscv64-linux-gnu \ |
| 186 |
gcc-s390x-linux-gnu g++-s390x-linux-gnu \ |
| 187 |
qemu-user |
| 188 |
|
| 189 |
- name: go test (Linux loong64) |
| 190 |
run: | |
| 191 |
go env -w CC=loongarch64-linux-gnu-gcc-14 |
| 192 |
go env -w CXX=loongarch64-linux-gnu-g++-14 |
| 193 |
env GOOS=linux GOARCH=loong64 CGO_ENABLED=0 go test -c -o=purego-test-nocgo . |
| 194 |
env QEMU_LD_PREFIX=/usr/loongarch64-linux-gnu qemu-loongarch64 ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10 |
| 195 |
env GOOS=linux GOARCH=loong64 CGO_ENABLED=1 go test -c -o=purego-test-cgo . |
| 196 |
env QEMU_LD_PREFIX=/usr/loongarch64-linux-gnu qemu-loongarch64 ./purego-test-cgo -test.shuffle=on -test.v -test.count=10 |
| 197 |
go env -u CC |
| 198 |
go env -u CXX |
| 199 |
|
| 200 |
- name: go test (Linux ppc64le) |
| 201 |
run: | |
| 202 |
go env -w CC=powerpc64le-linux-gnu-gcc |
| 203 |
go env -w CXX=powerpc64le-linux-gnu-g++ |
| 204 |
env GOOS=linux GOARCH=ppc64le CGO_ENABLED=0 go test -c -o=purego-test-nocgo . |
| 205 |
env QEMU_LD_PREFIX=/usr/powerpc64le-linux-gnu qemu-ppc64le ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10 |
| 206 |
env GOOS=linux GOARCH=ppc64le CGO_ENABLED=1 go test -c -o=purego-test-cgo . |
| 207 |
env QEMU_LD_PREFIX=/usr/powerpc64le-linux-gnu qemu-ppc64le ./purego-test-cgo -test.shuffle=on -test.v -test.count=10 |
| 208 |
go env -u CC |
| 209 |
go env -u CXX |
| 210 |
|
| 211 |
- name: go test (Linux riscv64) |
| 212 |
run: | |
| 213 |
go env -w CC=riscv64-linux-gnu-gcc |
| 214 |
go env -w CXX=riscv64-linux-gnu-g++ |
| 215 |
# Create symlink for the dynamic linker that QEMU expects |
| 216 |
sudo ln -sf /usr/riscv64-linux-gnu/lib/ld-linux-riscv64-lp64d.so.1 /lib/ld.so.1 |
| 217 |
env GOOS=linux GOARCH=riscv64 CGO_ENABLED=0 go test -c -o=purego-test-nocgo . |
| 218 |
env QEMU_LD_PREFIX=/usr/riscv64-linux-gnu qemu-riscv64 ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10 |
| 219 |
env GOOS=linux GOARCH=riscv64 CGO_ENABLED=1 go test -c -o=purego-test-cgo . |
| 220 |
env QEMU_LD_PREFIX=/usr/riscv64-linux-gnu qemu-riscv64 ./purego-test-cgo -test.shuffle=on -test.v -test.count=10 |
| 221 |
go env -u CC |
| 222 |
go env -u CXX |
| 223 |
|
| 224 |
- name: go test (Linux s390x) |
| 225 |
run: | |
| 226 |
go env -w CC=s390x-linux-gnu-gcc |
| 227 |
go env -w CXX=s390x-linux-gnu-g++ |
| 228 |
env GOOS=linux GOARCH=s390x CGO_ENABLED=1 go test -c -o=purego-test-cgo . |
| 229 |
env QEMU_LD_PREFIX=/usr/s390x-linux-gnu qemu-s390x ./purego-test-cgo -test.shuffle=on -test.v -test.count=10 |
| 230 |
go env -u CC |
| 231 |
go env -u CXX |
| 232 |
|
| 233 |
bsd: |
| 234 |
strategy: |
| 235 |
matrix: |
| 236 |
os: ['FreeBSD'] |
| 237 |
go: ['1.18.10', '1.19.13', '1.20.14', '1.21.13', '1.22.12', '1.23.12', '1.24.13', '1.25.7', '1.26.0'] |
| 238 |
exclude: |
| 239 |
|
| 240 |
- os: NetBSD |
| 241 |
go: '1.18.10' |
| 242 |
- os: NetBSD |
| 243 |
go: '1.19.13' |
| 244 |
- os: NetBSD |
| 245 |
go: '1.20.14' |
| 246 |
name: Test with Go ${{ matrix.go }} on ${{ matrix.os }} |
| 247 |
runs-on: ubuntu-22.04 |
| 248 |
defaults: |
| 249 |
run: |
| 250 |
shell: bash |
| 251 |
steps: |
| 252 |
- uses: actions/checkout@v5 |
| 253 |
- name: Run in FreeBSD |
| 254 |
if: matrix.os == 'FreeBSD' |
| 255 |
uses: vmactions/freebsd-vm@v1 |
| 256 |
with: |
| 257 |
usesh: true |
| 258 |
prepare: | |
| 259 |
fetch https://go.dev/dl/go${{matrix.go}}.freebsd-amd64.tar.gz |
| 260 |
rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.freebsd-amd64.tar.gz |
| 261 |
chmod +x $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh |
| 262 |
run: $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh |
| 263 |
- name: Run in NetBSD |
| 264 |
if: matrix.os == 'NetBSD' |
| 265 |
uses: vmactions/netbsd-vm@v1 |
| 266 |
with: |
| 267 |
usesh: true |
| 268 |
prepare: | |
| 269 |
ftp https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz |
| 270 |
mkdir /usr/local |
| 271 |
rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.netbsd-amd64.tar.gz |
| 272 |
chmod +x $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh |
| 273 |
run: $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh |