@@ -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" ;
@@ -90,8 +88,7 @@ fn cairo1_package_exists(version: &String) -> bool {
9088
9189/// Verifies that the Cairo1 package (of the given version) is available.
9290/// Attempts to download it if not.
93- #[ allow( dead_code) ]
94- async fn verify_cairo1_package ( version : & String ) {
91+ pub async fn verify_cairo1_package ( version : & String ) {
9592 if !cairo1_package_exists ( version) {
9693 download_cairo_package ( version) . await ;
9794 }
@@ -134,68 +131,40 @@ pub fn cairo0_compile(
134131pub fn cairo1_compile (
135132 path : String ,
136133 git_tag_override : Option < String > ,
137- cargo_nightly_arg : Option < String > ,
134+ _cargo_nightly_arg : Option < String > ,
138135) -> CompilationArtifacts {
139- let mut base_compile_args = vec ! [ ] ;
140- verify_cairo1_compiler_deps ( git_tag_override) ;
141-
142- let cairo1_compiler_path = local_cairo1_compiler_repo_path ( ) ;
143-
144- // Command args common to both compilation phases.
145- base_compile_args. extend ( vec ! [
146- "run" . into( ) ,
147- format!( "--manifest-path={}/Cargo.toml" , cairo1_compiler_path. to_string_lossy( ) ) ,
148- "--bin" . into( ) ,
149- ] ) ;
150- // Add additional cargo arg if provided. Should be first arg (base command is `cargo`).
151- if let Some ( nightly_version) = cargo_nightly_arg {
152- base_compile_args. insert ( 0 , format ! ( "+nightly-{nightly_version}" ) ) ;
153- }
136+ let ( tag, _cairo_repo_path) = get_tag_and_repo_file_path ( git_tag_override) ;
137+ let version = tag. strip_prefix ( "v" ) . unwrap ( ) . to_string ( ) ;
138+ assert ! ( cairo1_package_exists( & version) ) ;
154139
155- let sierra_output = starknet_compile ( path, & mut base_compile_args ) ;
140+ let sierra_output = starknet_compile ( path, & version ) ;
156141
157142 let mut temp_file = NamedTempFile :: new ( ) . unwrap ( ) ;
158143 temp_file. write_all ( & sierra_output) . unwrap ( ) ;
159144 let temp_path_str = temp_file. into_temp_path ( ) ;
160145
161146 // Sierra -> CASM.
162- let casm_output = starknet_sierra_compile (
163- temp_path_str. to_str ( ) . unwrap ( ) . to_string ( ) ,
164- & mut base_compile_args,
165- ) ;
147+ let casm_output =
148+ starknet_sierra_compile ( temp_path_str. to_str ( ) . unwrap ( ) . to_string ( ) , & version) ;
166149
167150 CompilationArtifacts :: Cairo1 { casm : casm_output, sierra : sierra_output }
168151}
169152
170- /// Compile Cairo1 Contract into their Sierra version using the compiler version set in the
171- /// Cargo.toml
172- pub fn starknet_compile ( path : String , base_compile_args : & mut [ String ] ) -> Vec < u8 > {
173- // Cairo -> Sierra.
174- let mut starknet_compile_commmand = Command :: new ( "cargo" ) ;
175- starknet_compile_commmand. args ( base_compile_args. to_owned ( ) ) ;
176- starknet_compile_commmand. args ( [
177- "starknet-compile" ,
178- "--" ,
179- "--single-file" ,
180- & path,
181- "--allowed-libfuncs-list-name" ,
182- "all" ,
183- ] ) ;
153+ /// Compile Cairo1 Contract into their Sierra version using the given compiler version.
154+ /// Assumes the relevant compiler version is already downloaded.
155+ pub fn starknet_compile ( path : String , version : & String ) -> Vec < u8 > {
156+ let mut starknet_compile_commmand = Command :: new ( starknet_compile_binary_path ( version) ) ;
157+ starknet_compile_commmand. args ( [ "--single-file" , & path, "--allowed-libfuncs-list-name" , "all" ] ) ;
184158 let sierra_output = run_and_verify_output ( & mut starknet_compile_commmand) ;
185159
186160 sierra_output. stdout
187161}
188162
189- /// Compile Sierra code into CASM.
190- fn starknet_sierra_compile ( path : String , base_compile_args : & mut Vec < String > ) -> Vec < u8 > {
191- let mut sierra_compile_command = Command :: new ( "cargo" ) ;
192- sierra_compile_command. args ( base_compile_args) ;
193- sierra_compile_command. args ( [
194- "starknet-sierra-compile" ,
195- path. as_str ( ) ,
196- "--allowed-libfuncs-list-name" ,
197- "all" ,
198- ] ) ;
163+ /// Compile Sierra code into CASM using the given compiler version.
164+ /// Assumes the relevant compiler version is already downloaded.
165+ fn starknet_sierra_compile ( path : String , version : & String ) -> Vec < u8 > {
166+ let mut sierra_compile_command = Command :: new ( starknet_sierra_compile_binary_path ( version) ) ;
167+ sierra_compile_command. args ( [ path. as_str ( ) , "--allowed-libfuncs-list-name" , "all" ] ) ;
199168 let casm_output = run_and_verify_output ( & mut sierra_compile_command) ;
200169 casm_output. stdout
201170}
@@ -244,36 +213,3 @@ fn get_tag_and_repo_file_path(git_tag_override: Option<String>) -> (String, Path
244213
245214 ( tag, cairo_repo_path)
246215}
247-
248- pub fn prepare_group_tag_compiler_deps ( tag_and_toolchain : & TagAndToolchain ) {
249- let ( optional_tag, optional_toolchain) = tag_and_toolchain;
250-
251- // Checkout the required version in the compiler repo.
252- let ( tag, cairo_repo_path) = get_tag_and_repo_file_path ( optional_tag. clone ( ) ) ;
253- run_and_verify_output ( Command :: new ( "git" ) . args ( [
254- "-C" ,
255- cairo_repo_path. to_str ( ) . unwrap ( ) ,
256- "checkout" ,
257- & tag,
258- ] ) ) ;
259-
260- // Install the toolchain, if specified.
261- if let Some ( toolchain) = optional_toolchain {
262- run_and_verify_output (
263- Command :: new ( "rustup" ) . args ( [ "install" , & format ! ( "nightly-{toolchain}" ) ] ) ,
264- ) ;
265- }
266- }
267-
268- fn verify_cairo1_compiler_deps ( git_tag_override : Option < String > ) {
269- let ( tag, cairo_repo_path) = get_tag_and_repo_file_path ( git_tag_override) ;
270-
271- // Verify that the checked out tag is as expected.
272- run_and_verify_output ( Command :: new ( "git" ) . args ( [
273- "-C" ,
274- cairo_repo_path. to_str ( ) . unwrap ( ) ,
275- "rev-parse" ,
276- "--verify" ,
277- & tag,
278- ] ) ) ;
279- }
0 commit comments