@@ -36,20 +36,53 @@ fn use_feature(feature: &str) {
36
36
37
37
/// Test whether the rustc at `var("RUSTC")` supports the given feature.
38
38
fn has_feature ( feature : & str ) -> bool {
39
+ can_compile ( & format ! (
40
+ "#![allow(stable_features)]\n #![feature({})]" ,
41
+ feature
42
+ ) )
43
+ }
44
+
45
+ /// Test whether the rustc at `var("RUSTC")` can compile the given code.
46
+ fn can_compile < T : AsRef < str > > ( test : T ) -> bool {
47
+ use std:: process:: Stdio ;
48
+
39
49
let out_dir = var ( "OUT_DIR" ) . unwrap ( ) ;
40
50
let rustc = var ( "RUSTC" ) . unwrap ( ) ;
51
+ let target = var ( "TARGET" ) . unwrap ( ) ;
52
+
53
+ let mut cmd = if let Ok ( wrapper) = var ( "CARGO_RUSTC_WRAPPER" ) {
54
+ let mut cmd = std:: process:: Command :: new ( wrapper) ;
55
+ // The wrapper's first argument is supposed to be the path to rustc.
56
+ cmd. arg ( rustc) ;
57
+ cmd
58
+ } else {
59
+ std:: process:: Command :: new ( rustc)
60
+ } ;
41
61
42
- let mut child = std:: process:: Command :: new ( rustc)
43
- . arg ( "--crate-type=rlib" ) // Don't require `main`.
62
+ cmd. arg ( "--crate-type=rlib" ) // Don't require `main`.
44
63
. arg ( "--emit=metadata" ) // Do as little as possible but still parse.
64
+ . arg ( "--target" )
65
+ . arg ( target)
45
66
. arg ( "--out-dir" )
46
- . arg ( out_dir) // Put the output somewhere inconsequential.
67
+ . arg ( out_dir) ; // Put the output somewhere inconsequential.
68
+
69
+ // If Cargo wants to set RUSTFLAGS, use that.
70
+ if let Ok ( rustflags) = var ( "CARGO_ENCODED_RUSTFLAGS" ) {
71
+ if !rustflags. is_empty ( ) {
72
+ for arg in rustflags. split ( '\x1f' ) {
73
+ cmd. arg ( arg) ;
74
+ }
75
+ }
76
+ }
77
+
78
+ let mut child = cmd
47
79
. arg ( "-" ) // Read from stdin.
48
- . stdin ( std:: process:: Stdio :: piped ( ) ) // Stdin is a pipe.
80
+ . stdin ( Stdio :: piped ( ) ) // Stdin is a pipe.
81
+ . stderr ( Stdio :: null ( ) ) // Errors from feature detection aren't interesting and can be confusing.
49
82
. spawn ( )
50
83
. unwrap ( ) ;
51
84
52
- writeln ! ( child. stdin. take( ) . unwrap( ) , "#![feature({})] " , feature ) . unwrap ( ) ;
85
+ writeln ! ( child. stdin. take( ) . unwrap( ) , "{} " , test . as_ref ( ) ) . unwrap ( ) ;
53
86
54
87
child. wait ( ) . unwrap ( ) . success ( )
55
88
}
0 commit comments