Skip to content

Commit 8815395

Browse files
chore(blockifier_test_utils): extract logic into starknet_sierra_compile
1 parent 64193f0 commit 8815395

1 file changed

Lines changed: 31 additions & 31 deletions

File tree

crates/blockifier_test_utils/src/cairo_compile.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -136,36 +136,6 @@ pub fn cairo1_compile(
136136
cargo_nightly_arg: Option<String>,
137137
) -> CompilationArtifacts {
138138
let mut base_compile_args = vec![];
139-
140-
let sierra_output =
141-
starknet_compile(path, git_tag_override, cargo_nightly_arg, &mut base_compile_args);
142-
143-
let mut temp_file = NamedTempFile::new().unwrap();
144-
temp_file.write_all(&sierra_output).unwrap();
145-
let temp_path_str = temp_file.into_temp_path();
146-
147-
// Sierra -> CASM.
148-
let mut sierra_compile_command = Command::new("cargo");
149-
sierra_compile_command.args(base_compile_args);
150-
sierra_compile_command.args([
151-
"starknet-sierra-compile",
152-
temp_path_str.to_str().unwrap(),
153-
"--allowed-libfuncs-list-name",
154-
"all",
155-
]);
156-
let casm_output = run_and_verify_output(&mut sierra_compile_command);
157-
158-
CompilationArtifacts::Cairo1 { casm: casm_output.stdout, sierra: sierra_output }
159-
}
160-
161-
/// Compile Cairo1 Contract into their Sierra version using the compiler version set in the
162-
/// Cargo.toml
163-
pub fn starknet_compile(
164-
path: String,
165-
git_tag_override: Option<String>,
166-
cargo_nightly_arg: Option<String>,
167-
base_compile_args: &mut Vec<String>,
168-
) -> Vec<u8> {
169139
verify_cairo1_compiler_deps(git_tag_override);
170140

171141
let cairo1_compiler_path = local_cairo1_compiler_repo_path();
@@ -181,9 +151,25 @@ pub fn starknet_compile(
181151
base_compile_args.insert(0, format!("+nightly-{nightly_version}"));
182152
}
183153

154+
let sierra_output = starknet_compile(path, &base_compile_args);
155+
156+
let mut temp_file = NamedTempFile::new().unwrap();
157+
temp_file.write_all(&sierra_output).unwrap();
158+
let temp_path_str = temp_file.into_temp_path();
159+
160+
// Sierra -> CASM.
161+
let casm_output =
162+
starknet_sierra_compile(temp_path_str.to_str().unwrap().to_string(), &base_compile_args);
163+
164+
CompilationArtifacts::Cairo1 { casm: casm_output, sierra: sierra_output }
165+
}
166+
167+
/// Compiles Cairo1 Contract into their Sierra version using the compiler version set in the
168+
/// Cargo.toml
169+
pub fn starknet_compile(path: String, base_compile_args: &[String]) -> Vec<u8> {
184170
// Cairo -> Sierra.
185171
let mut starknet_compile_commmand = Command::new("cargo");
186-
starknet_compile_commmand.args(base_compile_args.clone());
172+
starknet_compile_commmand.args(base_compile_args.to_owned());
187173
starknet_compile_commmand.args([
188174
"starknet-compile",
189175
"--",
@@ -197,6 +183,20 @@ pub fn starknet_compile(
197183
sierra_output.stdout
198184
}
199185

186+
/// Compiles Sierra code into CASM.
187+
fn starknet_sierra_compile(path: String, base_compile_args: &[String]) -> Vec<u8> {
188+
let mut sierra_compile_command = Command::new("cargo");
189+
sierra_compile_command.args(base_compile_args);
190+
sierra_compile_command.args([
191+
"starknet-sierra-compile",
192+
&path,
193+
"--allowed-libfuncs-list-name",
194+
"all",
195+
]);
196+
let casm_output = run_and_verify_output(&mut sierra_compile_command);
197+
casm_output.stdout
198+
}
199+
200200
/// Verifies that the required dependencies are available before compiling; panics if unavailable.
201201
fn verify_cairo0_compiler_deps() {
202202
// Python compiler. Verify correct version.

0 commit comments

Comments
 (0)