Skip to content

Commit

Permalink
feat: add WASM example (lambdaclass#1315)
Browse files Browse the repository at this point in the history
* Add example to workspace

* Rename example to wasm-demo, and add keywords

* Update example

* Update readme and links

* Make example show result

* Remove license, makefile, cairo contract

* Add contract source

* Update readme

* Update main readme

* Update changelog

* Compile example program in CI

* Build example program also in CI

* Modify dependencies in Makefile

* Compile example program in test_install workflow

* Cache correctly

* Activate venv before running make check

* Set pyenv local version in install scripts

* Remove venv activation from test_install

* Install requirements also in pyenv

* Add pyenv shims to PATH

* Add pyenv shims to path (now for real)

* Remove unneeded command and add instructions

* Fix workflow

* Merge install and compile steps

* Source script

* Apply Oppen's suggestions

* Add keywords to cli; use check instead of build

* Upload coverage from both runs and run on release

* Don't run in release

* Shallow clone repo before tests (+prints)

* Partition tests to reduce .profraw amount

* Fix: don't use '/' in the name

* Fix cache path

* Print only on debug

* Remove fetch-depth: 1 as it's the default

* Remove prints
  • Loading branch information
MegaRedHand authored and kariy committed Jul 25, 2023
1 parent 5f065e3 commit d8ac7b6
Show file tree
Hide file tree
Showing 19 changed files with 388 additions and 62 deletions.
80 changes: 55 additions & 25 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jobs:
path: |
cairo_programs/**/*.casm
cairo_programs/**/*.json
key: ${{ matrix.program-target }}-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
examples/wasm-demo/src/array_sum.json
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
Expand Down Expand Up @@ -81,7 +82,8 @@ jobs:
path: |
cairo_programs/**/*.casm
cairo_programs/**/*.json
key: cairo_test_programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
examples/wasm-demo/src/array_sum.json
key: cairo_test_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
- name: Fetch proof programs
uses: actions/cache/restore@v3
with:
Expand Down Expand Up @@ -137,7 +139,8 @@ jobs:
path: |
cairo_programs/**/*.casm
cairo_programs/**/*.json
key: cairo_test_programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
examples/wasm-demo/src/array_sum.json
key: cairo_test_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
- name: Fetch proof programs
uses: actions/cache/restore@v3
with:
Expand Down Expand Up @@ -184,17 +187,16 @@ jobs:
- name: Check no-std
run: |
cd ensure-no_std
cargo build --no-default-features
cargo build
cargo check --no-default-features
cargo check
tests:
needs: build-programs
strategy:
fail-fast: false
matrix:
special_features: ["", "lambdaworks-felt"]
target: [ test, test-no_std, test-wasm ]
# TODO: features
target: [ test#1, test#2, test-no_std, test-wasm ]
name: Run tests
runs-on: ubuntu-22.04
steps:
Expand All @@ -206,20 +208,15 @@ jobs:
uses: Swatinem/rust-cache@v2
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
# 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: Fetch test programs
uses: actions/cache/restore@v3
with:
path: |
cairo_programs/**/*.casm
cairo_programs/**/*.json
key: cairo_test_programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
examples/wasm-demo/src/array_sum.json
key: cairo_test_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
- name: Fetch proof programs
uses: actions/cache/restore@v3
with:
Expand All @@ -239,15 +236,23 @@ jobs:
uses: taiki-e/install-action@v2
with:
tool: cargo-nextest,cargo-llvm-cov,wasm-pack
- name: Run

- 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 ${{ matrix.target }} in
case ${NAME} in
'test')
cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}.info --workspace --features "cairo-1-hints, test_utils, ${{ matrix.special_features }}"
cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \
--partition count:${PARTITION}/2 \
--workspace --features "cairo-1-hints, test_utils, ${{ matrix.special_features }}"
;;
'test-no_std')
cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}.info --workspace --no-default-features --features "${{ matrix.special_features }}"
cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \
--workspace --no-default-features --features "${{ matrix.special_features }}"
;;
'test-wasm')
# NOTE: release mode is needed to avoid "too many locals" error
Expand All @@ -259,8 +264,8 @@ jobs:
if: matrix.target != 'test-wasm'
uses: actions/cache/save@v3
with:
path: lcov-${{ matrix.target }}.info
key: codecov-cache-${{ matrix.target }}-${{ github.sha }}
path: lcov-${{ matrix.target }}-${{ matrix.special_features }}.info
key: codecov-cache-${{ matrix.target }}-${{ matrix.special_features }}-${{ github.sha }}


build-release:
Expand Down Expand Up @@ -399,17 +404,42 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Fetch results for tests with stdlib
- 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.info
key: codecov-cache-test-${{ github.sha }}
path: lcov-test#2-.info
key: codecov-cache-test#2--${{ 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 }}
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 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
Expand Down
20 changes: 9 additions & 11 deletions .github/workflows/test_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ jobs:
python-version: '3.9'
cache: 'pip'

- name: Install dependencies
run: bash install.sh

- name: Compile project
run: cargo check
# NOTE: we do it in one step because GitHub cleans the PATH between steps
- name: Install dependencies and compile project
run: |
source install.sh
make check
install_debian:
name: "Install on debian-11"
Expand Down Expand Up @@ -77,10 +77,8 @@ jobs:
key: ${{ runner.os }}-python-install-${{ github.sha }}
restore-keys: ${{ runner.os }}-python-install-

- name: Install dependencies
run: bash install.sh

- name: Compile project
# NOTE: we do it in one step because GitHub cleans the PATH between steps
- name: Install dependencies and compile project
run: |
. "$HOME/.cargo/env"
cargo check
source install.sh
make check
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Upcoming Changes

* feat: updated the old WASM example and moved it to [`examples/wasm-demo`](examples/wasm-demo/) [#1315](https://github.com/lambdaclass/cairo-vm/pull/1315)

* feat: add `arbitrary` feature to enable arbitrary derive in `Program` and `CairoRunConfig`

* feat(fuzzing): add `arbitrary` feature to enable arbitrary derive in `Program` and `CairoRunConfig` [#1306](https://github.com/lambdaclass/cairo-vm/pull/1306) [#1330](https://github.com/lambdaclass/cairo-vm/pull/1330)
Expand Down
Loading

0 comments on commit d8ac7b6

Please sign in to comment.