-
-
Notifications
You must be signed in to change notification settings - Fork 47
465 lines (422 loc) · 17.7 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
name: Constantine CI
on: [push, pull_request]
# https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#permissions
permissions:
actions: write
checks: write
contents: read # list commits, change to write to create a release
jobs:
test:
strategy:
fail-fast: false
max-parallel: 20
matrix:
# version-2-0 is crashing due to https://github.com/mratsim/constantine/issues/471
# version-1-6 and version-2-0 have issues with templates in typedef operating on a generic for Fp12 tower in https://github.com/mratsim/constantine/pull/485
# Hence we only test and officially sypport 2.2.0, though 99% of Constantine should work on older compilers
# For ARM support on Linux we need to set a specific host
# either ubuntu-22.04-arm
# or ubuntu-24.04-arm
# We might as well test on 22.04 for ARM
nim_version: [version-2-2]
rust_toolchain: [stable] # [beta, nightly]
go_toolchain: [stable]
target:
# We only need to test 32-bit for targets like RISC-V that don't have ASM.
- os: linux
cpu: i386
ctt_backend: NO_ASM
host: ubuntu-latest
- os: linux
cpu: amd64
ctt_backend: NO_ASM
host: ubuntu-latest
- os: linux
cpu: amd64
ctt_backend: ASM
host: ubuntu-latest
# ASM code for ARM Linux is not available yet
- os: linux
cpu: arm64
ctt_backend: NO_ASM
host: ubuntu-22.04-arm
- os: windows
cpu: amd64
ctt_backend: NO_ASM
host: windows-latest
- os: windows
cpu: amd64
ctt_backend: ASM
host: windows-latest
- os: macos
cpu: arm64
ctt_backend: NO_ASM
host: macos-latest
- os: macos
cpu: arm64
ctt_backend: ASM
host: macos-latest
include:
- target:
os: linux
nim_channel: nightly
- target:
os: linux
nim_channel: nightly
- target:
os: macos
# MacOS Github agents are now using ARM and there are no ARM nightlies:
# https://github.com/mratsim/constantine/issues/372
# So we build from source
nim_channel: source
- target:
os: windows
nim_channel: nightly
name: '${{ matrix.target.os }}-${{ matrix.target.cpu }}-${{ matrix.target.ctt_backend }} (${{ matrix.nim_version }})'
runs-on: ${{ matrix.target.host }}
steps:
- name: Get branch name
shell: bash
run: |
if [[ '${{ github.event_name }}' == 'pull_request' ]]; then
echo "##[set-output name=branch_name;]$(echo ${GITHUB_HEAD_REF})"
echo "Branch found (PR): ${GITHUB_HEAD_REF}"
else
echo "##[set-output name=branch_name;]$(echo ${GITHUB_REF#refs/heads/})"
echo "Branch found (not PR): ${GITHUB_REF#refs/heads/}"
fi
id: get_branch
- name: Cancel Previous Runs (except master)
if: >
steps.get_branch.outputs.branch_name != 'master'
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- name: Checkout constantine
uses: actions/checkout@v4
with:
path: constantine
- name: Restore MinGW-W64 (Windows) from cache
if: runner.os == 'Windows'
id: windows-mingw-cache
uses: actions/cache@v4
with:
path: external/mingw-${{ matrix.target.cpu }}
key: 'mingw-${{ matrix.target.cpu }}'
- name: Restore Nim DLLs dependencies (Windows) from cache
if: runner.os == 'Windows'
id: windows-dlls-cache
uses: actions/cache@v4
with:
path: external/dlls-${{ matrix.target.cpu }}
key: 'dlls-${{ matrix.target.cpu }}'
- name: Install MinGW64 dependency (Windows)
if: >
steps.windows-mingw-cache.outputs.cache-hit != 'true' &&
runner.os == 'Windows'
shell: bash
run: |
mkdir -p external
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
MINGW_URL="https://github.com/brechtsanders/winlibs_mingw/releases/download/11.1.0-12.0.0-9.0.0-r2/winlibs-x86_64-posix-seh-gcc-11.1.0-mingw-w64-9.0.0-r2.7z"
ARCH=64
else
MINGW_URL="https://github.com/brechtsanders/winlibs_mingw/releases/download/11.1.0-12.0.0-9.0.0-r2/winlibs-i686-posix-dwarf-gcc-11.1.0-mingw-w64-9.0.0-r2.7z"
ARCH=32
fi
curl -L "$MINGW_URL" -o "external/mingw-${{ matrix.target.cpu }}.7z"
7z x -y "external/mingw-${{ matrix.target.cpu }}.7z" -oexternal/
mv external/mingw$ARCH external/mingw-${{ matrix.target.cpu }}
- name: Install DLLs dependencies (Windows)
if: >
steps.windows-dlls-cache.outputs.cache-hit != 'true' &&
runner.os == 'Windows'
shell: bash
run: |
mkdir -p external
curl -L "https://nim-lang.org/download/windeps.zip" -o external/windeps.zip
7z x -y external/windeps.zip -oexternal/dlls-${{ matrix.target.cpu }}
- name: Path to cached dependencies (Windows)
if: >
runner.os == 'Windows'
shell: bash
run: |
echo '${{ github.workspace }}'"/external/mingw-${{ matrix.target.cpu }}/bin" >> $GITHUB_PATH
echo '${{ github.workspace }}'"/external/dlls-${{ matrix.target.cpu }}" >> $GITHUB_PATH
- name: Get latest Nim commit hash & install dir
id: versions
shell: bash
run: |
getHash() {
git ls-remote "https://github.com/$1" "${2:-HEAD}" | cut -f 1
}
nimHash=$(getHash nim-lang/Nim '${{ matrix.branch }}')
installdir="nim-${{ matrix.target.os }}-${{ matrix.target.cpu }}-${{ matrix.nim_version }}-$nimHash"
echo "##[set-output name=installdir;]$(echo $installdir)"
echo "Nim installation directory: $installdir"
# Nightlies are already on Github
- name: Restore Nim from cache (except nightlies)
if: matrix.nim_channel != 'nightly'
id: nim-compiler-cache
uses: actions/cache@v4
with:
path: '${{ github.workspace }}/${{ steps.versions.outputs.installdir }}'
key: '${{ steps.versions.outputs.installdir }}'
- name: Setup Nim
if: steps.nim-compiler-cache.outputs.cache-hit != 'true'
shell: bash
run: |
bash constantine/scripts/install_nim.sh \
--nim-channel ${{ matrix.nim_channel }} \
--nim-version ${{ matrix.nim_version }} \
--os ${{ matrix.target.os }} \
--arch ${{ matrix.target.cpu }} \
--install-dir ${{ steps.versions.outputs.installdir }}
- name: Path to Nim
shell: bash
run: |
echo '${{ github.workspace }}'/"${{ steps.versions.outputs.installdir }}"/bin >> $GITHUB_PATH
echo '${{ github.workspace }}'"/.nimble/bin" >> $GITHUB_PATH
- name: Install test dependencies (Linux amd64)
if: runner.os == 'Linux' && matrix.target.cpu != 'i386'
run: |
sudo DEBIAN_FRONTEND='noninteractive' apt-get install \
--no-install-recommends -yq \
libgmp-dev \
llvm
- name: Install test dependencies (Linux i386)
if: runner.os == 'Linux' && matrix.target.cpu == 'i386'
# We don't install LLVM as the Rust libraries that call Constantine are 64-bit only.
run: |
sudo dpkg --add-architecture i386
sudo apt-get update -qq
# Try to fix "E: Unable to correct problems, you have held broken packages."
sudo apt-get clean
sudo DEBIAN_FRONTEND='noninteractive' apt-get install \
--no-install-recommends -yq \
gcc-multilib g++-multilib \
libssl-dev:i386 libgmp-dev:i386
mkdir -p external/bin
cat << EOF > external/bin/gcc
#!/bin/bash
exec $(which gcc) -m32 "\$@"
EOF
cat << EOF > external/bin/g++
#!/bin/bash
exec $(which g++) -m32 "\$@"
EOF
chmod 755 external/bin/{gcc,g++}
echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH
- name: Install test dependencies (macOS)
if: runner.os == 'macOS'
run: |
brew install gmp
- name: Setup MSYS2 (Windows)
if: runner.os == 'Windows'
uses: msys2/setup-msys2@v2
with:
path-type: inherit
update: false
install: base-devel git mingw-w64-x86_64-toolchain
- name: Install Go [${{ matrix.go_toolchain }}]
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go_toolchain }}
- name: Install Rust [${{ matrix.rust_toolchain }}]
shell: bash
run: rustup default ${{ matrix.rust_toolchain }}
- name: Print Nim, Go Rust, LLVM versions and CPU specs.
shell: bash
# gcc is an alias to Apple Clang on MacOS
run: |
nim -v
nimble -v
gcc -v
clang -v
go version
rustup --version
if [[ '${{ matrix.target.cpu }}' != 'i386' && '${{ runner.os }}' == 'Linux' ]]; then
llvm-config --version
fi
if [[ '${{ runner.os }}' == 'Linux' ]]; then
cat /proc/cpuinfo
fi
if [[ '${{ runner.os }}' == 'macOS' ]]; then
sysctl -a | grep machdep.cpu
sysctl -a | grep hw | grep cpu
sysctl -a | grep hw.optional
fi
- name: Install test dependencies (Windows)
if: runner.os == 'Windows'
shell: msys2 {0}
run: |
pacman -S --needed --noconfirm mingw-w64-x86_64-gmp mingw-w64-x86_64-llvm
nimble refresh --verbose -y
nimble install --verbose -y gmp@#head jsony asynctools [email protected] cliche
cd constantine
go mod download -modfile=go_test.mod
- name: Install test dependencies
if: runner.os != 'Windows'
shell: bash
run: |
nimble refresh --verbose -y
nimble install --verbose -y gmp@#head jsony asynctools [email protected] cliche
cd constantine
go mod download -modfile=go_test.mod
- name: Run Constantine as C library tests (Linux with Assembly)
if: runner.os == 'Linux' && matrix.target.ctt_backend == 'ASM'
shell: bash
run: |
cd constantine
nimble make_lib --verbose
nimble make_headers --verbose
nimble test_lib --verbose
- name: Run Constantine as C library tests (Linux no Assembly)
if: runner.os == 'Linux' && matrix.target.ctt_backend == 'NO_ASM'
shell: bash
run: |
cd constantine
CTT_ASM=0 nimble make_lib --verbose
nimble make_headers --verbose
nimble test_lib --verbose
- name: Run Constantine as C library tests (MacOS with Assembly)
# We manually do the tests due to Homebrew lib/headers not being in standard PATH
if: runner.os == 'macOS' && matrix.target.ctt_backend == 'ASM'
shell: bash
run: |
cd constantine
nimble make_lib --verbose
nimble make_headers --verbose
mkdir -p build/test_lib
clang -Iinclude -I"$(brew --prefix)/include" \
-Llib -L"$(brew --prefix)/lib" \
-o build/test_lib/t_libctt_bls12_381_staticlink.exe \
examples-c/t_libctt_bls12_381.c \
lib/libconstantine.a \
-lgmp
./build/test_lib/t_libctt_bls12_381_staticlink.exe
clang -Iinclude -I"$(brew --prefix)/include" \
-Llib -L"$(brew --prefix)/lib" \
-o build/test_lib/t_libctt_bls12_381_dynlink.exe \
examples-c/t_libctt_bls12_381.c \
-lconstantine \
-lgmp
./build/test_lib/t_libctt_bls12_381_dynlink.exe
clang -Iinclude -I"$(brew --prefix)/include" \
-Llib -L"$(brew --prefix)/lib" \
-o build/test_lib/t_libctt_banderwagon_staticlink.exe \
examples-c/t_libctt_banderwagon.c \
lib/libconstantine.a \
-lgmp
./build/test_lib/t_libctt_banderwagon_staticlink.exe
clang -Iinclude -I"$(brew --prefix)/include" \
-Llib -L"$(brew --prefix)/lib" \
-o build/test_lib/t_libctt_banderwagon_dynlink.exe \
examples-c/t_libctt_banderwagon.c \
-lconstantine \
-lgmp
./build/test_lib/t_libctt_banderwagon_dynlink.exe
clang -Iinclude -I"$(brew --prefix)/include" \
-Llib -L"$(brew --prefix)/lib" \
-o build/test_lib/ethereum_bls_signatures_staticlink.exe \
examples-c/ethereum_bls_signatures.c \
lib/libconstantine.a
./build/test_lib/ethereum_bls_signatures_staticlink.exe
clang -Iinclude -I"$(brew --prefix)/include" \
-Llib -L"$(brew --prefix)/lib" \
-o build/test_lib/ethereum_bls_signatures_dynlink.exe \
examples-c/ethereum_bls_signatures.c \
-lconstantine
./build/test_lib/ethereum_bls_signatures_dynlink.exe
- name: Run Constantine as C library tests (Windows with Assembly)
# So "test_lib" uses C and can find GMP
# but nim-gmp cannot find GMP on Windows CI
if: runner.os == 'Windows' && matrix.target.ctt_backend == 'ASM'
shell: msys2 {0}
run: |
cd constantine
nimble make_lib --verbose
nimble make_headers --verbose
nimble test_lib --verbose
- name: Run Constantine as Go library tests (with Assembly)
# This reuses the static library built with `nimble make_lib`
if: matrix.target.ctt_backend == 'ASM' && matrix.target.cpu != 'i386'
shell: bash
run: |
cd constantine/constantine-go
go test -modfile=../go_test.mod
- name: Run Constantine as Rust library tests (with Assembly)
if: matrix.target.ctt_backend == 'ASM' && matrix.target.cpu != 'i386'
shell: bash
# We need to deactivate the assembly (used by default for benches)
run: |
cd constantine
cargo test -- --nocapture
- name: Compile Constantine Zkalc benchmark (no assembly)
# Skip 32-bit as that would need clang-multilib or -m32
# Skip Windows as clang throws fatal error LNK1107
if: matrix.target.ctt_backend == 'NO_ASM' && matrix.target.cpu != 'i386' && runner.os != 'Windows'
shell: bash
run: |
cd constantine
CTT_ASM=0 nimble make_zkalc
- name: Compile Constantine Zkalc benchmark (with assembly)
# Skip 32-bit as that would need clang-multilib or -m32
# Skip Windows as clang throws fatal error LNK1107
if: matrix.target.ctt_backend == 'ASM' && matrix.target.cpu != 'i386' && runner.os != 'Windows'
shell: bash
run: |
cd constantine
nimble make_zkalc
- name: Run Constantine in-depth tests (Linux - with GMP, with Assembly)
if: runner.os == 'Linux' && matrix.target.ctt_backend == 'ASM'
shell: bash
run: |
cd constantine
nimble test_parallel --verbose
- name: Run Constantine in-depth tests (Linux - with GMP, no Assembly)
if: runner.os == 'Linux' && matrix.target.ctt_backend == 'NO_ASM'
shell: bash
run: |
cd constantine
CTT_ASM=0 nimble test_parallel --verbose
# On mac
# Homebrew install is not in default PATH
# this can be workaround with LD_LIBRARY_PATH for libraries
# but headers would need a
# --passC:-I$(brew --prefix)/include (-I/opt/homebrew/include on latest MacOS versions)
- name: Run Constantine in-depth tests (MacOS - no GMP, with Assembly)=
if: runner.os == 'macOS' && matrix.target.ctt_backend == 'ASM'
run: |
cd constantine
nimble test_parallel_no_gmp --verbose
- name: Run Constantine in-depth tests (MacOS - no GMP, no Assembly)
if: runner.os == 'macOS' && matrix.target.ctt_backend == 'NO_ASM'
run: |
cd constantine
CTT_ASM=0 nimble test_parallel_no_gmp --verbose
# On Windows
# So "test_bindings" uses C and can find GMP
# but nim-gmp cannot find GMP on Windows CI
# Also need to workaround asynctools not being able to create pipes https://github.com/nim-lang/Nim/issues/23118
# And LTO impossible constraint in the deneb_kzg test (but not MSM for some reason)
- name: Run Constantine in-depth tests (Windows - no GMP, with Assembly)=
if: runner.os == 'Windows' && matrix.target.ctt_backend == 'ASM'
shell: msys2 {0}
run: |
cd constantine
if [[ '${{ matrix.nim_version }}' != 'version-1-6' ]]; then
CTT_LTO=0 nimble test_no_gmp --verbose
else
nimble test_parallel_no_gmp --verbose
fi
- name: Run Constantine in-depth tests (Windows - no GMP, no Assembly)
if: runner.os == 'Windows' && matrix.target.ctt_backend == 'NO_ASM'
shell: msys2 {0}
run: |
cd constantine
if [[ '${{ matrix.nim_version }}' != 'version-1-6' ]]; then
CTT_ASM=0 CTT_LTO=0 nimble test_no_gmp --verbose
else
CTT_ASM=0 nimble test_parallel_no_gmp --verbose
fi