-
Notifications
You must be signed in to change notification settings - Fork 149
548 lines (488 loc) · 18.1 KB
/
rust.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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
name: QA
on:
merge_group:
push:
branches: [ main ]
pull_request:
branches: [ '**' ]
env:
CARGO_TERM_COLOR: always
CAIRO_PROGRAMS_PATH: |
cairo_programs/**/*.casm
cairo_programs/**/*.json
!cairo_programs/manually_compiled/*
examples/wasm-demo/src/array_sum.json
jobs:
build-programs:
strategy:
matrix:
# NOTE: we build cairo_bench_programs so clippy can check the benchmarks too
program-target: [
cairo_bench_programs,
cairo_proof_programs,
cairo_test_programs,
cairo_1_test_contracts,
cairo_2_test_contracts,
]
name: Build Cairo programs
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Fetch from cache
uses: actions/cache@v3
id: cache-programs
with:
path: ${{ env.CAIRO_PROGRAMS_PATH }}
key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
restore-keys: ${{ matrix.program-target }}-cache-
# This is not pretty, but we need `make` to see the compiled programs are
# actually newer than the sources, otherwise it will try to rebuild them
- name: Restore timestamps
uses: chetan/git-restore-mtime-action@v1
- name: Python3 Build
if: steps.cache-programs.outputs.cache-hit != 'true'
&& matrix.program-target != 'cairo_1_test_contracts'
&& matrix.program-target != 'cairo_2_test_contracts'
uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip'
- name: Install cairo-lang and deps
if: |
steps.cache-programs.outputs.cache-hit != 'true'
&& matrix.program-target != 'cairo_1_test_contracts'
&& matrix.program-target != 'cairo_2_test_contracts'
run: pip install -r requirements.txt
- name: Install cairo 1 compiler
if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_1_test_contracts'
run: make build-cairo-1-compiler
- name: Install cairo 2 compiler
if: steps.cache-programs.outputs.cache-hit != 'true' && matrix.program-target == 'cairo_2_test_contracts'
run: make build-cairo-2-compiler
- name: Build programs
if: steps.cache-programs.outputs.cache-hit != 'true'
run: make -j ${{ matrix.program-target }}
# NOTE: used to reduce the amount of cache steps we need in later jobs
# TODO: remove this cache once the workflow finishes
merge-caches:
name: Merge Cairo programs cache
runs-on: ubuntu-22.04
needs: build-programs
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Fetch test programs
uses: actions/cache/restore@v3
with:
path: ${{ env.CAIRO_PROGRAMS_PATH }}
key: cairo_test_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
fail-on-cache-miss: true
- name: Fetch proof programs
uses: actions/cache/restore@v3
with:
path: ${{ env.CAIRO_PROGRAMS_PATH }}
key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
fail-on-cache-miss: true
- name: Fetch bench programs
uses: actions/cache/restore@v3
with:
path: ${{ env.CAIRO_PROGRAMS_PATH }}
key: cairo_bench_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
fail-on-cache-miss: true
- name: Fetch test contracts (Cairo 1)
uses: actions/cache/restore@v3
with:
path: ${{ env.CAIRO_PROGRAMS_PATH }}
key: cairo_1_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
fail-on-cache-miss: true
- name: Fetch test contracts (Cairo 2)
uses: actions/cache/restore@v3
with:
path: ${{ env.CAIRO_PROGRAMS_PATH }}
key: cairo_2_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
fail-on-cache-miss: true
- name: Merge caches
uses: actions/cache/save@v3
with:
path: ${{ env.CAIRO_PROGRAMS_PATH }}
key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
lint:
needs: build-programs
name: Run Lints
runs-on: ubuntu-22.04
steps:
- name: Install Rust
uses: dtolnay/[email protected]
with:
components: rustfmt, clippy
- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
- name: Checkout
uses: actions/checkout@v3
- name: Format
run: make check-fmt
- name: Fetch programs
uses: actions/cache/restore@v3
with:
path: ${{ env.CAIRO_PROGRAMS_PATH }}
key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
fail-on-cache-miss: true
- name: Run clippy
run: make clippy
# NOTE: the term "smoke test" comes from electronics design: the minimal
# expectations anyone has in their device is to not catch fire on boot.
smoke:
needs: merge-caches
name: Make sure all builds work
runs-on: ubuntu-22.04
steps:
- name: Install Rust
uses: dtolnay/[email protected]
with:
targets: wasm32-unknown-unknown
- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Install cargo-all-features
uses: taiki-e/install-action@v2
with:
tool: cargo-all-features
- name: Checkout
uses: actions/checkout@v3
- name: Fetch programs
uses: actions/cache/restore@v3
with:
path: ${{ env.CAIRO_PROGRAMS_PATH }}
key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
fail-on-cache-miss: true
# NOTE: we do this separately because --workspace operates in weird ways
- name: Check all features (felt)
run: |
cd felt
cargo check-all-features
cargo check-all-features --workspace --all-targets
- name: Check all features (vm)
run: |
cd vm
cargo check-all-features
- name: Check all features (CLI)
run: |
cd cairo-vm-cli
cargo check-all-features
- name: Check all features (workspace)
run: |
cargo check-all-features --workspace --all-targets
- name: Check no-std
run: |
cd ensure-no_std
cargo check --no-default-features
cargo check
tests:
needs: merge-caches
strategy:
fail-fast: false
matrix:
special_features: ["", "lambdaworks-felt"]
target: [ test#1, test#2, test#3, test#4, test-no_std#1, test-no_std#2, test-no_std#3, test-no_std#4, test-wasm ]
name: Run tests
runs-on: ubuntu-22.04
steps:
- name: Install Rust
uses: dtolnay/[email protected]
with:
components: llvm-tools-preview
- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
- name: Checkout
uses: actions/checkout@v3
- name: Fetch programs
uses: actions/cache/restore@v3
with:
path: ${{ env.CAIRO_PROGRAMS_PATH }}
key: all-programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
fail-on-cache-miss: true
- name: Install testing tools
uses: taiki-e/install-action@v2
with:
tool: [email protected],cargo-llvm-cov,wasm-pack
- name: Install cairo 1 dependencies for running programs
run: |
cd cairo1-run
make deps
- name: Run ${{ matrix.target }}
run: |
# this splits the `test#1` into `test` and `1`
export MATRIX_TARGET=${{ matrix.target }}
export NAME=${MATRIX_TARGET%#*}
export PARTITION=${MATRIX_TARGET#*#}
# FIXME: we need to update the Makefile to do this correctly
case ${NAME} in
'test')
cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \
--partition count:${PARTITION}/4 \
--workspace --features "cairo-1-hints, test_utils, ${{ matrix.special_features }}"
;;
'test-no_std')
cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \
--partition count:${PARTITION}/4 \
--workspace --no-default-features --features "${{ matrix.special_features }}"
;;
'test-wasm')
# NOTE: release mode is needed to avoid "too many locals" error
wasm-pack test --release --node vm --no-default-features --features "${{ matrix.special_features }}"
;;
esac
- name: Save coverage
if: matrix.target != 'test-wasm'
uses: actions/cache/save@v3
with:
path: lcov-${{ matrix.target }}-${{ matrix.special_features }}.info
key: codecov-cache-${{ matrix.target }}-${{ matrix.special_features }}-${{ github.sha }}
build-release:
name: Build release binary for comparisons
runs-on: ubuntu-22.04
steps:
- name: Install Rust
uses: dtolnay/[email protected]
- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
- name: Checkout
uses: actions/checkout@v3
- name: Build
run: cargo b --release -p cairo-vm-cli
# We don't read from cache because it should always miss
- name: Store in cache
uses: actions/cache/save@v3
with:
key: cli-bin-rel-${{ github.sha }}
path: target/release/cairo-vm-cli
run-cairo-reference:
strategy:
matrix:
include:
- program-target: cairo_proof_programs
trace-target: cairo_proof_trace
nprocs: 1
- program-target: cairo_test_programs
trace-target: cairo_trace
nprocs: 2
name: Compute memory and execution traces with cairo-lang
needs: build-programs
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Check cache
uses: actions/cache@v3
id: trace-cache
with:
path: |
cairo_programs/**/*.memory
cairo_programs/**/*.trace
cairo_programs/**/*.air_public_input
key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
restore-keys: ${{ matrix.program-target }}-reference-trace-cache-
- name: Python3 Build
if: steps.trace-cache.outputs.cache-hit != 'true'
uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip'
- name: Install cairo-lang and deps
if: steps.trace-cache.outputs.cache-hit != 'true'
run: pip install -r requirements.txt
- name: Fetch programs
if: steps.trace-cache.outputs.cache-hit != 'true'
uses: actions/cache/restore@v3
with:
path: ${{ env.CAIRO_PROGRAMS_PATH }}
key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
fail-on-cache-miss: true
# This is not pretty, but we need `make` to see the compiled programs are
# actually newer than the sources, otherwise it will try to rebuild them
- name: Restore timestamps
if: steps.trace-cache.outputs.cache-hit != 'true'
uses: chetan/git-restore-mtime-action@v1
- name: Generate traces
if: steps.trace-cache.outputs.cache-hit != 'true'
run: make -j ${{ matrix.nprocs }} ${{ matrix.trace-target }}
run-cairo-release:
strategy:
matrix:
include:
- program-target: cairo_proof_programs
programs-dir: cairo_programs/proof_programs
extra-args: '--proof_mode --air_public_input {program}.rs.air_public_input '
- program-target: cairo_test_programs
programs-dir: cairo_programs
extra-args: ''
name: Compute memory and execution traces with cairo-vm
needs: [ build-programs, build-release ]
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Fetch release binary
uses: actions/cache/restore@v3
with:
key: cli-bin-rel-${{ github.sha }}
path: target/release/cairo-vm-cli
fail-on-cache-miss: true
- name: Fetch programs
uses: actions/cache/restore@v3
with:
path: ${{ env.CAIRO_PROGRAMS_PATH }}
key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
fail-on-cache-miss: true
- name: Generate traces
run: |
ls ${{ matrix.programs-dir }}/*.json | cut -f1 -d'.' | \
xargs -P 2 -I '{program}' \
./target/release/cairo-vm-cli '{program}'.json --layout starknet_with_keccak \
--memory_file '{program}'.rs.memory --trace_file '{program}'.rs.trace \
${{ matrix.extra-args }}
- name: Update cache
uses: actions/cache/save@v3
with:
path: |
cairo_programs/**/*.memory
cairo_programs/**/*.trace
cairo_programs/**/*.air_public_input
key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }}
upload-coverage:
name: Upload coverage results to codecov.io
needs: tests
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Fetch results for tests with stdlib (part. 1)
uses: actions/cache/restore@v3
with:
path: lcov-test#1-.info
key: codecov-cache-test#1--${{ github.sha }}
fail-on-cache-miss: true
- name: Fetch results for tests with stdlib (part. 2)
uses: actions/cache/restore@v3
with:
path: lcov-test#2-.info
key: codecov-cache-test#2--${{ github.sha }}
fail-on-cache-miss: true
- name: Fetch results for tests with stdlib (part. 3)
uses: actions/cache/restore@v3
with:
path: lcov-test#3-.info
key: codecov-cache-test#3--${{ github.sha }}
fail-on-cache-miss: true
- name: Fetch results for tests with stdlib (part. 4)
uses: actions/cache/restore@v3
with:
path: lcov-test#4-.info
key: codecov-cache-test#4--${{ github.sha }}
fail-on-cache-miss: true
- name: Fetch results for tests without stdlib
uses: actions/cache/restore@v3
with:
path: lcov-test-no_std-.info
key: codecov-cache-test-no_std--${{ github.sha }}
fail-on-cache-miss: true
- name: Fetch results for tests with stdlib (w/lambdaworks; part. 1)
uses: actions/cache/restore@v3
with:
path: lcov-test#1-lambdaworks-felt.info
key: codecov-cache-test#1-lambdaworks-felt-${{ github.sha }}
fail-on-cache-miss: true
- name: Fetch results for tests with stdlib (w/lambdaworks; part. 2)
uses: actions/cache/restore@v3
with:
path: lcov-test#2-lambdaworks-felt.info
key: codecov-cache-test#2-lambdaworks-felt-${{ github.sha }}
fail-on-cache-miss: true
- name: Fetch results for tests with stdlib (w/lambdaworks; part. 3)
uses: actions/cache/restore@v3
with:
path: lcov-test#3-lambdaworks-felt.info
key: codecov-cache-test#3-lambdaworks-felt-${{ github.sha }}
fail-on-cache-miss: true
- name: Fetch results for tests with stdlib (w/lambdaworks; part. 4)
uses: actions/cache/restore@v3
with:
path: lcov-test#4-lambdaworks-felt.info
key: codecov-cache-test#4-lambdaworks-felt-${{ github.sha }}
fail-on-cache-miss: true
- name: Fetch results for tests without stdlib (w/lambdaworks)
uses: actions/cache/restore@v3
with:
path: lcov-test-no_std-lambdaworks-felt.info
key: codecov-cache-test-no_std-lambdaworks-felt-${{ github.sha }}
fail-on-cache-miss: true
- name: Upload coverage to codecov.io
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: '*.info'
fail_ci_if_error: true
compare-memory-and-trace:
strategy:
matrix:
program-target: [ cairo_proof_programs, cairo_test_programs ]
name: Compare memory and execution traces from cairo-lang and cairo-vm
needs: [ run-cairo-reference, run-cairo-release ]
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Fetch traces for cairo-lang
uses: actions/cache/restore@v3
with:
path: |
cairo_programs/**/*.memory
cairo_programs/**/*.trace
cairo_programs/**/*.air_public_input
key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
fail-on-cache-miss: true
- name: Fetch traces for cairo-vm
uses: actions/cache/restore@v3
with:
path: |
cairo_programs/**/*.memory
cairo_programs/**/*.trace
cairo_programs/**/*.air_public_input
key: ${{ matrix.program-target }}-release-trace-cache-${{ github.sha }}
fail-on-cache-miss: true
- name: Run comparison script
run: |
if [ ${{ matrix.program-target }} = cairo_proof_programs ]; then
PROOF=proof_mode
AIR_PUBLIC_INPUT=air_public_input
fi
./vm/src/tests/compare_vm_state.sh trace memory $PROOF $AIR_PUBLIC_INPUT
./vm/src/tests/compare_vm_state.sh trace memory $PROOF
wasm-demo:
name: Build the wasm demo
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Python3 Build
uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip'
- name: Install cairo-lang and deps
run: |
pip install -r requirements.txt
npm install -g wasm-pack
- name: Build wasm-demo
run: |
cairo-compile cairo_programs/array_sum.cairo --no_debug_info --output cairo_programs/array_sum.json
cd examples/wasm-demo
wasm-pack build --target=web