@@ -14,41 +14,75 @@ jobs:
14
14
strategy :
15
15
matrix :
16
16
include :
17
- - os : ubuntu-latest
17
+ - target : x86_64-linux-gnu
18
+ os : ubuntu-latest
18
19
artifact : " linux-x64"
19
- ocaml-compiler : " ocaml-variants.5.2.0+options,ocaml-option-flambda"
20
20
triplet : " x64-linux"
21
- - os : ubuntu-24.04-arm
21
+ - target : aarch64-linux-gnu
22
+ os : ubuntu-latest
22
23
artifact : " linux-arm64"
23
- ocaml-compiler : " ocaml-variants.5.2.0+options,ocaml-option-flambda"
24
24
triplet : " arm64-linux"
25
- - os : windows-latest
26
- artifact : " windows-x64"
27
- ocaml-compiler : " ocaml-variants.5.2.0+options,ocaml-option-flambda"
25
+ toolchain : " gcc-aarch64-linux-gnu g++-aarch64-linux-gnu"
26
+ - target : x86_64-windows-gnu
27
+ os : windows-latest
28
+ artifact : " windows-x64.exe"
28
29
triplet : " x64-mingw-static"
29
- - os : macos-latest
30
+ - target : aarch64-windows-gnu
31
+ os : ubuntu-latest
32
+ artifact : " windows-arm64.exe"
33
+ triplet : " arm64-mingw-static"
34
+ toolchain : " llvm-mingw"
35
+ - target : aarch64-macos
36
+ os : macos-latest
30
37
artifact : " macos-arm64"
31
- ocaml-compiler : " ocaml-variants.5.2.0+options,ocaml-option-flambda"
32
38
triplet : " arm64-osx"
33
- - os : macos-13
39
+ - target : x86_64-macos
40
+ os : macos-13
34
41
artifact : " macos-x64"
35
- ocaml-compiler : " ocaml-variants.5.2.0+options,ocaml-option-flambda"
36
42
triplet : " x64-osx"
37
43
defaults :
38
44
run :
39
45
shell : bash
46
+
40
47
steps :
41
-
48
+ - name : Checkout code
49
+ uses : actions/checkout@v4
42
50
43
51
- if : runner.os == 'Windows'
44
52
run : |
45
53
rm -rf $(which pkg-config)
46
54
choco install pkgconfiglite
47
55
48
- - run : gcc --version
56
+ - name : Install cross-compilation toolchain
57
+ if : runner.os == 'Linux' && matrix.toolchain
58
+ run : |
59
+ if [[ "${{ matrix.target }}" == "aarch64-windows-gnu" ]]; then
60
+ wget https://github.com/mstorsjo/llvm-mingw/releases/download/20240417/llvm-mingw-20240417-ucrt-ubuntu-20.04-x86_64.tar.xz
61
+ tar -xf llvm-mingw-20240417-ucrt-ubuntu-20.04-x86_64.tar.xz
62
+ echo "${GITHUB_WORKSPACE}/llvm-mingw-20240417-ucrt-ubuntu-20.04-x86_64/bin" >> $GITHUB_PATH
63
+
64
+ sudo apt-get update
65
+ sudo apt-get install -y pkg-config
66
+
67
+ echo "CC=aarch64-w64-mingw32-clang" >> $GITHUB_ENV
68
+ echo "CXX=aarch64-w64-mingw32-clang++" >> $GITHUB_ENV
69
+ echo "AR=aarch64-w64-mingw32-llvm-ar" >> $GITHUB_ENV
70
+ echo "LD=aarch64-w64-mingw32-ld" >> $GITHUB_ENV
71
+ echo "STRIP=aarch64-w64-mingw32-llvm-strip" >> $GITHUB_ENV
72
+ echo "PKG_CONFIG=pkg-config" >> $GITHUB_ENV
73
+ else
74
+ # Regular GCC cross-compilation for Linux ARM64
75
+ sudo apt-get update
76
+ sudo apt-get install -y ${{ matrix.toolchain }}
77
+ fi
78
+
79
+ - name : Setup Zig
80
+ uses : goto-bus-stop/setup-zig@v2
81
+ with :
82
+ version : 0.15.1
49
83
50
84
- uses : lukka/get-cmake@latest
51
- - name : Setup anew (or from cache) vcpkg (and does not build any package)
85
+ - name : Setup vcpkg
52
86
uses : lukka/run-vcpkg@v11
53
87
env :
54
88
VCPKG_DEFAULT_TRIPLET : ${{ matrix.triplet }}
@@ -64,72 +98,139 @@ jobs:
64
98
ls "${GITHUB_WORKSPACE}/vcpkg_installed/${VCPKG_DEFAULT_TRIPLET}/lib/pkgconfig"
65
99
echo "PKG_CONFIG_PATH=${GITHUB_WORKSPACE}/vcpkg_installed/${VCPKG_DEFAULT_TRIPLET}/lib/pkgconfig" >> $GITHUB_ENV
66
100
67
- - name : Set pkg-config path on Unix
101
+ - name : Set pkg-config path on Windows
68
102
shell : bash
69
- if : runner.os == 'Windows'
103
+ if : runner.os == 'Windows'
70
104
run : |
71
- echo "PKG_CONFIG_PATH=${GITHUB_WORKSPACE}\vcpkg_installed\\${VCPKG_DEFAULT_TRIPLET}\lib\pkgconfig" >> $GITHUB_ENV
105
+ echo "PKG_CONFIG_PATH=${GITHUB_WORKSPACE}\\ vcpkg_installed\\${VCPKG_DEFAULT_TRIPLET}\\ lib\ \pkgconfig" >> $GITHUB_ENV
72
106
73
- - shell : bash
107
+ - name : Build for ${{ matrix.target }}
108
+ env :
109
+ VCPKG_ROOT : ${{ github.workspace }}/vcpkg_installed
74
110
run : |
75
- echo "LIBPNG_CFLAGS=$(pkg-config --cflags libspng_static)" >> $GITHUB_ENV
76
- echo "LIBPNG_LIBS=$(pkg-config --libs libspng_static)" >> $GITHUB_ENV
77
- echo "LIBTIFF_LIBS=$(pkg-config --libs libtiff-4)" >> $GITHUB_ENV
78
- echo "LIBTIFF_CFLAGS=$(pkg-config --cflags libtiff-4)" >> $GITHUB_ENV
79
- echo "LIBJPEG_CFLAGS=$(pkg-config --cflags libturbojpeg)" >> $GITHUB_ENV
80
- echo "LIBJPEG_LIBS=$(pkg-config --libs libturbojpeg)" >> $GITHUB_ENV
81
-
82
- - uses : ocaml/setup-ocaml@v3
83
- with :
84
- ocaml-compiler : ${{ matrix.ocaml-compiler }}
85
- opam-disable-sandboxing : true
86
- dune-cache : false
111
+ if [[ ! -d "$VCPKG_ROOT/${{ matrix.triplet }}" ]]; then
112
+ echo "ERROR: vcpkg triplet directory not found: $VCPKG_ROOT/${{ matrix.triplet }}"
113
+ exit 1
114
+ fi
115
+ zig build -Dtarget=${{ matrix.target }} -Doptimize=ReleaseFast --verbose
87
116
88
- - run : opam exec -- opam install . --deps-only --with-test
89
- - run : opam exec -- dune build --verbose
117
+ - name : Validate binary architecture
118
+ shell : bash
119
+ run : |
120
+ # Find the binary
121
+ if [[ -f "zig-out/bin/odiff.exe" ]]; then
122
+ BINARY_PATH="zig-out/bin/odiff.exe"
123
+ elif [[ -f "zig-out/bin/odiff" ]]; then
124
+ BINARY_PATH="zig-out/bin/odiff"
125
+ else
126
+ echo "ERROR: No binary found"
127
+ ls -la zig-out/bin/
128
+ exit 1
129
+ fi
90
130
91
- - run : opam exec -- dune exec ODiffBin -- --version
92
- - run : opam exec -- dune runtest
131
+ BINARY_INFO=$(file "$BINARY_PATH")
132
+ echo "$BINARY_INFO"
133
+
134
+ case "${{ matrix.target }}" in
135
+ *"windows"*)
136
+ if [[ ! "$BINARY_INFO" =~ "PE32+".*"x86-64" ]] && [[ ! "$BINARY_INFO" =~ "PE32+".*"Aarch64" ]] && [[ ! "$BINARY_INFO" =~ "COFF" ]]; then
137
+ echo "ERROR: Expected Windows PE/COFF executable, got: $BINARY_INFO"
138
+ exit 1
139
+ fi
140
+ ;;
141
+ *"linux"*)
142
+ if [[ ! "$BINARY_INFO" =~ "ELF".*"x86-64" ]] && [[ ! "$BINARY_INFO" =~ "ELF".*"aarch64" ]]; then
143
+ echo "ERROR: Expected Linux ELF executable, got: $BINARY_INFO"
144
+ exit 1
145
+ fi
146
+ ;;
147
+ *"macos"*)
148
+ if [[ ! "$BINARY_INFO" =~ "Mach-O".*"x86_64" ]] && [[ ! "$BINARY_INFO" =~ "Mach-O".*"arm64" ]]; then
149
+ echo "ERROR: Expected macOS Mach-O executable, got: $BINARY_INFO"
150
+ exit 1
151
+ fi
152
+ ;;
153
+ esac
93
154
94
- - if : failure()
95
- uses : actions/upload-artifact@v4
96
- with :
97
- name : test_images
98
- path : _build/default/test/test_images
155
+ - name : Test binary execution (if possible)
156
+ shell : bash
157
+ run : |
158
+ case "${{ matrix.target }}" in
159
+ "x86_64-linux-gnu")
160
+ if [[ "${{ runner.os }}" == "Linux" ]]; then
161
+ ./zig-out/bin/odiff --help
162
+ fi
163
+ ;;
164
+ "x86_64-windows-gnu")
165
+ if [[ "${{ runner.os }}" == "Windows" ]]; then
166
+ ./zig-out/bin/odiff.exe --help
167
+ fi
168
+ ;;
169
+ "x86_64-macos")
170
+ if [[ "${{ runner.os }}" == "macOS" ]]; then
171
+ ./zig-out/bin/odiff --help
172
+ fi
173
+ ;;
174
+ "aarch64-macos")
175
+ if [[ "${{ runner.os }}" == "macOS" ]] && [[ "$(uname -m)" == "arm64" ]]; then
176
+ ./zig-out/bin/odiff --help
177
+ fi
178
+ ;;
179
+ esac
99
180
100
- - name : Set up Node.js
101
- uses : actions/setup-node@v4
102
- with :
103
- node-version : ' 20'
104
- cache : ' npm'
105
- cache-dependency-path : ' package-lock.json'
106
-
107
- - name : Install node deps
108
- run : npm ci
109
- - name : e2e test
110
- run : npm test
111
-
112
- - name : Build release binary
113
- # this is needed because now ocaml's internal cygwin will be used on windows
114
- # which breaks normal line endings
115
- env :
116
- SHELLOPTS : igncr
181
+ - name : Copy binary to artifact name
117
182
run : |
118
- opam exec -- dune clean && \
119
- opam exec -- dune build --release && \
120
- cp "_build/default/bin/ODiffBin.exe" "odiff-${{ matrix.artifact }}.exe"
183
+ if [[ -f "zig-out/bin/odiff.exe" ]]; then
184
+ cp "zig-out/bin/odiff.exe" "odiff-${{ matrix.artifact }}"
185
+ else
186
+ cp "zig-out/bin/odiff" "odiff-${{ matrix.artifact }}"
187
+ fi
121
188
122
- - if : always()
189
+ - name : Upload artifact
123
190
uses : actions/upload-artifact@v4
124
191
with :
125
192
if-no-files-found : error
126
- name : odiff-${{ matrix.artifact }}.exe
127
- path : odiff-${{ matrix.artifact }}.exe
193
+ name : odiff-${{ matrix.artifact }}
194
+ path : odiff-${{ matrix.artifact }}
128
195
retention-days : 14
129
196
197
+ test :
198
+ runs-on : ubuntu-latest
199
+ name : Run Tests
200
+
201
+ steps :
202
+ - name : Checkout code
203
+ uses : actions/checkout@v4
204
+
205
+ - name : Setup Zig
206
+ uses : goto-bus-stop/setup-zig@v2
207
+ with :
208
+ version : 0.15.1
209
+
210
+ - name : Install system dependencies
211
+ run : |
212
+ sudo apt-get update
213
+ sudo apt-get install -y libspng-dev libjpeg-dev libtiff-dev pkg-config
214
+
215
+ - name : Run tests
216
+ run : |
217
+ zig build test-all
218
+
219
+ spellcheck :
220
+ name : Spell check
221
+ runs-on : ubuntu-latest
222
+ steps :
223
+ - name : Checkout code
224
+ uses : actions/checkout@v4
225
+
226
+ - name : Run typos
227
+ uses : crate-ci/typos@master
228
+ with :
229
+ config : ./typos.toml
230
+
130
231
publish :
131
232
name : Publish release
132
- needs : [build]
233
+ needs : [build, test ]
133
234
if : startsWith(github.ref, 'refs/tags/')
134
235
runs-on : ubuntu-latest
135
236
steps :
@@ -139,29 +240,28 @@ jobs:
139
240
- name : Download built binaries
140
241
uses : actions/download-artifact@v4
141
242
with :
142
- pattern : odiff-*.exe
243
+ pattern : odiff-*
143
244
merge-multiple : true
144
245
path : npm_package/raw_binaries
145
246
146
247
- name : Set up Node.js
147
248
uses : actions/setup-node@v4
148
249
with :
149
- node-version : ' 20 '
150
- cache : ' npm'
250
+ node-version : " 20 "
251
+ cache : " npm"
151
252
always-auth : true
152
- registry-url : ' https://registry.npmjs.org'
153
- cache-dependency-path : ' package-lock.json'
253
+ registry-url : " https://registry.npmjs.org"
254
+ cache-dependency-path : " package-lock.json"
154
255
155
256
- name : Publish npm package
156
257
working-directory : npm_package
157
258
run : npm publish
158
259
env :
159
260
NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
160
-
261
+
161
262
- name : Create github release
162
263
uses : softprops/action-gh-release@v1
163
264
with :
164
265
files : " npm_package/raw_binaries/*"
165
266
env :
166
267
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
167
-
0 commit comments