Skip to content

Commit

Permalink
Merge pull request #191 from 0xPolygonHermez/toolchain-changes
Browse files Browse the repository at this point in the history
Toolchain build/install commands changes
  • Loading branch information
agnusmor authored Dec 16, 2024
2 parents 53ea392 + b325f86 commit 3fc9061
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cli/src/commands/build_toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl BuildToolchainCmd {
repo_url,
"--depth=1",
"--single-branch",
"--branch=zisk",
"--branch=stable",
"zisk-rust",
])
.current_dir(&temp_dir)
Expand Down
39 changes: 27 additions & 12 deletions cli/src/commands/install_toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,36 @@ impl InstallToolchainCmd {
let toolchain_asset_name = format!("rust-toolchain-{}.tar.gz", target);
let toolchain_archive_path = root_dir.join(toolchain_asset_name.clone());
let toolchain_dir = root_dir.join(&target);
let rt = tokio::runtime::Runtime::new()?;

let toolchain_download_url =
rt.block_on(get_toolchain_download_url(&client, target.to_string()));
let source_toolchain_dir = std::env::var("ZISK_TOOLCHAIN_SOURCE_DIR");
match source_toolchain_dir {
Ok(source_toolchain_dir) => {
// Copy the toolchain from the source directory.
let mut source_toolchain_file = fs::canonicalize(source_toolchain_dir)?;
source_toolchain_file.push(&toolchain_asset_name);
fs::copy(&source_toolchain_file, &toolchain_archive_path)?;
println!("Successfully copied toolchain from source directory.");
}
Err(_) => {
// Download the toolchain.
let rt = tokio::runtime::Runtime::new()?;

let artifact_exists = rt.block_on(url_exists(&client, toolchain_download_url.as_str()));
if !artifact_exists {
return Err(anyhow::anyhow!(
"Unsupported architecture. Please build the toolchain from source."
));
}
let toolchain_download_url =
rt.block_on(get_toolchain_download_url(&client, target.to_string()));

let artifact_exists =
rt.block_on(url_exists(&client, toolchain_download_url.as_str()));
if !artifact_exists {
return Err(anyhow::anyhow!(
"Unsupported architecture. Please build the toolchain from source."
));
}

// Download the toolchain.
let mut file = fs::File::create(toolchain_archive_path)?;
rt.block_on(download_file(&client, toolchain_download_url.as_str(), &mut file)).unwrap();
let mut file = fs::File::create(toolchain_archive_path)?;
rt.block_on(download_file(&client, toolchain_download_url.as_str(), &mut file))
.unwrap();
}
}

// Remove the existing toolchain from rustup, if it exists.
let mut child = Command::new("rustup")
Expand Down

0 comments on commit 3fc9061

Please sign in to comment.