Skip to main content

sp1_cli/
lib.rs

1pub mod commands;
2
3use reqwest::Client;
4
5pub const RUSTUP_TOOLCHAIN_NAME: &str = "succinct";
6
7/// The latest version (github tag) of the toolchain that is supported by our build system.
8pub const LATEST_SUPPORTED_TOOLCHAIN_VERSION_TAG: &str = "succinct-1.93.0-64bit";
9
10pub const SP1_VERSION_MESSAGE: &str =
11    concat!("sp1", " (", env!("VERGEN_GIT_SHA"), " ", env!("VERGEN_BUILD_TIMESTAMP"), ")");
12
13pub async fn url_exists(client: &Client, url: &str) -> bool {
14    let res = client.head(url).send().await;
15    res.is_ok()
16}
17
18#[allow(unreachable_code)]
19pub fn is_supported_target() -> bool {
20    #[cfg(all(target_arch = "x86_64", target_os = "linux"))]
21    return true;
22
23    #[cfg(all(target_arch = "aarch64", target_os = "linux"))]
24    return true;
25
26    #[cfg(all(target_arch = "x86_64", target_os = "macos"))]
27    return true;
28
29    #[cfg(all(target_arch = "aarch64", target_os = "macos"))]
30    return true;
31
32    false
33}
34
35pub fn get_target() -> String {
36    let mut target: target_lexicon::Triple = target_lexicon::HOST;
37
38    // We don't want to operate on the musl toolchain, even if the CLI was compiled with musl
39    if target.environment == target_lexicon::Environment::Musl {
40        target.environment = target_lexicon::Environment::Gnu;
41    }
42
43    target.to_string()
44}
45
46#[allow(clippy::uninlined_format_args)]
47pub async fn get_toolchain_download_url(client: &Client, target: String) -> String {
48    let all_releases = client
49        .get("https://api.github.com/repos/succinctlabs/rust/releases")
50        .send()
51        .await
52        .unwrap()
53        .json::<serde_json::Value>()
54        .await
55        .unwrap();
56
57    // Check if the release exists.
58    let _ = all_releases
59        .as_array()
60        .expect("Failed to fetch releases list")
61        .iter()
62        .find(|release| {
63            release["tag_name"].as_str().unwrap() == LATEST_SUPPORTED_TOOLCHAIN_VERSION_TAG
64        })
65        .unwrap_or_else(|| {
66            panic!(
67                "No release found for the expected tag: {LATEST_SUPPORTED_TOOLCHAIN_VERSION_TAG}",
68            );
69        });
70
71    let url = format!(
72        "https://github.com/succinctlabs/rust/releases/download/{LATEST_SUPPORTED_TOOLCHAIN_VERSION_TAG}/rust-toolchain-{target}.tar.gz"
73    );
74
75    url
76}