1pub mod commands;
2
3use anyhow::{Context, Result};
4use reqwest::Client;
5use std::process::{Command, Stdio};
6
7pub const RUSTUP_TOOLCHAIN_NAME: &str = "succinct";
8
9pub const LATEST_SUPPORTED_TOOLCHAIN_VERSION_TAG: &str = "succinct-1.91.1";
14
15pub const SP1_VERSION_MESSAGE: &str =
16 concat!("sp1", " (", env!("VERGEN_GIT_SHA"), " ", env!("VERGEN_BUILD_TIMESTAMP"), ")");
17
18trait CommandExecutor {
19 fn run(&mut self) -> Result<()>;
20}
21
22impl CommandExecutor for Command {
23 fn run(&mut self) -> Result<()> {
24 self.stderr(Stdio::inherit())
25 .stdout(Stdio::inherit())
26 .stdin(Stdio::inherit())
27 .output()
28 .with_context(|| format!("while executing `{:?}`", &self))
29 .map(|_| ())
30 }
31}
32
33pub async fn url_exists(client: &Client, url: &str) -> bool {
34 let res = client.head(url).send().await;
35 res.is_ok()
36}
37
38#[allow(unreachable_code)]
39pub fn is_supported_target() -> bool {
40 #[cfg(all(target_arch = "x86_64", target_os = "linux"))]
41 return true;
42
43 #[cfg(all(target_arch = "aarch64", target_os = "linux"))]
44 return true;
45
46 #[cfg(all(target_arch = "x86_64", target_os = "macos"))]
47 return true;
48
49 #[cfg(all(target_arch = "aarch64", target_os = "macos"))]
50 return true;
51
52 false
53}
54
55pub fn get_target() -> String {
56 let mut target: target_lexicon::Triple = target_lexicon::HOST;
57
58 if target.environment == target_lexicon::Environment::Musl {
60 target.environment = target_lexicon::Environment::Gnu;
61 }
62
63 target.to_string()
64}
65
66pub async fn get_toolchain_download_url(client: &Client, target: String) -> String {
67 let all_releases = client
68 .get("https://api.github.com/repos/succinctlabs/rust/releases")
69 .send()
70 .await
71 .unwrap()
72 .json::<serde_json::Value>()
73 .await
74 .unwrap();
75
76 let _ = all_releases
78 .as_array()
79 .expect("Failed to fetch releases list")
80 .iter()
81 .find(|release| {
82 release["tag_name"].as_str().unwrap() == LATEST_SUPPORTED_TOOLCHAIN_VERSION_TAG
83 })
84 .unwrap_or_else(|| {
85 panic!(
86 "No release found for the expected tag: {LATEST_SUPPORTED_TOOLCHAIN_VERSION_TAG}",
87 );
88 });
89
90 let url = format!(
91 "https://github.com/succinctlabs/rust/releases/download/{LATEST_SUPPORTED_TOOLCHAIN_VERSION_TAG}/rust-toolchain-{target}.tar.gz"
92 );
93
94 url
95}