Skip to content

Commit 342b7ed

Browse files
chore(blockifier_test_utils): extract logic into starknet_sierra_compile
1 parent fedbe71 commit 342b7ed

1 file changed

Lines changed: 33 additions & 31 deletions

File tree

crates/blockifier_test_utils/src/cairo_compile.rs

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

178148
let cairo1_compiler_path = local_cairo1_compiler_repo_path();
@@ -188,9 +158,27 @@ pub fn starknet_compile(
188158
base_compile_args.insert(0, format!("+nightly-{nightly_version}"));
189159
}
190160

161+
let sierra_output = starknet_compile(path, &mut base_compile_args);
162+
163+
let mut temp_file = NamedTempFile::new().unwrap();
164+
temp_file.write_all(&sierra_output).unwrap();
165+
let temp_path_str = temp_file.into_temp_path();
166+
167+
// Sierra -> CASM.
168+
let casm_output = starknet_sierra_compile(
169+
temp_path_str.to_str().unwrap().to_string(),
170+
&mut base_compile_args,
171+
);
172+
173+
CompilationArtifacts::Cairo1 { casm: casm_output, sierra: sierra_output }
174+
}
175+
176+
/// Compile Cairo1 Contract into their Sierra version using the compiler version set in the
177+
/// Cargo.toml
178+
pub fn starknet_compile(path: String, base_compile_args: &mut [String]) -> Vec<u8> {
191179
// Cairo -> Sierra.
192180
let mut starknet_compile_commmand = Command::new("cargo");
193-
starknet_compile_commmand.args(base_compile_args.clone());
181+
starknet_compile_commmand.args(base_compile_args.to_owned());
194182
starknet_compile_commmand.args([
195183
"starknet-compile",
196184
"--",
@@ -204,6 +192,20 @@ pub fn starknet_compile(
204192
sierra_output.stdout
205193
}
206194

195+
/// Compile Sierra code into CASM.
196+
fn starknet_sierra_compile(path: String, base_compile_args: &mut Vec<String>) -> Vec<u8> {
197+
let mut sierra_compile_command = Command::new("cargo");
198+
sierra_compile_command.args(base_compile_args);
199+
sierra_compile_command.args([
200+
"starknet-sierra-compile",
201+
path.as_str(),
202+
"--allowed-libfuncs-list-name",
203+
"all",
204+
]);
205+
let casm_output = run_and_verify_output(&mut sierra_compile_command);
206+
casm_output.stdout
207+
}
208+
207209
/// Verifies that the required dependencies are available before compiling; panics if unavailable.
208210
fn verify_cairo0_compiler_deps() {
209211
// Python compiler. Verify correct version.

0 commit comments

Comments
 (0)