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