@@ -43,8 +43,7 @@ use self::unit_dependencies::UnitDep;
43
43
pub use crate :: core:: compiler:: unit:: { Unit , UnitInterner } ;
44
44
use crate :: core:: manifest:: TargetSourcePath ;
45
45
use crate :: core:: profiles:: { Lto , PanicStrategy , Profile } ;
46
- use crate :: core:: Feature ;
47
- use crate :: core:: { PackageId , Target } ;
46
+ use crate :: core:: { Feature , InternedString , PackageId , Target } ;
48
47
use crate :: util:: errors:: { self , CargoResult , CargoResultExt , Internal , ProcessError } ;
49
48
use crate :: util:: machine_message:: Message ;
50
49
use crate :: util:: paths;
@@ -894,8 +893,7 @@ fn build_deps_args<'a, 'cfg>(
894
893
} ) ;
895
894
}
896
895
897
- // Create Vec since mutable cx is needed in closure below.
898
- let deps = Vec :: from ( cx. unit_deps ( unit) ) ;
896
+ let deps = cx. unit_deps ( unit) ;
899
897
900
898
// If there is not one linkable target but should, rustc fails later
901
899
// on if there is an `extern crate` for it. This may turn into a hard
@@ -922,23 +920,14 @@ fn build_deps_args<'a, 'cfg>(
922
920
923
921
let mut unstable_opts = false ;
924
922
925
- if let Some ( sysroot) = cx. files ( ) . layout ( unit. kind ) . sysroot ( ) {
926
- if !unit. kind . is_host ( ) {
927
- cmd. arg ( "--sysroot" ) . arg ( sysroot) ;
928
- }
929
- }
930
-
931
923
for dep in deps {
932
- if !unit. is_std && dep. unit . is_std {
933
- // Dependency to sysroot crate uses --sysroot.
934
- continue ;
935
- }
936
924
if dep. unit . mode . is_run_custom_build ( ) {
937
925
cmd. env ( "OUT_DIR" , & cx. files ( ) . build_script_out_dir ( & dep. unit ) ) ;
938
926
}
939
- if dep. unit . target . linkable ( ) && !dep. unit . mode . is_doc ( ) {
940
- link_to ( cmd, cx, unit, & dep, & mut unstable_opts) ?;
941
- }
927
+ }
928
+
929
+ for arg in extern_args ( cx, unit, & mut unstable_opts) ? {
930
+ cmd. arg ( arg) ;
942
931
}
943
932
944
933
// This will only be set if we're already using a feature
@@ -948,37 +937,51 @@ fn build_deps_args<'a, 'cfg>(
948
937
}
949
938
950
939
return Ok ( ( ) ) ;
940
+ }
951
941
952
- fn link_to < ' a , ' cfg > (
953
- cmd : & mut ProcessBuilder ,
954
- cx : & mut Context < ' a , ' cfg > ,
955
- current : & Unit < ' a > ,
956
- dep : & UnitDep < ' a > ,
957
- need_unstable_opts : & mut bool ,
958
- ) -> CargoResult < ( ) > {
942
+ /// Generates a list of `--extern` arguments.
943
+ pub fn extern_args < ' a > (
944
+ cx : & Context < ' a , ' _ > ,
945
+ unit : & Unit < ' a > ,
946
+ unstable_opts : & mut bool ,
947
+ ) -> CargoResult < Vec < OsString > > {
948
+ let mut result = Vec :: new ( ) ;
949
+ let deps = cx. unit_deps ( unit) ;
950
+
951
+ // Closure to add one dependency to `result`.
952
+ let mut link_to = |dep : & UnitDep < ' a > ,
953
+ extern_crate_name : InternedString ,
954
+ noprelude : bool |
955
+ -> CargoResult < ( ) > {
959
956
let mut value = OsString :: new ( ) ;
960
- value. push ( dep. extern_crate_name . as_str ( ) ) ;
957
+ let mut opts = Vec :: new ( ) ;
958
+ if unit
959
+ . pkg
960
+ . manifest ( )
961
+ . features ( )
962
+ . require ( Feature :: public_dependency ( ) )
963
+ . is_ok ( )
964
+ && !dep. public
965
+ {
966
+ opts. push ( "priv" ) ;
967
+ * unstable_opts = true ;
968
+ }
969
+ if noprelude {
970
+ opts. push ( "noprelude" ) ;
971
+ * unstable_opts = true ;
972
+ }
973
+ if !opts. is_empty ( ) {
974
+ value. push ( opts. join ( "," ) ) ;
975
+ value. push ( ":" ) ;
976
+ }
977
+ value. push ( extern_crate_name. as_str ( ) ) ;
961
978
value. push ( "=" ) ;
962
979
963
980
let mut pass = |file| {
964
981
let mut value = value. clone ( ) ;
965
982
value. push ( file) ;
966
-
967
- if current
968
- . pkg
969
- . manifest ( )
970
- . features ( )
971
- . require ( Feature :: public_dependency ( ) )
972
- . is_ok ( )
973
- && !dep. public
974
- {
975
- cmd. arg ( "--extern-private" ) ;
976
- * need_unstable_opts = true ;
977
- } else {
978
- cmd. arg ( "--extern" ) ;
979
- }
980
-
981
- cmd. arg ( & value) ;
983
+ result. push ( OsString :: from ( "--extern" ) ) ;
984
+ result. push ( value) ;
982
985
} ;
983
986
984
987
let outputs = cx. outputs ( & dep. unit ) ?;
@@ -987,7 +990,7 @@ fn build_deps_args<'a, 'cfg>(
987
990
_ => None ,
988
991
} ) ;
989
992
990
- if cx. only_requires_rmeta ( current , & dep. unit ) {
993
+ if cx. only_requires_rmeta ( unit , & dep. unit ) {
991
994
let ( output, _rmeta) = outputs
992
995
. find ( |( _output, rmeta) | * rmeta)
993
996
. expect ( "failed to find rlib dep for pipelined dep" ) ;
@@ -1000,7 +1003,15 @@ fn build_deps_args<'a, 'cfg>(
1000
1003
}
1001
1004
}
1002
1005
Ok ( ( ) )
1006
+ } ;
1007
+
1008
+ for dep in deps {
1009
+ if dep. unit . target . linkable ( ) && !dep. unit . mode . is_doc ( ) {
1010
+ link_to ( & dep, dep. extern_crate_name , dep. noprelude ) ?;
1011
+ }
1003
1012
}
1013
+
1014
+ Ok ( result)
1004
1015
}
1005
1016
1006
1017
fn envify ( s : & str ) -> String {
0 commit comments