Skip to content

Commit

Permalink
Get rustup target directly
Browse files Browse the repository at this point in the history
Signed-off-by: Graham MacDonald <[email protected]>
  • Loading branch information
gmacd authored and orangecms committed Jan 7, 2024
1 parent c1568ee commit 775db88
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 68 deletions.
65 changes: 1 addition & 64 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ edition = "2021"

[dependencies]
clap = { version = "4.2.4", features = ["derive"] }
rustup-configurator = "0.1.1"
serde = { version = "1.0.160", features = ["derive"] }
target-lexicon = { version = "0.12" }
toml = "0.8.0"
21 changes: 18 additions & 3 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::config::{generate_args, Configuration};
use rustup_configurator::Triple;
use std::{
env, fmt,
path::{Path, PathBuf},
process::{self, Command},
str::FromStr,
};
use target_lexicon::Triple;

mod config;

Expand Down Expand Up @@ -84,11 +85,25 @@ impl RustupState {
/// Also caches the current toolchain.
fn new() -> Self {
Self {
installed_targets: rustup_configurator::installed().unwrap(),
installed_targets: Self::installed_rustup_targets().unwrap(),
curr_toolchain: env::var("RUSTUP_TOOLCHAIN").unwrap(),
}
}

/// Call `rustup target list --installed` to get all installed target triples
fn installed_rustup_targets() -> Result<Vec<Triple>> {
let output =
Command::new("rustup").arg("target").arg("list").arg("--installed").output()?;
if !output.status.success() {
return Err(String::from_utf8(output.stdout.clone())?.into());
}

Ok(String::from_utf8(output.stdout.clone())?
.lines()
.flat_map(|line| Triple::from_str(line))
.collect())
}

/// For the given arch, return a compatible toolchain triple that is
/// installed and can be used by cargo check. It will prefer the default
/// toolchain if it's a match, otherwise it will look for the
Expand Down Expand Up @@ -692,7 +707,7 @@ impl TestStep {
}
let status = annotated_status(&mut cmd)?;
if !status.success() {
return Err("check failed".into());
return Err("test failed".into());
}
}
Ok(())
Expand Down

0 comments on commit 775db88

Please sign in to comment.