test.yml RawHistoryFolder
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']
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 qemu-user
36
37 - name: go vet
38 if: runner.os != 'Windows' && runner.os != 'macOS'
39 run: |
40 go vet -v ./...
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=arm go build -v ./...
54 env GOOS=windows GOARCH=arm64 go build -v ./...
55
56 # Check cross-compiling macOS binaries.
57 env GOOS=darwin GOARCH=amd64 go build -v ./...
58 env GOOS=darwin GOARCH=arm64 go build -v ./...
59
60 # Check cross-compiling Linux binaries.
61 env GOOS=linux GOARCH=amd64 go build -v ./...
62 env GOOS=linux GOARCH=arm64 go build -v ./...
63
64 # Check cross-compiling FreeBSD binaries.
65 # gcflags -std is necessary to make fakecgo the Cgo for
66 # FreeBSD to add the symbols that libc.so depends on.
67 env GOOS=freebsd GOARCH=amd64 go build -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -v ./...
68 env GOOS=freebsd GOARCH=arm64 go build -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -v ./...
69
70 - name: go build (plugin)
71 if: runner.os == 'Linux' || runner.os == 'macOS'
72 run:
73 # Make sure that plugin buildmode works since we save the R15 register (#254)
74 go build -buildmode=plugin ./examples/libc
75
76 - name: go mod vendor
77 if: runner.os != 'Linux'
78 run: |
79 mkdir /tmp/vendoring
80 cd /tmp/vendoring
81 go mod init foo
82 echo 'package main' > main.go
83 echo 'import (' >> main.go
84 echo ' _ "github.com/ebitengine/purego"' >> main.go
85 echo ')' >> main.go
86 echo 'func main() {}' >> main.go
87 go mod edit -replace github.com/ebitengine/purego=$GITHUB_WORKSPACE
88 go mod tidy
89 go mod vendor
90 go build -v .
91
92 - name: go test
93 run: |
94 env CGO_ENABLED=0 go test -shuffle=on -v -count=10 ./...
95 env CGO_ENABLED=1 go test -shuffle=on -v -count=10 ./...
96 # Compile without optimization to check potential stack overflow.
97 # The option '-gcflags=all=-N -l' is often used at Visual Studio Code.
98 # See also https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#launch.
99 env CGO_ENABLED=0 go test "-gcflags=all=-N -l" -v ./...
100 env CGO_ENABLED=1 go test "-gcflags=all=-N -l" -v ./...
101
102 - name: go test (Linux arm64)
103 if: runner.os == 'Linux'
104 run: |
105 go env -w CC=aarch64-linux-gnu-gcc
106 go env -w CXX=aarch64-linux-gnu-g++
107 env GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go test -c -o=purego-test-nocgo .
108 env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64 ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10
109 env GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go test -c -o=purego-test-cgo .
110 env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64 ./purego-test-cgo -test.shuffle=on -test.v -test.count=10
111
112 echo "=> go build (plugin)"
113 # Make sure that plugin buildmode works since we save the R15 register (#254)
114 env GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go build -buildmode=plugin ./examples/libc
115
116 go env -u CC
117 go env -u CXX
118
119 - name: go test (Windows 386)
120 if: runner.os == 'Windows'
121 run: |
122 env CGO_ENABLED=0 GOARCH=386 go test -shuffle=on -v -count=10 ./...
123 env CGO_ENABLED=1 GOARCH=386 go test -shuffle=on -v -count=10 ./...
124
125 - name: go test (Linux 386)
126 if: runner.os == 'Linux'
127 run: |
128 sudo apt-get install gcc-multilib
129 sudo apt-get install g++-multilib
130 env CGO_ENABLED=1 GOARCH=386 go test -shuffle=on -v -count=10 ./...
131
132 - name: go test race
133 if: ${{ !startsWith(matrix.go, '1.18.') && !startsWith(matrix.go, '1.19.') }}
134 run: |
135 go test -race -shuffle=on -v -count=10 ./...
136
137 freebsd:
138 strategy:
139 matrix:
140 go: ['1.18.10', '1.19.13', '1.20.14', '1.21.13', '1.22.12', '1.23.9', '1.24.3']
141 name: Test with Go ${{ matrix.go }} on FreeBSD
142 runs-on: ubuntu-22.04
143 defaults:
144 run:
145 shell: bash
146 steps:
147 - uses: actions/checkout@v4
148 - name: Run in freebsd
149 uses: vmactions/freebsd-vm@v1
150 with:
151 usesh: true
152 prepare: |
153 fetch https://go.dev/dl/go${{matrix.go}}.freebsd-amd64.tar.gz
154 rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.freebsd-amd64.tar.gz
155 ln -s /usr/local/go/bin/go /usr/local/bin
156 run: |
157 # FreeBSD tests run within QEMU on Ubuntu.
158 # vmactions/freebsd-vm only supports a single "step" where it
159 # brings down the VM at the end of the step, so all
160 # the commands to run need to be put into this single block.
161
162 echo "Running tests on $(uname -a) at $PWD"
163
164 # verify Go is available
165 go version
166
167 echo "=> go build"
168 go build -v ./...
169 # Compile without optimization to check potential stack overflow.
170 # The option '-gcflags=all=-N -l' is often used at Visual Studio Code.
171 # See also https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#launch and the issue hajimehoshi/ebiten#2120.
172 go build "-gcflags=all=-N -l" -v ./...
173
174 # Check cross-compiling Windows binaries.
175 env GOOS=windows GOARCH=386 go build -v ./...
176 env GOOS=windows GOARCH=amd64 go build -v ./...
177 env GOOS=windows GOARCH=arm go build -v ./...
178 env GOOS=windows GOARCH=arm64 go build -v ./...
179
180 # Check cross-compiling macOS binaries.
181 env GOOS=darwin GOARCH=amd64 go build -v ./...
182 env GOOS=darwin GOARCH=arm64 go build -v ./...
183
184 # Check cross-compiling Linux binaries.
185 env GOOS=linux GOARCH=amd64 go build -v ./...
186 env GOOS=linux GOARCH=arm64 go build -v ./...
187
188 # Check cross-compiling FreeBSD binaries.
189 env GOOS=freebsd GOARCH=amd64 go build -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -v ./...
190 env GOOS=freebsd GOARCH=arm64 go build -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -v ./...
191
192 echo "=> go build (plugin)"
193 # Make sure that plugin buildmode works since we save the R15 register (#254)
194 go build -buildmode=plugin ./examples/libc
195
196 echo "=> go mod vendor"
197 mkdir /tmp/vendoring
198 cd /tmp/vendoring
199 go mod init foo
200 echo 'package main' > main.go
201 echo 'import (' >> main.go
202 echo ' _ "github.com/ebitengine/purego"' >> main.go
203 echo ')' >> main.go
204 echo 'func main() {}' >> main.go
205 go mod edit -replace github.com/ebitengine/purego=$GITHUB_WORKSPACE
206 go mod tidy
207 go mod vendor
208 go build -v .
209
210 cd $GITHUB_WORKSPACE
211 echo "=> go test CGO_ENABLED=0"
212 env CGO_ENABLED=0 go test -gcflags="github.com/ebitengine/purego/internal/fakecgo=-std" -shuffle=on -v -count=10 ./...
213
214 echo "=> go test CGO_ENABLED=1"
215 env CGO_ENABLED=1 go test -shuffle=on -v -count=10 ./...
216
217 if [ -z "$(echo ${{matrix.go}} | grep '^1.1')" ]; then
218 echo "=> go test race"
219 go test -race -shuffle=on -v -count=10 ./...
220 fi