From 2fdc6b99c34b99f8aa51b7ad7a23676aa8b3bd04 Mon Sep 17 00:00:00 2001 From: agnusmor Date: Wed, 11 Dec 2024 16:00:59 +0100 Subject: [PATCH 1/2] Add ZISK_TOOLCHAIN_SOURCE_DIR env variable to install-toolchain command. Change checkout branch to 'stable' on build-toolchain command --- cli/src/commands/build_toolchain.rs | 2 +- cli/src/commands/install_toolchain.rs | 47 ++++++++++++++++++--------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/cli/src/commands/build_toolchain.rs b/cli/src/commands/build_toolchain.rs index 5b36dbb1..e33589ea 100644 --- a/cli/src/commands/build_toolchain.rs +++ b/cli/src/commands/build_toolchain.rs @@ -33,7 +33,7 @@ impl BuildToolchainCmd { repo_url, "--depth=1", "--single-branch", - "--branch=zisk", + "--branch=stable", "zisk-rust", ]) .current_dir(&temp_dir) diff --git a/cli/src/commands/install_toolchain.rs b/cli/src/commands/install_toolchain.rs index 2b8d6e7e..d8c90f15 100644 --- a/cli/src/commands/install_toolchain.rs +++ b/cli/src/commands/install_toolchain.rs @@ -36,10 +36,10 @@ impl InstallToolchainCmd { if let Ok(entry) = entry { let entry_path = entry.path(); let entry_name = entry_path.file_name().unwrap(); - if entry_path.is_dir() && - entry_name != "bin" && - entry_name != "circuits" && - entry_name != "toolchains" + if entry_path.is_dir() + && entry_name != "bin" + && entry_name != "circuits" + && entry_name != "toolchains" { if let Err(err) = fs::remove_dir_all(&entry_path) { println!("Failed to remove directory {:?}: {}", entry_path, err); @@ -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") From b325f8600741a4c26bc7d53359bd11b3f097cefa Mon Sep 17 00:00:00 2001 From: agnusmor Date: Thu, 12 Dec 2024 12:06:51 +0100 Subject: [PATCH 2/2] fix linter --- cli/src/commands/install_toolchain.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/src/commands/install_toolchain.rs b/cli/src/commands/install_toolchain.rs index d8c90f15..17be7b55 100644 --- a/cli/src/commands/install_toolchain.rs +++ b/cli/src/commands/install_toolchain.rs @@ -36,10 +36,10 @@ impl InstallToolchainCmd { if let Ok(entry) = entry { let entry_path = entry.path(); let entry_name = entry_path.file_name().unwrap(); - if entry_path.is_dir() - && entry_name != "bin" - && entry_name != "circuits" - && entry_name != "toolchains" + if entry_path.is_dir() && + entry_name != "bin" && + entry_name != "circuits" && + entry_name != "toolchains" { if let Err(err) = fs::remove_dir_all(&entry_path) { println!("Failed to remove directory {:?}: {}", entry_path, err);