@@ -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" ;
@@ -100,8 +98,7 @@ fn cairo1_package_exists(version: &String) -> bool {
10098
10199/// Verifies that the Cairo1 package (of the given version) is available.
102100/// Attempts to download it if not.
103- #[ allow( dead_code) ]
104- async fn verify_cairo1_package ( version : & String ) {
101+ pub async fn verify_cairo1_package ( version : & String ) {
105102 if !cairo1_package_exists ( version) {
106103 download_cairo_package ( version) . await ;
107104 }
@@ -144,68 +141,40 @@ pub fn cairo0_compile(
144141pub fn cairo1_compile (
145142 path : String ,
146143 git_tag_override : Option < String > ,
147- cargo_nightly_arg : Option < String > ,
144+ _cargo_nightly_arg : Option < String > ,
148145) -> CompilationArtifacts {
149- let mut base_compile_args = vec ! [ ] ;
150- verify_cairo1_compiler_deps ( git_tag_override) ;
151-
152- let cairo1_compiler_path = local_cairo1_compiler_repo_path ( ) ;
153-
154- // Command args common to both compilation phases.
155- base_compile_args. extend ( vec ! [
156- "run" . into( ) ,
157- format!( "--manifest-path={}/Cargo.toml" , cairo1_compiler_path. to_string_lossy( ) ) ,
158- "--bin" . into( ) ,
159- ] ) ;
160- // Add additional cargo arg if provided. Should be first arg (base command is `cargo`).
161- if let Some ( nightly_version) = cargo_nightly_arg {
162- base_compile_args. insert ( 0 , format ! ( "+nightly-{nightly_version}" ) ) ;
163- }
146+ let ( tag, _cairo_repo_path) = get_tag_and_repo_file_path ( git_tag_override) ;
147+ let version = tag. strip_prefix ( "v" ) . unwrap ( ) . to_string ( ) ;
148+ assert ! ( cairo1_package_exists( & version) ) ;
164149
165- let sierra_output = starknet_compile ( path, & mut base_compile_args ) ;
150+ let sierra_output = starknet_compile ( path, & version ) ;
166151
167152 let mut temp_file = NamedTempFile :: new ( ) . unwrap ( ) ;
168153 temp_file. write_all ( & sierra_output) . unwrap ( ) ;
169154 let temp_path_str = temp_file. into_temp_path ( ) ;
170155
171156 // Sierra -> CASM.
172- let casm_output = starknet_sierra_compile (
173- temp_path_str. to_str ( ) . unwrap ( ) . to_string ( ) ,
174- & mut base_compile_args,
175- ) ;
157+ let casm_output =
158+ starknet_sierra_compile ( temp_path_str. to_str ( ) . unwrap ( ) . to_string ( ) , & version) ;
176159
177160 CompilationArtifacts :: Cairo1 { casm : casm_output, sierra : sierra_output }
178161}
179162
180- /// Compile Cairo1 Contract into their Sierra version using the compiler version set in the
181- /// Cargo.toml
182- pub fn starknet_compile ( path : String , base_compile_args : & mut [ String ] ) -> Vec < u8 > {
183- // Cairo -> Sierra.
184- let mut starknet_compile_commmand = Command :: new ( "cargo" ) ;
185- starknet_compile_commmand. args ( base_compile_args. to_owned ( ) ) ;
186- starknet_compile_commmand. args ( [
187- "starknet-compile" ,
188- "--" ,
189- "--single-file" ,
190- & path,
191- "--allowed-libfuncs-list-name" ,
192- "all" ,
193- ] ) ;
163+ /// Compile Cairo1 Contract into their Sierra version using the given compiler version.
164+ /// Assumes the relevant compiler version is already downloaded.
165+ pub fn starknet_compile ( path : String , version : & String ) -> Vec < u8 > {
166+ let mut starknet_compile_commmand = Command :: new ( starknet_compile_binary_path ( version) ) ;
167+ starknet_compile_commmand. args ( [ "--single-file" , & path, "--allowed-libfuncs-list-name" , "all" ] ) ;
194168 let sierra_output = run_and_verify_output ( & mut starknet_compile_commmand) ;
195169
196170 sierra_output. stdout
197171}
198172
199- /// Compile Sierra code into CASM.
200- fn starknet_sierra_compile ( path : String , base_compile_args : & mut Vec < String > ) -> Vec < u8 > {
201- let mut sierra_compile_command = Command :: new ( "cargo" ) ;
202- sierra_compile_command. args ( base_compile_args) ;
203- sierra_compile_command. args ( [
204- "starknet-sierra-compile" ,
205- path. as_str ( ) ,
206- "--allowed-libfuncs-list-name" ,
207- "all" ,
208- ] ) ;
173+ /// Compile Sierra code into CASM using the given compiler version.
174+ /// Assumes the relevant compiler version is already downloaded.
175+ fn starknet_sierra_compile ( path : String , version : & String ) -> Vec < u8 > {
176+ let mut sierra_compile_command = Command :: new ( starknet_sierra_compile_binary_path ( version) ) ;
177+ sierra_compile_command. args ( [ path. as_str ( ) , "--allowed-libfuncs-list-name" , "all" ] ) ;
209178 let casm_output = run_and_verify_output ( & mut sierra_compile_command) ;
210179 casm_output. stdout
211180}
@@ -254,36 +223,3 @@ fn get_tag_and_repo_file_path(git_tag_override: Option<String>) -> (String, Path
254223
255224 ( tag, cairo_repo_path)
256225}
257-
258- pub fn prepare_group_tag_compiler_deps ( tag_and_toolchain : & TagAndToolchain ) {
259- let ( optional_tag, optional_toolchain) = tag_and_toolchain;
260-
261- // Checkout the required version in the compiler repo.
262- let ( tag, cairo_repo_path) = get_tag_and_repo_file_path ( optional_tag. clone ( ) ) ;
263- run_and_verify_output ( Command :: new ( "git" ) . args ( [
264- "-C" ,
265- cairo_repo_path. to_str ( ) . unwrap ( ) ,
266- "checkout" ,
267- & tag,
268- ] ) ) ;
269-
270- // Install the toolchain, if specified.
271- if let Some ( toolchain) = optional_toolchain {
272- run_and_verify_output (
273- Command :: new ( "rustup" ) . args ( [ "install" , & format ! ( "nightly-{toolchain}" ) ] ) ,
274- ) ;
275- }
276- }
277-
278- fn verify_cairo1_compiler_deps ( git_tag_override : Option < String > ) {
279- let ( tag, cairo_repo_path) = get_tag_and_repo_file_path ( git_tag_override) ;
280-
281- // Verify that the checked out tag is as expected.
282- run_and_verify_output ( Command :: new ( "git" ) . args ( [
283- "-C" ,
284- cairo_repo_path. to_str ( ) . unwrap ( ) ,
285- "rev-parse" ,
286- "--verify" ,
287- & tag,
288- ] ) ) ;
289- }
0 commit comments