@@ -9,8 +9,6 @@ use apollo_infra_utils::path::project_path;
99use tempfile:: NamedTempFile ;
1010use tracing:: info;
1111
12- use crate :: contracts:: TagAndToolchain ;
13-
1412const CAIRO0_PIP_REQUIREMENTS_FILE : & str = "tests/requirements.txt" ;
1513const CAIRO1_REPO_RELATIVE_PATH_OVERRIDE_ENV_VAR : & str = "CAIRO1_REPO_RELATIVE_PATH" ;
1614const DEFAULT_CAIRO1_REPO_RELATIVE_PATH : & str = "../../../cairo" ;
@@ -93,8 +91,7 @@ fn download_cairo_package(version: &String) {
9391}
9492
9593/// Verifies that the Cairo1 package (of the given version) is available.
96- #[ allow( dead_code) ]
97- fn verify_cairo1_package ( version : & String , download_if_missing : bool ) {
94+ pub fn verify_cairo1_package ( version : & String , download_if_missing : bool ) {
9895 let cairo_compiler_path = starknet_compile_binary_path ( version) ;
9996 let sierra_compiler_path = starknet_sierra_compile_binary_path ( version) ;
10097 if download_if_missing && ( !cairo_compiler_path. exists ( ) || !sierra_compiler_path. exists ( ) ) {
@@ -140,68 +137,41 @@ pub fn cairo0_compile(
140137pub fn cairo1_compile (
141138 path : String ,
142139 git_tag_override : Option < String > ,
143- cargo_nightly_arg : Option < String > ,
140+ _cargo_nightly_arg : Option < String > ,
144141) -> CompilationArtifacts {
145- let mut base_compile_args = vec ! [ ] ;
146- verify_cairo1_compiler_deps ( git_tag_override) ;
147-
148- let cairo1_compiler_path = local_cairo1_compiler_repo_path ( ) ;
149-
150- // Command args common to both compilation phases.
151- base_compile_args. extend ( vec ! [
152- "run" . into( ) ,
153- format!( "--manifest-path={}/Cargo.toml" , cairo1_compiler_path. to_string_lossy( ) ) ,
154- "--bin" . into( ) ,
155- ] ) ;
156- // Add additional cargo arg if provided. Should be first arg (base command is `cargo`).
157- if let Some ( nightly_version) = cargo_nightly_arg {
158- base_compile_args. insert ( 0 , format ! ( "+nightly-{nightly_version}" ) ) ;
159- }
142+ let ( tag, _cairo_repo_path) = get_tag_and_repo_file_path ( git_tag_override) ;
143+ let download_if_missing = false ;
144+ let version = tag. strip_prefix ( "v" ) . unwrap ( ) . to_string ( ) ;
145+ verify_cairo1_package ( & version, download_if_missing) ;
160146
161- let sierra_output = starknet_compile ( path, & mut base_compile_args ) ;
147+ let sierra_output = starknet_compile ( path, & version ) ;
162148
163149 let mut temp_file = NamedTempFile :: new ( ) . unwrap ( ) ;
164150 temp_file. write_all ( & sierra_output) . unwrap ( ) ;
165151 let temp_path_str = temp_file. into_temp_path ( ) ;
166152
167153 // Sierra -> CASM.
168- let casm_output = starknet_sierra_compile (
169- temp_path_str. to_str ( ) . unwrap ( ) . to_string ( ) ,
170- & mut base_compile_args,
171- ) ;
154+ let casm_output =
155+ starknet_sierra_compile ( temp_path_str. to_str ( ) . unwrap ( ) . to_string ( ) , & version) ;
172156
173157 CompilationArtifacts :: Cairo1 { casm : casm_output, sierra : sierra_output }
174158}
175159
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 Vec < String > ) -> Vec < u8 > {
179- // Cairo -> Sierra.
180- let mut starknet_compile_commmand = Command :: new ( "cargo" ) ;
181- starknet_compile_commmand. args ( base_compile_args. clone ( ) ) ;
182- starknet_compile_commmand. args ( [
183- "starknet-compile" ,
184- "--" ,
185- "--single-file" ,
186- & path,
187- "--allowed-libfuncs-list-name" ,
188- "all" ,
189- ] ) ;
160+ /// Compile Cairo1 Contract into their Sierra version using the given compiler version.
161+ /// Assumes the relevant compiler version is already downloaded.
162+ pub fn starknet_compile ( path : String , version : & String ) -> Vec < u8 > {
163+ let mut starknet_compile_commmand = Command :: new ( starknet_compile_binary_path ( version) ) ;
164+ starknet_compile_commmand. args ( [ "--single-file" , & path, "--allowed-libfuncs-list-name" , "all" ] ) ;
190165 let sierra_output = run_and_verify_output ( & mut starknet_compile_commmand) ;
191166
192167 sierra_output. stdout
193168}
194169
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- ] ) ;
170+ /// Compile Sierra code into CASM using the given compiler version.
171+ /// Assumes the relevant compiler version is already downloaded.
172+ fn starknet_sierra_compile ( path : String , version : & String ) -> Vec < u8 > {
173+ let mut sierra_compile_command = Command :: new ( starknet_sierra_compile_binary_path ( version) ) ;
174+ sierra_compile_command. args ( [ path. as_str ( ) , "--allowed-libfuncs-list-name" , "all" ] ) ;
205175 let casm_output = run_and_verify_output ( & mut sierra_compile_command) ;
206176 casm_output. stdout
207177}
@@ -250,36 +220,3 @@ fn get_tag_and_repo_file_path(git_tag_override: Option<String>) -> (String, Path
250220
251221 ( tag, cairo_repo_path)
252222}
253-
254- pub fn prepare_group_tag_compiler_deps ( tag_and_toolchain : & TagAndToolchain ) {
255- let ( optional_tag, optional_toolchain) = tag_and_toolchain;
256-
257- // Checkout the required version in the compiler repo.
258- let ( tag, cairo_repo_path) = get_tag_and_repo_file_path ( optional_tag. clone ( ) ) ;
259- run_and_verify_output ( Command :: new ( "git" ) . args ( [
260- "-C" ,
261- cairo_repo_path. to_str ( ) . unwrap ( ) ,
262- "checkout" ,
263- & tag,
264- ] ) ) ;
265-
266- // Install the toolchain, if specified.
267- if let Some ( toolchain) = optional_toolchain {
268- run_and_verify_output (
269- Command :: new ( "rustup" ) . args ( [ "install" , & format ! ( "nightly-{toolchain}" ) ] ) ,
270- ) ;
271- }
272- }
273-
274- fn verify_cairo1_compiler_deps ( git_tag_override : Option < String > ) {
275- let ( tag, cairo_repo_path) = get_tag_and_repo_file_path ( git_tag_override) ;
276-
277- // Verify that the checked out tag is as expected.
278- run_and_verify_output ( Command :: new ( "git" ) . args ( [
279- "-C" ,
280- cairo_repo_path. to_str ( ) . unwrap ( ) ,
281- "rev-parse" ,
282- "--verify" ,
283- & tag,
284- ] ) ) ;
285- }
0 commit comments