@@ -21,6 +21,7 @@ use std::{env, fs, mem};
21
21
use cargo:: core:: shell:: { ColorConfig , Verbosity } ;
22
22
use cargo:: util:: { self , CargoResult , ChainError , Config , Filesystem } ;
23
23
use rustc_cfg:: Cfg ;
24
+ use rustc_version:: Channel ;
24
25
25
26
mod sysroot;
26
27
@@ -47,26 +48,35 @@ fn run(config_opt: &mut Option<Config>) -> CargoResult<()> {
47
48
is not set")
48
49
} ) ) ;
49
50
51
+ let meta = rustc_version:: version_meta_for ( & config. rustc_info ( ) . verbose_version ) ;
52
+ if meta. channel != Channel :: Nightly {
53
+ return Err ( util:: human ( "Only the nightly channel is currently supported" ) ) ;
54
+ }
55
+
50
56
let ( mut cargo, target, verbose, is_cargo_doc, verb) = try!( parse_args ( ) ) ;
51
57
52
- let rustflags = & try!( rustflags ( config) ) ;
58
+ let target = if let Some ( target) = target {
59
+ Some ( target)
60
+ } else {
61
+ if let Some ( triple) = try!( config. get_string ( "build.target" ) ) {
62
+ try!( Target :: from ( & triple. val ) )
63
+ } else {
64
+ None
65
+ }
66
+ } ;
67
+
68
+ let rustflags = & try!( rustflags ( config, target. as_ref ( ) . map ( |t| & t. triple ) , & meta. host ) ) ;
53
69
let profiles = & try!( parse_cargo_toml ( config) ) ;
54
70
let mut with_sysroot = false ;
55
71
56
72
match verb. as_ref ( ) . map ( |s| & * * s) {
57
73
// All these commands shouldn't trigger a sysroot rebuild
58
- Some ( "clean" ) | Some ( "new" ) | Some ( "init" ) | Some ( "update" ) | Some ( "search" ) => { } ,
74
+ Some ( "clean" ) | Some ( "new" ) | Some ( "init" ) | Some ( "update" ) | Some ( "search" ) => { }
59
75
_ => {
60
76
if let Some ( target) = target {
61
- try!( sysroot:: create ( config, & target, root, verbose, rustflags, profiles) ) ;
77
+ try!( sysroot:: create ( config, & target, root, verbose, rustflags, profiles, meta ) ) ;
62
78
with_sysroot = true ;
63
- } else if let Some ( triple) = try!( config. get_string ( "build.target" ) ) {
64
- if let Some ( target) = try!( Target :: from ( & triple. val ) ) {
65
- try!( sysroot:: create ( config, & target, root, verbose, rustflags, profiles) ) ;
66
- with_sysroot = true ;
67
- }
68
79
}
69
-
70
80
}
71
81
}
72
82
@@ -201,13 +211,20 @@ fn parse_args() -> CargoResult<(Command, Option<Target>, bool, bool, Option<Stri
201
211
202
212
/// Returns the RUSTFLAGS the user has set either via the env variable or via build.rustflags
203
213
// NOTE Logic copied from cargo's Context::rustflags_args
204
- fn rustflags ( config : & Config ) -> CargoResult < Vec < String > > {
214
+ fn rustflags ( config : & Config , target : Option < & String > , host : & String ) -> CargoResult < Vec < String > > {
205
215
// First try RUSTFLAGS from the environment
206
216
if let Some ( a) = env:: var ( "RUSTFLAGS" ) . ok ( ) {
207
217
let args = a. split ( " " ) . map ( str:: trim) . filter ( |s| !s. is_empty ( ) ) . map ( str:: to_string) ;
208
218
return Ok ( args. collect ( ) ) ;
209
219
}
210
220
221
+ // Then the target.*.rustflags value
222
+ if let Some ( args) =
223
+ try!( config. get_list ( & format ! ( "target.{}.rustflags" , target. unwrap_or( host) ) ) ) {
224
+ let args = args. val . into_iter ( ) . map ( |a| a. 0 ) ;
225
+ return Ok ( args. collect ( ) ) ;
226
+ }
227
+
211
228
// Then the build.rustflags value
212
229
if let Some ( args) = try!( config. get_list ( "build.rustflags" ) ) {
213
230
let args = args. val . into_iter ( ) . map ( |a| a. 0 ) ;
0 commit comments