1name: Test
2
3on: [push, pull_request]
4
5jobs:
6 test:
7 strategy:
8 matrix:
9 os: [ubuntu-latest, macos-latest, windows-latest]
10 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']
11 name: Test with Go ${{ matrix.go }} on ${{ matrix.os }}
12 runs-on: ${{ matrix.os }}
13 defaults:
14 run:
15 shell: bash
16 steps:
17 - name: Git
18 run: |
19 # See actions/checkout#135
20 git config --global core.autocrlf false
21 git config --global core.eol lf
22
23 - name: Checkout
24 uses: actions/checkout@v4
25
26 - name: Setup Go
27 uses: actions/setup-go@v5
28 with:
29 go-version: ${{ matrix.go }}
30
31 - name: Set up the prerequisites
32 if: runner.os == 'Linux'
33 run: |
34 sudo apt-get update
35 sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu gcc-14-loongarch64-linux-gnu g++-14-loongarch64-linux-gnu qemu-user
36
37 - name: Set up the prerequisites
38 if: runner.os == 'Windows'
39 uses: msys2/setup-msys2@v2
40
41 - name: go vet
42 run: |
43 env CGO_ENABLED=0 go vet -v ./...
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=arm go build -v ./...
57 env GOOS=windows GOARCH=arm64 go build -v ./...
58
59 # Check cross-compiling macOS binaries.
60 env GOOS=darwin GOARCH=amd64 go build -v ./...
61 env GOOS=darwin GOARCH=arm64 go build -v ./...
62
63 # Check cross-compiling Linux binaries.
64 env GOOS=linux GOARCH=amd64 go build -v ./...
65 env GOOS=linux GOARCH=arm64 go build -v ./...
66
67 # Check cross-compiling FreeBSD binaries.
68 # gcflags -std is necessary to make fakecgo the Cgo for
69 # FreeBSD to add the symbols that libc.so depends on.
70 env GOOS=freebsd GOARCH=amd64 go build -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -v ./...
71 env GOOS=freebsd GOARCH=arm64 go build -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -v ./...
72
73 # Check cross-compiling NetBSD binaries.
74 env GOOS=netbsd GOARCH=amd64 go build -v ./...
75 env GOOS=netbsd GOARCH=arm64 go build -v ./...
76
77 - name: go build (Linux loong64)
78 if: ${{ !startsWith(matrix.go, '1.18.') && !startsWith(matrix.go, '1.19.') && !startsWith(matrix.go, '1.20.') && !startsWith(matrix.go, '1.21.') && !startsWith(matrix.go, '1.22.') && !startsWith(matrix.go, '1.23.') && !startsWith(matrix.go, '1.24.') }}
79 run: |
80 # Check cross-compiling Linux binaries for loong64.
81 # Loong64 support internal linking from go1.25.
82 env GOOS=linux GOARCH=loong64 go build -v ./...
83
84 - name: go build (plugin)
85 if: runner.os == 'Linux' || runner.os == 'macOS'
86 run:
87 # Make sure that plugin buildmode works since we save the R15 register (#254)
88 go build -buildmode=plugin ./examples/libc
89
90 - name: go mod vendor
91 if: runner.os != 'Linux'
92 run: |
93 mkdir /tmp/vendoring
94 cd /tmp/vendoring
95 go mod init foo
96 echo 'package main' > main.go
97 echo 'import (' >> main.go
98 echo ' _ "github.com/ebitengine/purego"' >> main.go
99 echo ')' >> main.go
100 echo 'func main() {}' >> main.go
101 go mod edit -replace github.com/ebitengine/purego=$GITHUB_WORKSPACE
102 go mod tidy
103 go mod vendor
104 go build -v .
105
106 - name: go test
107 run: |
108 env CGO_ENABLED=0 go test -shuffle=on -v -count=10 ./...
109 env CGO_ENABLED=1 go test -shuffle=on -v -count=10 ./...
110 # Compile without optimization to check potential stack overflow.
111 # The option '-gcflags=all=-N -l' is often used at Visual Studio Code.
112 # See also https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#launch.
113 env CGO_ENABLED=0 go test "-gcflags=all=-N -l" -v ./...
114 env CGO_ENABLED=1 go test "-gcflags=all=-N -l" -v ./...
115
116 - name: go test (Linux arm64)
117 if: runner.os == 'Linux'
118 run: |
119 go env -w CC=aarch64-linux-gnu-gcc
120 go env -w CXX=aarch64-linux-gnu-g++
121 env GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go test -c -o=purego-test-nocgo .
122 env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64 ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10
123 env GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go test -c -o=purego-test-cgo .
124 env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64 ./purego-test-cgo -test.shuffle=on -test.v -test.count=10
125
126 echo "=> go build (plugin)"
127 # Make sure that plugin buildmode works since we save the R15 register (#254)
128 env GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go build -buildmode=plugin ./examples/libc
129
130 go env -u CC
131 go env -u CXX
132
133 - name: go test (Linux loong64)
134 if: ${{ runner.os == 'Linux' && !startsWith(matrix.go, '1.18.') && !startsWith(matrix.go, '1.19.') && !startsWith(matrix.go, '1.20.') && !startsWith(matrix.go, '1.21.') && !startsWith(matrix.go, '1.22.') && !startsWith(matrix.go, '1.23.') && !startsWith(matrix.go, '1.24.') }}
135 run: |
136 go env -w CC=loongarch64-linux-gnu-gcc-14
137 go env -w CXX=loongarch64-linux-gnu-g++-14
138 env GOOS=linux GOARCH=loong64 CGO_ENABLED=0 go test -c -o=purego-test-nocgo .
139 env QEMU_LD_PREFIX=/usr/loongarch64-linux-gnu qemu-loongarch64 ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10
140 env GOOS=linux GOARCH=loong64 CGO_ENABLED=1 go test -c -o=purego-test-cgo .
141 env QEMU_LD_PREFIX=/usr/loongarch64-linux-gnu qemu-loongarch64 ./purego-test-cgo -test.shuffle=on -test.v -test.count=10
142 go env -u CC
143 go env -u CXX
144
145 - name: go test (Windows 386)
146 if: runner.os == 'Windows'
147 run: |
148 env CGO_ENABLED=0 GOARCH=386 go test -shuffle=on -v -count=10 ./...
149 env CGO_ENABLED=1 GOARCH=386 go test -shuffle=on -v -count=10 ./...
150
151 - name: go test (Linux 386)
152 if: runner.os == 'Linux'
153 run: |
154 sudo apt-get install gcc-multilib
155 sudo apt-get install g++-multilib
156 env CGO_ENABLED=1 GOARCH=386 go test -shuffle=on -v -count=10 ./...
157
158 - name: go test race (no Cgo)
159 if: ${{ runner.os == 'macOS' && !startsWith(matrix.go, '1.18.') && !startsWith(matrix.go, '1.19.') }}
160 run: |
161 # -race usually requires Cgo, but macOS is an exception. See https://go.dev/doc/articles/race_detector#Requirements
162 env CGO_ENABLED=0 go test -race -shuffle=on -v -count=10 ./...
163
164 - name: go test race (Cgo)
165 if: ${{ !startsWith(matrix.go, '1.18.') && !startsWith(matrix.go, '1.19.') }}
166 run: |
167 env CGO_ENABLED=1 go test -race -shuffle=on -v -count=10 ./...
168
169 bsd:
170 strategy:
171 matrix:
172 os: ['FreeBSD'] # TODO: Add 'NetBSD' again (#304)
173 go: ['1.18.10', '1.19.13', '1.20.14', '1.21.13', '1.22.12', '1.23.12', '1.24.6', '1.25.0']
174 exclude:
175 # there are no prebuilt download links for these versions of Go for NetBSD
176 - os: NetBSD
177 go: '1.18.10'
178 - os: NetBSD
179 go: '1.19.13'
180 - os: NetBSD
181 go: '1.20.14'
182 name: Test with Go ${{ matrix.go }} on ${{ matrix.os }}
183 runs-on: ubuntu-22.04
184 defaults:
185 run:
186 shell: bash
187 steps:
188 - uses: actions/checkout@v4
189 - name: Run in FreeBSD
190 if: matrix.os == 'FreeBSD'
191 uses: vmactions/freebsd-vm@v1
192 with:
193 usesh: true
194 prepare: |
195 fetch https://go.dev/dl/go${{matrix.go}}.freebsd-amd64.tar.gz
196 rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.freebsd-amd64.tar.gz
197 chmod +x $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh
198 run: $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh
199 - name: Run in NetBSD
200 if: matrix.os == 'NetBSD'
201 uses: vmactions/netbsd-vm@v1
202 with:
203 usesh: true
204 prepare: |
205 ftp https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz
206 mkdir /usr/local
207 rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.netbsd-amd64.tar.gz
208 chmod +x $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh
209 run: $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh