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