@@ -5,7 +5,9 @@ use std::{env, fs};
55
66use apollo_infra_utils:: cairo_compiler_version:: cairo1_compiler_version;
77use apollo_infra_utils:: compile_time_cargo_manifest_dir;
8+ use apollo_infra_utils:: path:: project_path;
89use tempfile:: NamedTempFile ;
10+ use tracing:: info;
911
1012use crate :: contracts:: TagAndToolchain ;
1113
@@ -35,6 +37,32 @@ fn local_cairo1_compiler_repo_path() -> PathBuf {
3537 )
3638}
3739
40+ /// Path to local compiler package directory, of the specified version.
41+ fn cairo1_package_dir ( version : & String ) -> PathBuf {
42+ project_path ( ) . unwrap ( ) . join ( format ! ( "target/bin/cairo_package__{version}" ) )
43+ }
44+
45+ /// Downloads the cairo package to the local directory.
46+ /// Creates the directory if it does not exist.
47+ #[ allow( dead_code) ]
48+ async fn download_cairo_package ( version : & String ) {
49+ let directory = cairo1_package_dir ( version) ;
50+ info ! ( "Downloading Cairo package to {directory:?}." ) ;
51+ std:: fs:: create_dir_all ( & directory) . unwrap ( ) ;
52+
53+ // Download the artifact.
54+ let client = reqwest:: Client :: new ( ) ;
55+ let filename = "release-x86_64-unknown-linux-musl.tar.gz" ;
56+ let package_url =
57+ format ! ( "https://github.com/starkware-libs/cairo/releases/download/v{version}/{filename}" ) ;
58+ let response = client. get ( package_url) . send ( ) . await . unwrap ( ) ;
59+ assert ! ( response. status( ) . is_success( ) , "Failed to download the package: {response:?}." ) ;
60+ let tar_package_bytes: & [ u8 ] = & response. bytes ( ) . await . unwrap ( ) ;
61+ info ! ( "Extracting and writing package." ) ;
62+ tar:: Archive :: new ( flate2:: read:: GzDecoder :: new ( tar_package_bytes) ) . unpack ( & directory) . unwrap ( ) ;
63+ info ! ( "Done." ) ;
64+ }
65+
3866/// Runs a command. If it has succeeded, it returns the command's output; otherwise, it panics with
3967/// stderr output.
4068fn run_and_verify_output ( command : & mut Command ) -> Output {
0 commit comments