@@ -15,7 +15,7 @@ use std::process::{Command, Output};
15
15
use std:: str;
16
16
use std:: time:: { self , Duration } ;
17
17
18
- use cargo:: util:: { CargoResult , Rustc } ;
18
+ use cargo:: util:: CargoResult ;
19
19
use cargo_util:: { is_ci, ProcessBuilder , ProcessError } ;
20
20
use serde_json:: { self , Value } ;
21
21
use url:: Url ;
@@ -1549,25 +1549,44 @@ fn substitute_macros(input: &str) -> String {
1549
1549
1550
1550
pub mod install;
1551
1551
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
+ }
1561
1580
1562
1581
/// 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
1565
1584
}
1566
1585
1567
1586
pub fn is_nightly ( ) -> bool {
1587
+ let vv = & RUSTC_INFO . verbose_version ;
1568
1588
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" ) )
1571
1590
}
1572
1591
1573
1592
pub fn process < T : AsRef < OsStr > > ( t : T ) -> ProcessBuilder {
0 commit comments