@@ -45,24 +45,24 @@ fn starknet_sierra_compile_binary_path(version: &String) -> PathBuf {
4545
4646/// Downloads the cairo package to the local directory.
4747/// Creates the directory if it does not exist.
48- fn download_cairo_package ( version : & String ) {
48+ async fn download_cairo_package ( version : & String ) {
4949 let directory = cairo1_package_dir ( version) ;
5050 info ! ( "Downloading Cairo package to {directory:?}." ) ;
5151 std:: fs:: create_dir_all ( & directory) . unwrap ( ) ;
5252
5353 // Download the artifact.
54- let client = reqwest:: blocking :: Client :: new ( ) ;
54+ let client = reqwest:: Client :: new ( ) ;
5555 let filename = "release-x86_64-unknown-linux-musl.tar.gz" ;
5656 let package_url =
5757 format ! ( "https://github.com/starkware-libs/cairo/releases/download/v{version}/{filename}" ) ;
58- let response = client. get ( package_url) . send ( ) . unwrap ( ) ;
58+ let response = client. get ( package_url) . send ( ) . await . unwrap ( ) ;
5959 assert ! ( response. status( ) . is_success( ) , "Failed to download the package: {response:?}." ) ;
6060
6161 // Write the response to a file.
6262 info ! ( "Writing and extracting package." ) ;
6363 let tar_gz_path = Path :: new ( & directory) . join ( filename) ;
6464 let mut file = std:: fs:: File :: create ( & tar_gz_path) . unwrap ( ) ;
65- file. write_all ( & response. bytes ( ) . unwrap ( ) ) . unwrap ( ) ;
65+ file. write_all ( & response. bytes ( ) . await . unwrap ( ) ) . unwrap ( ) ;
6666
6767 // Extract the tar.gz file.
6868 let tar_gz = std:: fs:: File :: open ( & tar_gz_path) . unwrap ( ) ;
@@ -73,15 +73,19 @@ fn download_cairo_package(version: &String) {
7373 info ! ( "Done." ) ;
7474}
7575
76- /// Verifies that the Cairo1 package (of the given version) is available.
77- pub fn verify_cairo1_package ( version : & String , download_if_missing : bool ) {
76+ fn cairo1_package_exists ( version : & String ) -> bool {
7877 let cairo_compiler_path = starknet_compile_binary_path ( version) ;
7978 let sierra_compiler_path = starknet_sierra_compile_binary_path ( version) ;
80- if download_if_missing && ( !cairo_compiler_path. exists ( ) || !sierra_compiler_path. exists ( ) ) {
81- download_cairo_package ( version) ;
79+ cairo_compiler_path. exists ( ) && sierra_compiler_path. exists ( )
80+ }
81+
82+ /// Verifies that the Cairo1 package (of the given version) is available.
83+ /// Attempts to download it if not.
84+ pub async fn verify_cairo1_package ( version : & String ) {
85+ if !cairo1_package_exists ( version) {
86+ download_cairo_package ( version) . await ;
8287 }
83- assert ! ( cairo_compiler_path. exists( ) , "Cairo compiler not found at {cairo_compiler_path:?}" ) ;
84- assert ! ( sierra_compiler_path. exists( ) , "Sierra compiler not found at {sierra_compiler_path:?}" ) ;
88+ assert ! ( cairo1_package_exists( version) ) ;
8589}
8690
8791/// Runs a command. If it has succeeded, it returns the command's output; otherwise, it panics with
@@ -118,8 +122,7 @@ pub fn cairo0_compile(
118122
119123/// Compiles a Cairo1 program using the compiler version set in the Cargo.toml.
120124pub fn cairo1_compile ( path : String , version : String ) -> CompilationArtifacts {
121- let download_if_missing = false ;
122- verify_cairo1_package ( & version, download_if_missing) ;
125+ assert ! ( cairo1_package_exists( & version) ) ;
123126
124127 let sierra_output = starknet_compile ( path, & version) ;
125128
0 commit comments