diff --git a/crates/blockifier_test_utils/src/cairo_compile.rs b/crates/blockifier_test_utils/src/cairo_compile.rs index 444ccf12275..3f7edd04982 100644 --- a/crates/blockifier_test_utils/src/cairo_compile.rs +++ b/crates/blockifier_test_utils/src/cairo_compile.rs @@ -10,8 +10,6 @@ use apollo_infra_utils::path::{project_path, resolve_project_relative_path}; use tempfile::NamedTempFile; use tracing::info; -use crate::contracts::TagAndToolchain; - static CAIRO0_PIP_REQUIREMENTS_FILE: LazyLock = LazyLock::new(|| resolve_project_relative_path("scripts/requirements.txt").unwrap()); const CAIRO1_REPO_RELATIVE_PATH_OVERRIDE_ENV_VAR: &str = "CAIRO1_REPO_RELATIVE_PATH"; @@ -89,8 +87,7 @@ fn cairo1_package_exists(version: &String) -> bool { /// Verifies that the Cairo1 package (of the given version) is available. /// Attempts to download it if not. -#[allow(dead_code)] -async fn verify_cairo1_package(version: &String) { +pub async fn verify_cairo1_package(version: &String) { if !cairo1_package_exists(version) { download_cairo_package(version).await; } @@ -133,24 +130,13 @@ pub fn cairo0_compile( pub fn cairo1_compile( path: String, git_tag_override: Option, - cargo_nightly_arg: Option, + _cargo_nightly_arg: Option, ) -> CompilationArtifacts { - verify_cairo1_compiler_deps(git_tag_override); - - let cairo1_compiler_path = local_cairo1_compiler_repo_path(); - - // Command args common to both compilation phases. - let mut base_compile_args = vec![ - "run".into(), - format!("--manifest-path={}/Cargo.toml", cairo1_compiler_path.to_string_lossy()), - "--bin".into(), - ]; - // Add additional cargo arg if provided. Should be first arg (base command is `cargo`). - if let Some(nightly_version) = cargo_nightly_arg { - base_compile_args.insert(0, format!("+nightly-{nightly_version}")); - } + let (tag, _cairo_repo_path) = get_tag_and_repo_file_path(git_tag_override); + let version = tag.strip_prefix("v").unwrap().to_string(); + assert!(cairo1_package_exists(&version)); - let sierra_output = starknet_compile(path, &base_compile_args); + let sierra_output = starknet_compile(path, &version); let mut temp_file = NamedTempFile::new().unwrap(); temp_file.write_all(&sierra_output).unwrap(); @@ -158,40 +144,26 @@ pub fn cairo1_compile( // Sierra -> CASM. let casm_output = - starknet_sierra_compile(temp_path_str.to_str().unwrap().to_string(), &base_compile_args); + starknet_sierra_compile(temp_path_str.to_str().unwrap().to_string(), &version); CompilationArtifacts::Cairo1 { casm: casm_output, sierra: sierra_output } } -/// Compiles Cairo1 Contract into their Sierra version using the compiler version set in the -/// Cargo.toml -pub fn starknet_compile(path: String, base_compile_args: &[String]) -> Vec { - // Cairo -> Sierra. - let mut starknet_compile_commmand = Command::new("cargo"); - starknet_compile_commmand.args(base_compile_args.to_owned()); - starknet_compile_commmand.args([ - "starknet-compile", - "--", - "--single-file", - &path, - "--allowed-libfuncs-list-name", - "all", - ]); +/// Compiles Cairo1 contracts into their Sierra version using the given compiler version. +/// Assumes the relevant compiler version was already downloaded. +pub fn starknet_compile(path: String, version: &String) -> Vec { + let mut starknet_compile_commmand = Command::new(starknet_compile_binary_path(version)); + starknet_compile_commmand.args(["--single-file", &path, "--allowed-libfuncs-list-name", "all"]); let sierra_output = run_and_verify_output(&mut starknet_compile_commmand); sierra_output.stdout } -/// Compiles Sierra code into CASM. -fn starknet_sierra_compile(path: String, base_compile_args: &[String]) -> Vec { - let mut sierra_compile_command = Command::new("cargo"); - sierra_compile_command.args(base_compile_args); - sierra_compile_command.args([ - "starknet-sierra-compile", - &path, - "--allowed-libfuncs-list-name", - "all", - ]); +/// Compiles Sierra code into CASM using the given compiler version. +/// Assumes the relevant compiler version was already downloaded. +fn starknet_sierra_compile(path: String, version: &String) -> Vec { + let mut sierra_compile_command = Command::new(starknet_sierra_compile_binary_path(version)); + sierra_compile_command.args([&path, "--allowed-libfuncs-list-name", "all"]); let casm_output = run_and_verify_output(&mut sierra_compile_command); casm_output.stdout } @@ -244,36 +216,3 @@ fn get_tag_and_repo_file_path(git_tag_override: Option) -> (String, Path (tag, cairo_repo_path) } - -pub fn prepare_group_tag_compiler_deps(tag_and_toolchain: &TagAndToolchain) { - let (optional_tag, optional_toolchain) = tag_and_toolchain; - - // Checkout the required version in the compiler repo. - let (tag, cairo_repo_path) = get_tag_and_repo_file_path(optional_tag.clone()); - run_and_verify_output(Command::new("git").args([ - "-C", - cairo_repo_path.to_str().unwrap(), - "checkout", - &tag, - ])); - - // Install the toolchain, if specified. - if let Some(toolchain) = optional_toolchain { - run_and_verify_output( - Command::new("rustup").args(["install", &format!("nightly-{toolchain}")]), - ); - } -} - -fn verify_cairo1_compiler_deps(git_tag_override: Option) { - let (tag, cairo_repo_path) = get_tag_and_repo_file_path(git_tag_override); - - // Verify that the checked out tag is as expected. - run_and_verify_output(Command::new("git").args([ - "-C", - cairo_repo_path.to_str().unwrap(), - "rev-parse", - "--verify", - &tag, - ])); -} diff --git a/crates/blockifier_test_utils/tests/feature_contracts_compatibility_test.rs b/crates/blockifier_test_utils/tests/feature_contracts_compatibility_test.rs index 4b09a78c7ca..1742254a4a1 100644 --- a/crates/blockifier_test_utils/tests/feature_contracts_compatibility_test.rs +++ b/crates/blockifier_test_utils/tests/feature_contracts_compatibility_test.rs @@ -1,6 +1,10 @@ use std::fs; -use blockifier_test_utils::cairo_compile::{prepare_group_tag_compiler_deps, CompilationArtifacts}; +use blockifier_test_utils::cairo_compile::{ + cairo1_compiler_tag, + verify_cairo1_package, + CompilationArtifacts, +}; use blockifier_test_utils::cairo_versions::{CairoVersion, RunnableCairo1}; use blockifier_test_utils::contracts::{ FeatureContract, @@ -85,7 +89,13 @@ async fn verify_feature_contracts_compatibility(fix: bool, cairo_version: CairoV for (tag_and_tool_chain, feature_contracts) in FeatureContract::cairo1_feature_contracts_by_tag() { - prepare_group_tag_compiler_deps(&tag_and_tool_chain); + let version = tag_and_tool_chain + .0 + .unwrap_or(cairo1_compiler_tag()) + .strip_prefix("v") + .unwrap() + .to_string(); + verify_cairo1_package(&version).await; let mut task_set = tokio::task::JoinSet::new(); @@ -97,9 +107,9 @@ async fn verify_feature_contracts_compatibility(fix: bool, cairo_version: CairoV task_set .spawn(verify_feature_contracts_compatibility_logic_async(contract, fix)); } - info!("Done spawning tasks for {tag_and_tool_chain:?}. Awaiting them..."); + info!("Done spawning tasks for {version:?}. Awaiting them..."); task_set.join_all().await; - info!("Done awaiting tasks for {tag_and_tool_chain:?}."); + info!("Done awaiting tasks for {version:?}."); } } #[cfg(feature = "cairo_native")]