@@ -136,36 +136,6 @@ pub fn cairo1_compile(
136136 cargo_nightly_arg : Option < String > ,
137137) -> CompilationArtifacts {
138138 let mut base_compile_args = vec ! [ ] ;
139-
140- let sierra_output =
141- starknet_compile ( path, git_tag_override, cargo_nightly_arg, & mut base_compile_args) ;
142-
143- let mut temp_file = NamedTempFile :: new ( ) . unwrap ( ) ;
144- temp_file. write_all ( & sierra_output) . unwrap ( ) ;
145- let temp_path_str = temp_file. into_temp_path ( ) ;
146-
147- // Sierra -> CASM.
148- let mut sierra_compile_command = Command :: new ( "cargo" ) ;
149- sierra_compile_command. args ( base_compile_args) ;
150- sierra_compile_command. args ( [
151- "starknet-sierra-compile" ,
152- temp_path_str. to_str ( ) . unwrap ( ) ,
153- "--allowed-libfuncs-list-name" ,
154- "all" ,
155- ] ) ;
156- let casm_output = run_and_verify_output ( & mut sierra_compile_command) ;
157-
158- CompilationArtifacts :: Cairo1 { casm : casm_output. stdout , sierra : sierra_output }
159- }
160-
161- /// Compile Cairo1 Contract into their Sierra version using the compiler version set in the
162- /// Cargo.toml
163- pub fn starknet_compile (
164- path : String ,
165- git_tag_override : Option < String > ,
166- cargo_nightly_arg : Option < String > ,
167- base_compile_args : & mut Vec < String > ,
168- ) -> Vec < u8 > {
169139 verify_cairo1_compiler_deps ( git_tag_override) ;
170140
171141 let cairo1_compiler_path = local_cairo1_compiler_repo_path ( ) ;
@@ -181,9 +151,27 @@ pub fn starknet_compile(
181151 base_compile_args. insert ( 0 , format ! ( "+nightly-{nightly_version}" ) ) ;
182152 }
183153
154+ let sierra_output = starknet_compile ( path, & mut base_compile_args) ;
155+
156+ let mut temp_file = NamedTempFile :: new ( ) . unwrap ( ) ;
157+ temp_file. write_all ( & sierra_output) . unwrap ( ) ;
158+ let temp_path_str = temp_file. into_temp_path ( ) ;
159+
160+ // Sierra -> CASM.
161+ let casm_output = starknet_sierra_compile (
162+ temp_path_str. to_str ( ) . unwrap ( ) . to_string ( ) ,
163+ & mut base_compile_args,
164+ ) ;
165+
166+ CompilationArtifacts :: Cairo1 { casm : casm_output, sierra : sierra_output }
167+ }
168+
169+ /// Compile Cairo1 Contract into their Sierra version using the compiler version set in the
170+ /// Cargo.toml
171+ pub fn starknet_compile ( path : String , base_compile_args : & mut [ String ] ) -> Vec < u8 > {
184172 // Cairo -> Sierra.
185173 let mut starknet_compile_commmand = Command :: new ( "cargo" ) ;
186- starknet_compile_commmand. args ( base_compile_args. clone ( ) ) ;
174+ starknet_compile_commmand. args ( base_compile_args. to_owned ( ) ) ;
187175 starknet_compile_commmand. args ( [
188176 "starknet-compile" ,
189177 "--" ,
@@ -197,6 +185,20 @@ pub fn starknet_compile(
197185 sierra_output. stdout
198186}
199187
188+ /// Compile Sierra code into CASM.
189+ fn starknet_sierra_compile ( path : String , base_compile_args : & mut Vec < String > ) -> Vec < u8 > {
190+ let mut sierra_compile_command = Command :: new ( "cargo" ) ;
191+ sierra_compile_command. args ( base_compile_args) ;
192+ sierra_compile_command. args ( [
193+ "starknet-sierra-compile" ,
194+ & path,
195+ "--allowed-libfuncs-list-name" ,
196+ "all" ,
197+ ] ) ;
198+ let casm_output = run_and_verify_output ( & mut sierra_compile_command) ;
199+ casm_output. stdout
200+ }
201+
200202/// Verifies that the required dependencies are available before compiling; panics if unavailable.
201203fn verify_cairo0_compiler_deps ( ) {
202204 // Python compiler. Verify correct version.
0 commit comments