Skip to content

Commit

Permalink
fix(cli): get-target (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xYYY authored Feb 23, 2024
1 parent 81f01f9 commit aa71d90
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ serde_json = "1.0.113"
yansi = "0.5.1"
hex = "0.4.3"
anstyle = "1.0.6"
target-lexicon = "0.12.13"
6 changes: 3 additions & 3 deletions cli/src/commands/install_toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl InstallToolchainCmd {
let target = get_target();
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 toolchain_dir = root_dir.join(&target);
let toolchain_download_url = get_toolchain_download_url();

// Download the toolchain.
Expand All @@ -84,7 +84,7 @@ impl InstallToolchainCmd {
fs::create_dir_all(toolchain_dir)?;
Command::new("tar")
.current_dir(&root_dir)
.args(["-xzf", &toolchain_asset_name, "-C", target])
.args(["-xzf", &toolchain_asset_name, "-C", &target])
.run()?;

// Move the toolchain to a random directory (avoid rustup bugs).
Expand All @@ -95,7 +95,7 @@ impl InstallToolchainCmd {
.collect();
Command::new("mv")
.current_dir(&root_dir)
.args([target, &random_string])
.args([&target, &random_string])
.run()?;

// Link the toolchain to rustup.
Expand Down
15 changes: 3 additions & 12 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::cmp::min;
use std::fs::File as SyncFile;
use std::io::Write;
use std::process::{Command, Stdio};
use target_lexicon;

Check failure on line 13 in cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / Formatting & Clippy

this import is redundant

pub const RUSTUP_TOOLCHAIN_NAME: &str = "succinct";

Expand Down Expand Up @@ -62,18 +63,8 @@ pub async fn download_file(client: &Client, url: &str, path: &str) -> Result<(),
Ok(())
}

#[allow(unreachable_code)]
pub fn get_target() -> &'static str {
#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
return "x86_64-unknown-linux-gnu";

#[cfg(all(target_arch = "aarch64", target_os = "linux"))]
return "aarch64-unknown-linux-gnu";

#[cfg(all(target_arch = "aarch64", target_os = "macos"))]
return "aarch64-apple-darwin";

panic!("Unsupported architecture. Please build the toolchain from source.")
pub fn get_target() -> String {
target_lexicon::HOST.to_string()
}

#[allow(unreachable_code)]
Expand Down

0 comments on commit aa71d90

Please sign in to comment.