File tree 1 file changed +23
-0
lines changed
src/cargo/ops/cargo_rustc
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,10 @@ pub struct TargetConfig {
46
46
/// The second element of the tuple returned is the target triple that rustc
47
47
/// is a host for.
48
48
pub fn rustc_version ( ) -> CargoResult < ( String , String ) > {
49
+ rustc_new_version ( ) . or_else ( |_| rustc_old_version ( ) )
50
+ }
51
+
52
+ pub fn rustc_old_version ( ) -> CargoResult < ( String , String ) > {
49
53
let output = try!( try!( util:: process ( "rustc" ) )
50
54
. arg ( "-v" )
51
55
. arg ( "verbose" )
@@ -65,6 +69,25 @@ pub fn rustc_version() -> CargoResult<(String, String)> {
65
69
Ok ( ( output, triple) )
66
70
}
67
71
72
+ pub fn rustc_new_version ( ) -> CargoResult < ( String , String ) > {
73
+ let output = try!( try!( util:: process ( "rustc" ) )
74
+ . arg ( "-vV" )
75
+ . exec_with_output ( ) ) ;
76
+ let output = try!( String :: from_utf8 ( output. output ) . map_err ( |_| {
77
+ internal ( "rustc -v didn't return utf8 output" )
78
+ } ) ) ;
79
+ let triple = {
80
+ let triple = output. as_slice ( ) . lines ( ) . filter ( |l| {
81
+ l. starts_with ( "host: " )
82
+ } ) . map ( |l| l. slice_from ( 6 ) ) . next ( ) ;
83
+ let triple = try!( triple. require ( || {
84
+ internal ( "rustc -v didn't have a line for `host:`" )
85
+ } ) ) ;
86
+ triple. to_string ( )
87
+ } ;
88
+ Ok ( ( output, triple) )
89
+ }
90
+
68
91
// This is a temporary assert that ensures the consistency of the arguments
69
92
// given the current limitations of Cargo. The long term fix is to have each
70
93
// Target know the absolute path to the build location.
You can’t perform that action at this time.
0 commit comments