Skip to content

Commit 091fd64

Browse files
chore(blockifier_test_utils): implement download_cairo_package
1 parent 9561130 commit 091fd64

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

@@ -45,6 +47,32 @@ fn local_cairo1_compiler_repo_path() -> PathBuf {
4547
)
4648
}
4749

50+
/// Path to local compiler package directory, of the specified version.
51+
fn cairo1_package_dir(version: &String) -> PathBuf {
52+
project_path().unwrap().join(format!("target/bin/cairo_package__{version}"))
53+
}
54+
55+
/// Downloads the cairo package to the local directory.
56+
/// Creates the directory if it does not exist.
57+
#[allow(dead_code)]
58+
async fn download_cairo_package(version: &String) {
59+
let directory = cairo1_package_dir(version);
60+
info!("Downloading Cairo package to {directory:?}.");
61+
std::fs::create_dir_all(&directory).unwrap();
62+
63+
// Download the artifact.
64+
let client = reqwest::Client::new();
65+
let filename = "release-x86_64-unknown-linux-musl.tar.gz";
66+
let package_url =
67+
format!("https://github.com/starkware-libs/cairo/releases/download/v{version}/{filename}");
68+
let response = client.get(package_url).send().await.unwrap();
69+
assert!(response.status().is_success(), "Failed to download the package: {response:?}.");
70+
let tar_package_bytes: &[u8] = &response.bytes().await.unwrap();
71+
info!("Extracting and writing package.");
72+
tar::Archive::new(flate2::read::GzDecoder::new(tar_package_bytes)).unpack(&directory).unwrap();
73+
info!("Done.");
74+
}
75+
4876
/// Runs a command. If it has succeeded, it returns the command's output; otherwise, it panics with
4977
/// stderr output.
5078
fn run_and_verify_output(command: &mut Command) -> Output {

0 commit comments

Comments
 (0)