@@ -10,8 +10,6 @@ use apollo_infra_utils::path::{project_path, resolve_project_relative_path};
1010use tempfile:: NamedTempFile ;
1111use tracing:: info;
1212
13- use crate :: contracts:: TagAndToolchain ;
14-
1513static CAIRO0_PIP_REQUIREMENTS_FILE : LazyLock < PathBuf > =
1614 LazyLock :: new ( || resolve_project_relative_path ( "scripts/requirements.txt" ) . unwrap ( ) ) ;
1715const CAIRO1_REPO_RELATIVE_PATH_OVERRIDE_ENV_VAR : & str = "CAIRO1_REPO_RELATIVE_PATH" ;
@@ -89,8 +87,7 @@ fn cairo1_package_exists(version: &String) -> bool {
8987
9088/// Verifies that the Cairo1 package (of the given version) is available.
9189/// Attempts to download it if not.
92- #[ allow( dead_code) ]
93- async fn verify_cairo1_package ( version : & String ) {
90+ pub async fn verify_cairo1_package ( version : & String ) {
9491 if !cairo1_package_exists ( version) {
9592 download_cairo_package ( version) . await ;
9693 }
@@ -133,66 +130,40 @@ pub fn cairo0_compile(
133130pub fn cairo1_compile (
134131 path : String ,
135132 git_tag_override : Option < String > ,
136- cargo_nightly_arg : Option < String > ,
133+ _cargo_nightly_arg : Option < String > ,
137134) -> CompilationArtifacts {
138- let mut base_compile_args = vec ! [ ] ;
139- verify_cairo1_compiler_deps ( git_tag_override) ;
140-
141- let cairo1_compiler_path = local_cairo1_compiler_repo_path ( ) ;
142-
143- // Command args common to both compilation phases.
144- base_compile_args. extend ( vec ! [
145- "run" . into( ) ,
146- format!( "--manifest-path={}/Cargo.toml" , cairo1_compiler_path. to_string_lossy( ) ) ,
147- "--bin" . into( ) ,
148- ] ) ;
149- // Add additional cargo arg if provided. Should be first arg (base command is `cargo`).
150- if let Some ( nightly_version) = cargo_nightly_arg {
151- base_compile_args. insert ( 0 , format ! ( "+nightly-{nightly_version}" ) ) ;
152- }
135+ let ( tag, _cairo_repo_path) = get_tag_and_repo_file_path ( git_tag_override) ;
136+ let version = tag. strip_prefix ( "v" ) . unwrap ( ) . to_string ( ) ;
137+ assert ! ( cairo1_package_exists( & version) ) ;
153138
154- let sierra_output = starknet_compile ( path, & base_compile_args ) ;
139+ let sierra_output = starknet_compile ( path, & version ) ;
155140
156141 let mut temp_file = NamedTempFile :: new ( ) . unwrap ( ) ;
157142 temp_file. write_all ( & sierra_output) . unwrap ( ) ;
158143 let temp_path_str = temp_file. into_temp_path ( ) ;
159144
160145 // Sierra -> CASM.
161146 let casm_output =
162- starknet_sierra_compile ( temp_path_str. to_str ( ) . unwrap ( ) . to_string ( ) , & base_compile_args ) ;
147+ starknet_sierra_compile ( temp_path_str. to_str ( ) . unwrap ( ) . to_string ( ) , & version ) ;
163148
164149 CompilationArtifacts :: Cairo1 { casm : casm_output, sierra : sierra_output }
165150}
166151
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 > {
170- // Cairo -> Sierra.
171- let mut starknet_compile_commmand = Command :: new ( "cargo" ) ;
172- starknet_compile_commmand. args ( base_compile_args. to_owned ( ) ) ;
173- starknet_compile_commmand. args ( [
174- "starknet-compile" ,
175- "--" ,
176- "--single-file" ,
177- & path,
178- "--allowed-libfuncs-list-name" ,
179- "all" ,
180- ] ) ;
152+ /// Compiles Cairo1 Contract into their Sierra version using the given compiler version.
153+ /// Assumes the relevant compiler version is already downloaded.
154+ pub fn starknet_compile ( path : String , version : & String ) -> Vec < u8 > {
155+ let mut starknet_compile_commmand = Command :: new ( starknet_compile_binary_path ( version) ) ;
156+ starknet_compile_commmand. args ( [ "--single-file" , & path, "--allowed-libfuncs-list-name" , "all" ] ) ;
181157 let sierra_output = run_and_verify_output ( & mut starknet_compile_commmand) ;
182158
183159 sierra_output. stdout
184160}
185161
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- ] ) ;
162+ /// Compiles Sierra code into CASM using the given compiler version.
163+ /// Assumes the relevant compiler version is already downloaded.
164+ fn starknet_sierra_compile ( path : String , version : & String ) -> Vec < u8 > {
165+ let mut sierra_compile_command = Command :: new ( starknet_sierra_compile_binary_path ( version) ) ;
166+ sierra_compile_command. args ( [ & path, "--allowed-libfuncs-list-name" , "all" ] ) ;
196167 let casm_output = run_and_verify_output ( & mut sierra_compile_command) ;
197168 casm_output. stdout
198169}
@@ -245,36 +216,3 @@ fn get_tag_and_repo_file_path(git_tag_override: Option<String>) -> (String, Path
245216
246217 ( tag, cairo_repo_path)
247218}
248-
249- pub fn prepare_group_tag_compiler_deps ( tag_and_toolchain : & TagAndToolchain ) {
250- let ( optional_tag, optional_toolchain) = tag_and_toolchain;
251-
252- // Checkout the required version in the compiler repo.
253- let ( tag, cairo_repo_path) = get_tag_and_repo_file_path ( optional_tag. clone ( ) ) ;
254- run_and_verify_output ( Command :: new ( "git" ) . args ( [
255- "-C" ,
256- cairo_repo_path. to_str ( ) . unwrap ( ) ,
257- "checkout" ,
258- & tag,
259- ] ) ) ;
260-
261- // Install the toolchain, if specified.
262- if let Some ( toolchain) = optional_toolchain {
263- run_and_verify_output (
264- Command :: new ( "rustup" ) . args ( [ "install" , & format ! ( "nightly-{toolchain}" ) ] ) ,
265- ) ;
266- }
267- }
268-
269- fn verify_cairo1_compiler_deps ( git_tag_override : Option < String > ) {
270- let ( tag, cairo_repo_path) = get_tag_and_repo_file_path ( git_tag_override) ;
271-
272- // Verify that the checked out tag is as expected.
273- run_and_verify_output ( Command :: new ( "git" ) . args ( [
274- "-C" ,
275- cairo_repo_path. to_str ( ) . unwrap ( ) ,
276- "rev-parse" ,
277- "--verify" ,
278- & tag,
279- ] ) ) ;
280- }
0 commit comments