Skip to content

Commit

Permalink
ci: optimize build checks (#1384)
Browse files Browse the repository at this point in the history
* ci: optimize build checks

Split build checks to parallel builds by:
- Sharding the workspace-level feature check;
- Launching a job per crate for the crate-level feature check.

* ci: test all combinations

* Update cairo1-run/Cargo.toml

* Update rust version for workflows added by this PR

* Download proof_porgrams symlinks

* Fix yaml

* Fix yaml

* Add Checkout step

* Update rust toolchain to match other workflows

* Remove duplicate feature

---------

Co-authored-by: Pedro Fontana <[email protected]>
Co-authored-by: fmoletta <[email protected]>
Co-authored-by: Federica <[email protected]>
Co-authored-by: Juan Bono <[email protected]>
  • Loading branch information
5 people authored Apr 9, 2024
1 parent 404407d commit 918d01c
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 22 deletions.
88 changes: 80 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ jobs:
smoke:
needs: merge-caches
name: Make sure all builds work
strategy:
fail-fast: false
matrix:
crate: ["vm", "cairo-vm-cli", "cairo1-run"]
runs-on: ubuntu-22.04
steps:
- name: Install Rust
Expand All @@ -210,6 +214,7 @@ jobs:
uses: taiki-e/install-action@v2
with:
tool: cargo-all-features

- name: Checkout
uses: actions/checkout@v3

Expand All @@ -226,19 +231,86 @@ jobs:
fail-on-cache-miss: true

# NOTE: we do this separately because --workspace operates in weird ways
- name: Check all features (vm)
- name: Check all features (${{ matrix.crate }})
run: |
cd vm
cd ${{ matrix.crate }}
cargo check-all-features
cargo check-all-features --workspace --all-targets
smoke-workspace:
needs: merge-caches
name: Make sure all builds work (workspace)
strategy:
fail-fast: false
matrix:
chunk: [1, 2, 3, 4, 5, 6]
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: Download proof programs symlinks
uses: actions/download-artifact@master
with:
name: proof_programs
path: cairo_programs/proof_programs/

- 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: 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
cargo check-all-features --n-chunks 6 --chunk ${{ matrix.chunk }} --workspace --all-targets
smoke-no-std:
needs: merge-caches
name: Make sure all builds work (no_std)
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: Checkout
uses: actions/checkout@v3

- name: Download proof programs symlinks
uses: actions/download-artifact@master
with:
name: proof_programs
path: cairo_programs/proof_programs/

- 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: Check no-std
run: |
Expand Down
2 changes: 0 additions & 2 deletions bench/criterion_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ use cairo_vm::{
};
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion};

#[cfg(feature = "with_mimalloc")]
use mimalloc::MiMalloc;

#[cfg(feature = "with_mimalloc")]
#[global_allocator]
static ALLOC: MiMalloc = MiMalloc;

Expand Down
2 changes: 0 additions & 2 deletions bench/iai_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ use cairo_vm::{
vm::{runners::cairo_runner::CairoRunner, vm_core::VirtualMachine},
};

#[cfg(feature = "with_mimalloc")]
use mimalloc::MiMalloc;

#[cfg(feature = "with_mimalloc")]
#[global_allocator]
static ALLOC: MiMalloc = MiMalloc;

Expand Down
6 changes: 4 additions & 2 deletions cairo-vm-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ rstest = "0.17.0"

[features]
default = ["with_mimalloc"]
with_mimalloc = ["cairo-vm/with_mimalloc", "dep:mimalloc"]
with_tracer = ["cairo-vm/with_tracer", "cairo-vm-tracer"]

with_mimalloc = ["dep:mimalloc"]
with_tracer = ["cairo-vm/tracer", "cairo-vm-tracer"]

1 change: 0 additions & 1 deletion cairo-vm-tracer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ readme.workspace = true
default = ["std"]
std = []
alloc = []
tracer = []

[dependencies]
cairo-vm = { workspace = true, features = ["arbitrary", "std"] }
Expand Down
2 changes: 1 addition & 1 deletion cairo1-run/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ num-traits = { version = "0.2", default-features = false }

[features]
default = ["with_mimalloc"]
with_mimalloc = ["cairo-vm/with_mimalloc", "dep:mimalloc"]
with_mimalloc = ["dep:mimalloc"]
6 changes: 2 additions & 4 deletions vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ readme.workspace = true
keywords.workspace = true

[features]
default = ["std", "with_mimalloc"]
with_mimalloc = ["dep:mimalloc"]
with_tracer = ["tracer"]
default = ["std"]
std = [
"serde_json/std",
"bincode/std",
Expand Down Expand Up @@ -46,7 +44,6 @@ print = ["std"]

[dependencies]
zip = {version = "0.6.6", optional = true }
mimalloc = { workspace = true, optional = true }
num-bigint = { workspace = true }
rand = { workspace = true }
num-traits = { workspace = true }
Expand Down Expand Up @@ -94,6 +91,7 @@ wasm-bindgen-test = "0.3.34"
iai-callgrind = "0.3.1"
criterion = { version = "0.5.1", features = ["html_reports"] }
proptest = "1.0.0"
mimalloc.workspace = true

[[bench]]
path = "../bench/iai_benchmark.rs"
Expand Down
1 change: 0 additions & 1 deletion vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//! - `skip_next_instruction_hint`: Enable the `skip_next_instruction()` hint. Not enabled by default.
//! - `hooks`: Enable [`Hooks`](crate::vm::hooks::Hooks) support for the [VirtualMachine](vm::vm_core::VirtualMachine). Not enabled by default.
//! - `test_utils`: Enables test utils (`hooks` and `skip_next_instruction` features). Not enabled by default.
//! - `with_mimalloc`: Use [`MiMalloc`](https://crates.io/crates/mimalloc) as the program global allocator.
//! - `cairo-1-hints`: Enable hints that were introduced in Cairo 1. Not enabled by default.
//! - `arbitrary`: Enables implementations of [`arbitrary::Arbitrary`](https://docs.rs/arbitrary/latest/arbitrary/) for some structs. Not enabled by default.
Expand Down
2 changes: 1 addition & 1 deletion vm/src/vm/vm_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ impl VirtualMachine {
Err(VirtualMachineError::NoOutputBuiltin)
}

#[cfg(feature = "with_tracer")]
#[cfg(feature = "tracer")]
pub fn relocate_segments(&self) -> Result<Vec<usize>, MemoryError> {
self.segments.relocate_segments()
}
Expand Down

0 comments on commit 918d01c

Please sign in to comment.