Skip to content

Commit 180668b

Browse files
feat: ODiff v3 SIMD (#125)
* feat: ODiff v3 SIMD * chore(release): v3.0.0-beta.1 * fxi: Build script * chore(release): v3.0.0-beta.2 * Fail cross compilation * chore(release): v3.0.0-beta.3
1 parent df03e4a commit 180668b

File tree

128 files changed

+4686
-5613
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+4686
-5613
lines changed

.gitattributes

Lines changed: 0 additions & 2 deletions
This file was deleted.

.github/FUNDING.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 170 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,75 @@ jobs:
1414
strategy:
1515
matrix:
1616
include:
17-
- os: ubuntu-latest
17+
- target: x86_64-linux-gnu
18+
os: ubuntu-latest
1819
artifact: "linux-x64"
19-
ocaml-compiler: "ocaml-variants.5.2.0+options,ocaml-option-flambda"
2020
triplet: "x64-linux"
21-
- os: ubuntu-24.04-arm
21+
- target: aarch64-linux-gnu
22+
os: ubuntu-latest
2223
artifact: "linux-arm64"
23-
ocaml-compiler: "ocaml-variants.5.2.0+options,ocaml-option-flambda"
2424
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"
2829
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
3037
artifact: "macos-arm64"
31-
ocaml-compiler: "ocaml-variants.5.2.0+options,ocaml-option-flambda"
3238
triplet: "arm64-osx"
33-
- os: macos-13
39+
- target: x86_64-macos
40+
os: macos-13
3441
artifact: "macos-x64"
35-
ocaml-compiler: "ocaml-variants.5.2.0+options,ocaml-option-flambda"
3642
triplet: "x64-osx"
3743
defaults:
3844
run:
3945
shell: bash
46+
4047
steps:
41-
- uses: actions/[email protected]
48+
- name: Checkout code
49+
uses: actions/checkout@v4
4250

4351
- if: runner.os == 'Windows'
4452
run: |
4553
rm -rf $(which pkg-config)
4654
choco install pkgconfiglite
4755
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
4983

5084
- uses: lukka/get-cmake@latest
51-
- name: Setup anew (or from cache) vcpkg (and does not build any package)
85+
- name: Setup vcpkg
5286
uses: lukka/run-vcpkg@v11
5387
env:
5488
VCPKG_DEFAULT_TRIPLET: ${{ matrix.triplet }}
@@ -64,72 +98,139 @@ jobs:
6498
ls "${GITHUB_WORKSPACE}/vcpkg_installed/${VCPKG_DEFAULT_TRIPLET}/lib/pkgconfig"
6599
echo "PKG_CONFIG_PATH=${GITHUB_WORKSPACE}/vcpkg_installed/${VCPKG_DEFAULT_TRIPLET}/lib/pkgconfig" >> $GITHUB_ENV
66100
67-
- name: Set pkg-config path on Unix
101+
- name: Set pkg-config path on Windows
68102
shell: bash
69-
if: runner.os == 'Windows'
103+
if: runner.os == 'Windows'
70104
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
72106
73-
- shell: bash
107+
- name: Build for ${{ matrix.target }}
108+
env:
109+
VCPKG_ROOT: ${{ github.workspace }}/vcpkg_installed
74110
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
87116
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
90130
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
93154
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
99180
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
117182
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
121188
122-
- if: always()
189+
- name: Upload artifact
123190
uses: actions/upload-artifact@v4
124191
with:
125192
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 }}
128195
retention-days: 14
129196

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+
130231
publish:
131232
name: Publish release
132-
needs: [build]
233+
needs: [build, test]
133234
if: startsWith(github.ref, 'refs/tags/')
134235
runs-on: ubuntu-latest
135236
steps:
@@ -139,29 +240,28 @@ jobs:
139240
- name: Download built binaries
140241
uses: actions/download-artifact@v4
141242
with:
142-
pattern: odiff-*.exe
243+
pattern: odiff-*
143244
merge-multiple: true
144245
path: npm_package/raw_binaries
145246

146247
- name: Set up Node.js
147248
uses: actions/setup-node@v4
148249
with:
149-
node-version: '20'
150-
cache: 'npm'
250+
node-version: "20"
251+
cache: "npm"
151252
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"
154255

155256
- name: Publish npm package
156257
working-directory: npm_package
157258
run: npm publish
158259
env:
159260
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
160-
261+
161262
- name: Create github release
162263
uses: softprops/action-gh-release@v1
163264
with:
164265
files: "npm_package/raw_binaries/*"
165266
env:
166267
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
167-

.gitignore

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
.merlin
2-
.DS_Store
3-
**/.DS_Store
1+
.zig-cache/
42
node_modules/
5-
_build
6-
_esy
7-
_release
8-
*.byte
9-
*.native
10-
*.install
11-
images/diff.png
12-
test/test-images/_*.png
13-
vcpkg_installed/*
14-
out.png
15-
_opam/
3+
vcpkg/
4+
zig-out/

.spr.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.vscode/c_cpp_properties.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)