@@ -67,11 +67,11 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
67
67
profiles : & ' a Profiles ) -> CargoResult < Context < ' a , ' cfg > > {
68
68
let target = build_config. requested_target . clone ( ) ;
69
69
let target = target. as_ref ( ) . map ( |s| & s[ ..] ) ;
70
- let target_info = try!( Context :: target_info ( target, config) ) ;
70
+ let target_info = try!( Context :: target_info ( target, config, & build_config ) ) ;
71
71
let host_info = if build_config. requested_target . is_none ( ) {
72
72
target_info. clone ( )
73
73
} else {
74
- try!( Context :: target_info ( None , config) )
74
+ try!( Context :: target_info ( None , config, & build_config ) )
75
75
} ;
76
76
let target_triple = target. unwrap_or_else ( || {
77
77
& config. rustc_info ( ) . host [ ..]
@@ -103,15 +103,19 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
103
103
104
104
/// Run `rustc` to discover the dylib prefix/suffix for the target
105
105
/// specified as well as the exe suffix
106
- fn target_info ( target : Option < & str > , cfg : & Config )
106
+ fn target_info ( target : Option < & str > ,
107
+ cfg : & Config ,
108
+ build_config : & BuildConfig )
107
109
-> CargoResult < TargetInfo > {
110
+ let kind = if target. is_none ( ) { Kind :: Host } else { Kind :: Target } ;
108
111
let mut process = util:: process ( cfg. rustc ( ) ) ;
109
112
process. arg ( "-" )
110
113
. arg ( "--crate-name" ) . arg ( "_" )
111
114
. arg ( "--crate-type" ) . arg ( "dylib" )
112
115
. arg ( "--crate-type" ) . arg ( "staticlib" )
113
116
. arg ( "--crate-type" ) . arg ( "bin" )
114
117
. arg ( "--print=file-names" )
118
+ . args ( & try!( rustflags_args ( cfg, build_config, kind) ) )
115
119
. env_remove ( "RUST_LOG" ) ;
116
120
if let Some ( s) = target {
117
121
process. arg ( "--target" ) . arg ( s) ;
@@ -617,53 +621,59 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
617
621
& self . profiles . dev
618
622
}
619
623
620
- // Acquire extra flags to pass to the compiler from the
621
- // RUSTFLAGS environment variable and similar config values
622
624
pub fn rustflags_args ( & self , unit : & Unit ) -> CargoResult < Vec < String > > {
623
- // We *want* to apply RUSTFLAGS only to builds for the
624
- // requested target architecture, and not to things like build
625
- // scripts and plugins, which may be for an entirely different
626
- // architecture. Cargo's present architecture makes it quite
627
- // hard to only apply flags to things that are not build
628
- // scripts and plugins though, so we do something more hacky
629
- // instead to avoid applying the same RUSTFLAGS to multiple targets
630
- // arches:
631
- //
632
- // 1) If --target is not specified we just apply RUSTFLAGS to
633
- // all builds; they are all going to have the same target.
634
- //
635
- // 2) If --target *is* specified then we only apply RUSTFLAGS
636
- // to compilation units with the Target kind, which indicates
637
- // it was chosen by the --target flag.
638
- //
639
- // This means that, e.g. even if the specified --target is the
640
- // same as the host, build scripts in plugins won't get
641
- // RUSTFLAGS.
642
- let compiling_with_target = self . build_config . requested_target . is_some ( ) ;
643
- let is_target_kind = unit. kind == Kind :: Target ;
644
-
645
- if compiling_with_target && ! is_target_kind {
646
- // This is probably a build script or plugin and we're
647
- // compiling with --target. In this scenario there are
648
- // no rustflags we can apply.
649
- return Ok ( Vec :: new ( ) ) ;
650
- }
625
+ rustflags_args ( self . config , & self . build_config , unit. kind )
626
+ }
627
+ }
651
628
652
- // First try RUSTFLAGS from the environment
653
- if let Some ( a) = env:: var ( "RUSTFLAGS" ) . ok ( ) {
654
- let args = a. split ( " " )
655
- . map ( str:: trim)
656
- . filter ( |s| !s. is_empty ( ) )
657
- . map ( str:: to_string) ;
658
- return Ok ( args. collect ( ) ) ;
659
- }
629
+ // Acquire extra flags to pass to the compiler from the
630
+ // RUSTFLAGS environment variable and similar config values
631
+ fn rustflags_args ( config : & Config ,
632
+ build_config : & BuildConfig ,
633
+ kind : Kind ) -> CargoResult < Vec < String > > {
634
+ // We *want* to apply RUSTFLAGS only to builds for the
635
+ // requested target architecture, and not to things like build
636
+ // scripts and plugins, which may be for an entirely different
637
+ // architecture. Cargo's present architecture makes it quite
638
+ // hard to only apply flags to things that are not build
639
+ // scripts and plugins though, so we do something more hacky
640
+ // instead to avoid applying the same RUSTFLAGS to multiple targets
641
+ // arches:
642
+ //
643
+ // 1) If --target is not specified we just apply RUSTFLAGS to
644
+ // all builds; they are all going to have the same target.
645
+ //
646
+ // 2) If --target *is* specified then we only apply RUSTFLAGS
647
+ // to compilation units with the Target kind, which indicates
648
+ // it was chosen by the --target flag.
649
+ //
650
+ // This means that, e.g. even if the specified --target is the
651
+ // same as the host, build scripts in plugins won't get
652
+ // RUSTFLAGS.
653
+ let compiling_with_target = build_config. requested_target . is_some ( ) ;
654
+ let is_target_kind = kind == Kind :: Target ;
655
+
656
+ if compiling_with_target && !is_target_kind {
657
+ // This is probably a build script or plugin and we're
658
+ // compiling with --target. In this scenario there are
659
+ // no rustflags we can apply.
660
+ return Ok ( Vec :: new ( ) ) ;
661
+ }
660
662
661
- // Then the build.rustflags value
662
- if let Some ( args) = try!( self . config . get_list ( "build.rustflags" ) ) {
663
- let args = args. val . into_iter ( ) . map ( |a| a. 0 ) ;
664
- return Ok ( args. collect ( ) ) ;
665
- }
663
+ // First try RUSTFLAGS from the environment
664
+ if let Some ( a) = env:: var ( "RUSTFLAGS" ) . ok ( ) {
665
+ let args = a. split ( " " )
666
+ . map ( str:: trim)
667
+ . filter ( |s| !s. is_empty ( ) )
668
+ . map ( str:: to_string) ;
669
+ return Ok ( args. collect ( ) ) ;
670
+ }
666
671
667
- Ok ( Vec :: new ( ) )
672
+ // Then the build.rustflags value
673
+ if let Some ( args) = try!( config. get_list ( "build.rustflags" ) ) {
674
+ let args = args. val . into_iter ( ) . map ( |a| a. 0 ) ;
675
+ return Ok ( args. collect ( ) ) ;
668
676
}
677
+
678
+ Ok ( Vec :: new ( ) )
669
679
}
0 commit comments