Skip to content

Commit

Permalink
fix: more verbose installs and clean up downloaded archive
Browse files Browse the repository at this point in the history
  • Loading branch information
sagar-a16z committed Oct 22, 2024
1 parent 8148fd4 commit 45dd06a
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions jolt-core/src/host/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ pub fn install_toolchain() -> Result<()> {
download_toolchain(&client, &toolchain_url)
}))?;
unpack_toolchain()?;
remove_archive()?;
link_toolchain()?;
write_tag_file()?;
println!(
"\"riscv32im-jolt-zkvm-elf\" toolchain installed successfully at {:?}",
jolt_dir()
);
}
Ok(())
}
Expand All @@ -39,7 +44,6 @@ pub fn install_no_std_toolchain() -> Result<()> {
std::process::Command::new("rustup")
.args(["target", "add", "riscv32im-unknown-none-elf"])
.output()?;

Ok(())
}

Expand Down Expand Up @@ -114,7 +118,6 @@ async fn download_toolchain(client: &Client, url: &str) -> Result<()> {
fs::create_dir(&jolt_dir)?;
}

println!("Downloading toolchain");
let mut response = client.get(url).send().await?;
if response.status().is_success() {
let mut file = File::create(output_path)?;
Expand Down Expand Up @@ -146,6 +149,14 @@ async fn download_toolchain(client: &Client, url: &str) -> Result<()> {
}
}

fn remove_archive() -> Result<()> {
let toolchain_archive = jolt_dir().join("rust-toolchain.tar.gz");
if toolchain_archive.exists() {
fs::remove_file(&toolchain_archive)?;
}
Ok(())
}

fn toolchain_url() -> String {
let target = target_lexicon::HOST;
format!(
Expand All @@ -154,6 +165,16 @@ fn toolchain_url() -> String {
)
}

#[cfg(not(target_arch = "wasm32"))]
pub fn uninstall_no_std_toolchain() -> Result<()> {
std::process::Command::new("rustup")
.args(["target", "remove", "riscv32im-unknown-none-elf"])
.output()?;

println!("\"riscv32im-unknown-none-elf\" toolchain uninstalled successfully");
Ok(())
}

#[cfg(not(target_arch = "wasm32"))]
/// Uninstalls the toolchain if it is already installed
pub fn uninstall_toolchain() -> Result<()> {
Expand Down Expand Up @@ -181,18 +202,15 @@ pub fn uninstall_toolchain() -> Result<()> {
}

// Remove the downloaded toolchain archive
let toolchain_archive = jolt_dir().join("rust-toolchain.tar.gz");
if toolchain_archive.exists() {
fs::remove_file(&toolchain_archive)?;
}
remove_archive()?;

// Remove the toolchain tag file
let tag_file = toolchain_tag_file();
if tag_file.exists() {
fs::remove_file(&tag_file)?;
}

println!("Toolchain uninstalled successfully");
println!("\"riscv32im-jolt-zkvm-elf\" toolchain uninstalled successfully");
Ok(())
}

Expand Down

0 comments on commit 45dd06a

Please sign in to comment.