Skip to content

Commit 3e6a24f

Browse files
authored
Merge pull request #76 from klensy/rustc_version
replace version_check with rustc_version
2 parents 0ab1449 + d83b78e commit 3e6a24f

File tree

6 files changed

+23
-117
lines changed

6 files changed

+23
-117
lines changed

Cargo.lock

Lines changed: 15 additions & 87 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ rustc-demangle = "0.1"
4040
walkdir = "2.5"
4141
shellwords = "1.1"
4242
blake3 = "1.4"
43-
version_check = "0.9"
43+
rustc_version = "0.4.1"

src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn cargo_command_with_rustflags(
7272
// values from .cargo/config.toml.
7373

7474
// The `--config` flag is only supported in Rust 1.63+.
75-
let supports_config_flag = version_check::is_min_version("1.63.0").unwrap_or(false);
75+
let supports_config_flag = rustc_version::version()? >= semver::Version::new(1, 63, 0);
7676
let serialized_rustflags = rustflags.join(" ");
7777

7878
let mut final_cargo_args = vec![];

src/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::bolt::env::{find_llvm_bolt, find_merge_fdata};
22
use crate::bolt::llvm_bolt_install_hint;
33
use crate::cli::cli_format_path;
4-
use crate::get_rustc_version;
54
use crate::pgo::env::find_pgo_env;
65
use crate::pgo::llvm_profdata_install_hint;
76
use anyhow::anyhow;
87
use colored::Colorize;
8+
use rustc_version;
99
use std::path::PathBuf;
1010

1111
/// Check that binaries required for performing PGO and BOLT can be found.
@@ -23,7 +23,7 @@ pub fn environment_info() -> anyhow::Result<()> {
2323
}
2424

2525
fn check_rustc_version() -> bool {
26-
match get_rustc_version() {
26+
match rustc_version::version() {
2727
Ok(version) => {
2828
if version >= semver::Version::new(1, 39, 0) {
2929
println!(

src/lib.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub mod pgo;
1212
pub(crate) mod utils;
1313
pub(crate) mod workspace;
1414

15-
use anyhow::anyhow;
1615
use std::ffi::OsStr;
1716
use std::path::{Path, PathBuf};
1817
use std::process::{Command, ExitStatus};
@@ -68,28 +67,7 @@ fn run_command<S: AsRef<OsStr>, Str: AsRef<OsStr>>(
6867

6968
/// Tries to find the default target triple used for compiling on the current host computer.
7069
pub fn get_default_target() -> anyhow::Result<String> {
71-
get_rustc_info("host: ")
72-
}
73-
74-
pub fn get_rustc_version() -> anyhow::Result<semver::Version> {
75-
let version = get_rustc_info("release: ")?;
76-
let version = semver::Version::parse(&version)?;
77-
Ok(version)
78-
}
79-
80-
fn get_rustc_info(field: &str) -> anyhow::Result<String> {
81-
// Query rustc for defaults.
82-
let output = run_command("rustc", &["-vV"])?;
83-
84-
// Parse the field from stdout.
85-
let host = output
86-
.stdout
87-
.lines()
88-
.find(|l| l.starts_with(field))
89-
.map(|l| l[field.len()..].trim())
90-
.ok_or_else(|| anyhow!("Failed to parse field {} from rustc output.", field))?
91-
.to_owned();
92-
Ok(host)
70+
Ok(rustc_version::version_meta()?.host)
9371
}
9472

9573
/// Clears all files from the directory, and recreates it.

tests/integration/pgo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ fn test_respect_target_dir() -> anyhow::Result<()> {
233233

234234
#[test]
235235
fn test_respect_profile() -> anyhow::Result<()> {
236-
if !version_check::is_min_version("1.57.0").unwrap_or(false) {
236+
if !(rustc_version::version()? >= semver::Version::new(1, 57, 0)) {
237237
println!("Skipping test_respect_profile because of too old rustc");
238238
return Ok(());
239239
}
@@ -284,7 +284,7 @@ fn test_respect_existing_rustflags() -> anyhow::Result<()> {
284284
/// This only works for Rust 1.63+.
285285
#[test]
286286
fn test_override_build_rustflags_from_config() -> anyhow::Result<()> {
287-
if !version_check::is_min_version("1.63.0").unwrap_or(false) {
287+
if !(rustc_version::version()? >= semver::Version::new(1, 63, 0)) {
288288
return Ok(());
289289
}
290290

@@ -308,7 +308,7 @@ rustflags = ["-Ctarget-cpu=native"]
308308

309309
#[test]
310310
fn test_respect_existing_target_rustflags_from_config() -> anyhow::Result<()> {
311-
if !version_check::is_min_version("1.63.0").unwrap_or(false) {
311+
if !(rustc_version::version()? >= semver::Version::new(1, 63, 0)) {
312312
return Ok(());
313313
}
314314

0 commit comments

Comments
 (0)