|
1 | 1 | use std::io::Write; |
2 | 2 | use std::path::{Path, PathBuf}; |
3 | | -use std::process::{Command, Output}; |
| 3 | +use std::process::{Command, Output, Stdio}; |
4 | 4 | use std::{env, fs}; |
5 | 5 |
|
6 | 6 | use apollo_infra_utils::cairo_compiler_version::cairo1_compiler_version; |
7 | 7 | use apollo_infra_utils::compile_time_cargo_manifest_dir; |
| 8 | +use apollo_infra_utils::path::project_path; |
8 | 9 | use tempfile::NamedTempFile; |
| 10 | +use tracing::info; |
9 | 11 |
|
10 | 12 | use crate::contracts::TagAndToolchain; |
11 | 13 |
|
@@ -35,6 +37,39 @@ fn local_cairo1_compiler_repo_path() -> PathBuf { |
35 | 37 | ) |
36 | 38 | } |
37 | 39 |
|
| 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 filename = "release-x86_64-unknown-linux-musl.tar.gz"; |
| 55 | + let package_url = |
| 56 | + format!("https://github.com/starkware-libs/cairo/releases/download/v{version}/{filename}"); |
| 57 | + let curl_result = run_and_verify_output(Command::new("curl").args(["-L", &package_url])); |
| 58 | + let mut tar_command = Command::new("tar") |
| 59 | + .args(["-xz", "-C", directory.to_str().unwrap()]) |
| 60 | + .stdin(Stdio::piped()) |
| 61 | + .spawn() |
| 62 | + .unwrap(); |
| 63 | + let tar_command_stdin = tar_command.stdin.as_mut().unwrap(); |
| 64 | + tar_command_stdin.write_all(&curl_result.stdout).unwrap(); |
| 65 | + let output = tar_command.wait_with_output().unwrap(); |
| 66 | + if !output.status.success() { |
| 67 | + let stderr_output = String::from_utf8(output.stderr).unwrap(); |
| 68 | + panic!("{stderr_output}"); |
| 69 | + } |
| 70 | + info!("Done."); |
| 71 | +} |
| 72 | + |
38 | 73 | /// Runs a command. If it has succeeded, it returns the command's output; otherwise, it panics with |
39 | 74 | /// stderr output. |
40 | 75 | fn run_and_verify_output(command: &mut Command) -> Output { |
|
0 commit comments