Skip to content

Commit

Permalink
refactor: starknet compile function in casm compile
Browse files Browse the repository at this point in the history
  • Loading branch information
varex83 authored and rodrigo-pino committed Oct 30, 2024
1 parent f8bde15 commit 18aaae6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
13 changes: 4 additions & 9 deletions crates/blockifier/src/test_utils/cairo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ pub fn cairo1_compile(
git_tag_override: Option<String>,
cargo_nightly_arg: Option<String>,
) -> Vec<u8> {
prepare_cairo1_compiler_deps(git_tag_override);
let cairo1_compiler_path = local_cairo1_compiler_repo_path();

// Command args common to both compilation phases.
Expand All @@ -121,18 +120,14 @@ pub fn cairo1_compile(
"--bin".into(),
];
// Add additional cargo arg if provided. Should be first arg (base command is `cargo`).
if let Some(nightly_version) = cargo_nightly_arg {
if let Some(ref nightly_version) = cargo_nightly_arg {
base_compile_args.insert(0, format!("+nightly-{nightly_version}"));
}

// Cairo -> Sierra.
let mut starknet_compile_commmand = Command::new("cargo");
starknet_compile_commmand.args(base_compile_args.clone());
starknet_compile_commmand.args(["starknet-compile", "--", "--single-file", &path]);
let sierra_output = run_and_verify_output(&mut starknet_compile_commmand);
let sierra_output = starknet_compile(path, git_tag_override, cargo_nightly_arg);

let mut temp_file = NamedTempFile::new().unwrap();
temp_file.write_all(&sierra_output.stdout).unwrap();
temp_file.write_all(&sierra_output).unwrap();
let temp_path_str = temp_file.into_temp_path();

// Sierra -> CASM.
Expand All @@ -144,7 +139,7 @@ pub fn cairo1_compile(
casm_output.stdout
}

pub fn sierra_compile(
pub fn starknet_compile(
path: String,
git_tag_override: Option<String>,
cargo_nightly_arg: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions crates/blockifier/src/test_utils/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::execution::contract_class::{
NativeContractClassV1,
};
use crate::execution::entry_point::CallEntryPoint;
use crate::test_utils::cairo_compile::{cairo0_compile, cairo1_compile, sierra_compile};
use crate::test_utils::cairo_compile::{cairo0_compile, cairo1_compile, starknet_compile};
use crate::test_utils::{get_raw_contract_class, CairoVersion};

// This file contains featured contracts, used for tests. Use the function 'test_state' in
Expand Down Expand Up @@ -320,7 +320,7 @@ impl FeatureContract {
let (tag_override, cargo_nightly_arg) = self.fixed_tag_and_rust_toolchain();
cairo1_compile(self.get_source_path(), tag_override, cargo_nightly_arg)
}
CairoVersion::Native => sierra_compile(self.get_source_path(), None, None),
CairoVersion::Native => starknet_compile(self.get_source_path(), None, None),
}
}

Expand Down

0 comments on commit 18aaae6

Please sign in to comment.