@@ -249,14 +249,12 @@ fn make_failed_scrape_diagnostic(
249
249
250
250
/// Creates a unit of work invoking `rustc` for building the `unit`.
251
251
fn rustc ( cx : & mut Context < ' _ , ' _ > , unit : & Unit , exec : & Arc < dyn Executor > ) -> CargoResult < Work > {
252
- let mut rustc = prepare_rustc ( cx, & unit . target . rustc_crate_types ( ) , unit) ?;
252
+ let mut rustc = prepare_rustc ( cx, unit) ?;
253
253
let build_plan = cx. bcx . build_config . build_plan ;
254
254
255
255
let name = unit. pkg . name ( ) . to_string ( ) ;
256
256
let buildkey = unit. buildkey ( ) ;
257
257
258
- add_cap_lints ( cx. bcx , unit, & mut rustc) ;
259
-
260
258
let outputs = cx. outputs ( unit) ?;
261
259
let root = cx. files ( ) . out_dir ( unit) ;
262
260
@@ -282,10 +280,6 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
282
280
let rustc_dep_info_loc = root. join ( dep_info_name) ;
283
281
let dep_info_loc = fingerprint:: dep_info_loc ( cx, unit) ;
284
282
285
- rustc. args ( cx. bcx . rustflags_args ( unit) ) ;
286
- if cx. bcx . config . cli_unstable ( ) . binary_dep_depinfo {
287
- rustc. arg ( "-Z" ) . arg ( "binary-dep-depinfo" ) ;
288
- }
289
283
let mut output_options = OutputOptions :: new ( cx, unit) ;
290
284
let package_id = unit. pkg . package_id ( ) ;
291
285
let target = Target :: clone ( & unit. target ) ;
@@ -668,13 +662,13 @@ where
668
662
search_path
669
663
}
670
664
671
- // TODO: do we really need this as a separate function?
672
- // Maybe we should reorganize `rustc` fn to make it more traceable and readable .
673
- fn prepare_rustc (
674
- cx : & Context < ' _ , ' _ > ,
675
- crate_types : & [ CrateType ] ,
676
- unit : & Unit ,
677
- ) -> CargoResult < ProcessBuilder > {
665
+ /// Prepares flags and environments we can compute for a `rustc` invocation
666
+ /// before the job queue starts compiling any unit .
667
+ ///
668
+ /// This builds a static view of the invocation. Flags depending on the
669
+ /// completion of other units will be added later in runtime, such as flags
670
+ /// from build scripts.
671
+ fn prepare_rustc ( cx : & Context < ' _ , ' _ > , unit : & Unit ) -> CargoResult < ProcessBuilder > {
678
672
let is_primary = cx. is_primary_package ( unit) ;
679
673
let is_workspace = cx. bcx . ws . is_member ( & unit. pkg ) ;
680
674
@@ -692,8 +686,13 @@ fn prepare_rustc(
692
686
}
693
687
694
688
base. inherit_jobserver ( & cx. jobserver ) ;
695
- build_base_args ( cx, & mut base, unit, crate_types ) ?;
689
+ build_base_args ( cx, & mut base, unit) ?;
696
690
build_deps_args ( & mut base, cx, unit) ?;
691
+ add_cap_lints ( cx. bcx , unit, & mut base) ;
692
+ base. args ( cx. bcx . rustflags_args ( unit) ) ;
693
+ if cx. bcx . config . cli_unstable ( ) . binary_dep_depinfo {
694
+ base. arg ( "-Z" ) . arg ( "binary-dep-depinfo" ) ;
695
+ }
697
696
Ok ( base)
698
697
}
699
698
@@ -940,12 +939,7 @@ fn add_error_format_and_color(cx: &Context<'_, '_>, cmd: &mut ProcessBuilder) {
940
939
}
941
940
942
941
/// Adds essential rustc flags and environment variables to the command to execute.
943
- fn build_base_args (
944
- cx : & Context < ' _ , ' _ > ,
945
- cmd : & mut ProcessBuilder ,
946
- unit : & Unit ,
947
- crate_types : & [ CrateType ] ,
948
- ) -> CargoResult < ( ) > {
942
+ fn build_base_args ( cx : & Context < ' _ , ' _ > , cmd : & mut ProcessBuilder , unit : & Unit ) -> CargoResult < ( ) > {
949
943
assert ! ( !unit. mode. is_run_custom_build( ) ) ;
950
944
951
945
let bcx = cx. bcx ;
@@ -977,7 +971,7 @@ fn build_base_args(
977
971
978
972
let mut contains_dy_lib = false ;
979
973
if !test {
980
- for crate_type in crate_types {
974
+ for crate_type in & unit . target . rustc_crate_types ( ) {
981
975
cmd. arg ( "--crate-type" ) . arg ( crate_type. as_str ( ) ) ;
982
976
contains_dy_lib |= crate_type == & CrateType :: Dylib ;
983
977
}
0 commit comments