Skip to content

Commit 1022493

Browse files
committed
Remove use of Rustc from cargo-test-support.
cargo-test-support wasn't using any of the caching or other logic from Rustc, so this just swaps with a very basic implementation in order to remove the dependency on `cargo`.
1 parent 4aa1ec2 commit 1022493

File tree

1 file changed

+33
-14
lines changed
  • crates/cargo-test-support/src

1 file changed

+33
-14
lines changed

crates/cargo-test-support/src/lib.rs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::process::{Command, Output};
1515
use std::str;
1616
use std::time::{self, Duration};
1717

18-
use cargo::util::{CargoResult, Rustc};
18+
use cargo::util::CargoResult;
1919
use cargo_util::{is_ci, ProcessBuilder, ProcessError};
2020
use serde_json::{self, Value};
2121
use url::Url;
@@ -1549,25 +1549,44 @@ fn substitute_macros(input: &str) -> String {
15491549

15501550
pub mod install;
15511551

1552-
thread_local!(
1553-
pub static RUSTC: Rustc = Rustc::new(
1554-
PathBuf::from("rustc"),
1555-
None,
1556-
None,
1557-
Path::new("should be path to rustup rustc, but we don't care in tests"),
1558-
None,
1559-
).unwrap()
1560-
);
1552+
struct RustcInfo {
1553+
verbose_version: String,
1554+
host: String,
1555+
}
1556+
1557+
impl RustcInfo {
1558+
fn new() -> RustcInfo {
1559+
let output = ProcessBuilder::new("rustc")
1560+
.arg("-vV")
1561+
.exec_with_output()
1562+
.expect("rustc should exec");
1563+
let verbose_version = String::from_utf8(output.stdout).expect("utf8 output");
1564+
let host = verbose_version
1565+
.lines()
1566+
.filter_map(|line| line.strip_prefix("host: "))
1567+
.next()
1568+
.expect("verbose version has host: field")
1569+
.to_string();
1570+
RustcInfo {
1571+
verbose_version,
1572+
host,
1573+
}
1574+
}
1575+
}
1576+
1577+
lazy_static::lazy_static! {
1578+
static ref RUSTC_INFO: RustcInfo = RustcInfo::new();
1579+
}
15611580

15621581
/// The rustc host such as `x86_64-unknown-linux-gnu`.
1563-
pub fn rustc_host() -> String {
1564-
RUSTC.with(|r| r.host.to_string())
1582+
pub fn rustc_host() -> &'static str {
1583+
&RUSTC_INFO.host
15651584
}
15661585

15671586
pub fn is_nightly() -> bool {
1587+
let vv = &RUSTC_INFO.verbose_version;
15681588
env::var("CARGO_TEST_DISABLE_NIGHTLY").is_err()
1569-
&& RUSTC
1570-
.with(|r| r.verbose_version.contains("-nightly") || r.verbose_version.contains("-dev"))
1589+
&& (vv.contains("-nightly") || vv.contains("-dev"))
15711590
}
15721591

15731592
pub fn process<T: AsRef<OsStr>>(t: T) -> ProcessBuilder {

0 commit comments

Comments
 (0)