Skip to content

Commit 08f31d4

Browse files
chore(blockifier_test_utils): implement download_cairo_package
1 parent 1037625 commit 08f31d4

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/blockifier_test_utils/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ cairo_native = []
1212
[dependencies]
1313
apollo_infra_utils = { workspace = true, features = ["testing"] }
1414
cairo-lang-starknet-classes.workspace = true
15+
flate2.workspace = true
1516
itertools.workspace = true
1617
pretty_assertions.workspace = true
18+
reqwest.workspace = true
1719
rstest.workspace = true
1820
serde_json = { workspace = true, features = ["arbitrary_precision"] }
1921
starknet-types-core.workspace = true
2022
starknet_api = { workspace = true, features = ["testing"] }
2123
strum.workspace = true
2224
strum_macros.workspace = true
25+
tar.workspace = true
2326
tempfile.workspace = true
2427
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
2528
tracing.workspace = true

crates/blockifier_test_utils/src/cairo_compile.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use std::{env, fs};
55

66
use apollo_infra_utils::cairo_compiler_version::cairo1_compiler_version;
77
use apollo_infra_utils::compile_time_cargo_manifest_dir;
8+
use apollo_infra_utils::path::project_path;
89
use tempfile::NamedTempFile;
10+
use tracing::info;
911

1012
use 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.
4068
fn run_and_verify_output(command: &mut Command) -> Output {

0 commit comments

Comments
 (0)