@@ -52,6 +52,8 @@ struct State<'a, 'gctx> {
5252 std_resolve : Option < & ' a Resolve > ,
5353 /// Like `usr_features` but for building standard library (`-Zbuild-std`).
5454 std_features : Option < & ' a ResolvedFeatures > ,
55+ // The root units of any opaque dependencies present in the user resolve
56+ opaque_roots : & ' a HashMap < CompileKind , Vec < Unit > > ,
5557 /// `true` while generating the dependencies for the standard library.
5658 is_std : bool ,
5759 /// The high-level operation requested by the user.
@@ -92,7 +94,7 @@ pub fn build_unit_dependencies<'a, 'gctx>(
9294 resolve : & ' a Resolve ,
9395 features : & ' a ResolvedFeatures ,
9496 std_resolve : Option < & ' a ( Resolve , ResolvedFeatures ) > ,
95- roots : & [ Unit ] ,
97+ roots : & [ Unit ] , //TODO: builtins can be roots if requested on the command line
9698 scrape_units : & [ Unit ] ,
9799 std_roots : & HashMap < CompileKind , Vec < Unit > > ,
98100 intent : UserIntent ,
@@ -119,6 +121,7 @@ pub fn build_unit_dependencies<'a, 'gctx>(
119121 usr_features : features,
120122 std_resolve,
121123 std_features,
124+ opaque_roots : std_roots,
122125 is_std : false ,
123126 intent,
124127 target_data,
@@ -129,15 +132,14 @@ pub fn build_unit_dependencies<'a, 'gctx>(
129132 } ;
130133
131134 let std_unit_deps = calc_deps_of_std ( & mut state, std_roots) ?;
135+ if let Some ( std_unit_deps) = std_unit_deps {
136+ attach_std_deps ( & mut state, std_unit_deps) ;
137+ }
132138
133139 deps_of_roots ( roots, & mut state) ?;
134140 super :: links:: validate_links ( state. resolve ( ) , & state. unit_dependencies ) ?;
135141 // Hopefully there aren't any links conflicts with the standard library?
136142
137- if let Some ( std_unit_deps) = std_unit_deps {
138- attach_std_deps ( & mut state, std_roots, std_unit_deps) ;
139- }
140-
141143 connect_run_custom_build_deps ( & mut state) ;
142144
143145 // Dependencies are used in tons of places throughout the backend, many of
@@ -188,35 +190,14 @@ fn calc_deps_of_std(
188190 Ok ( Some ( std:: mem:: take ( & mut state. unit_dependencies ) ) )
189191}
190192
191- /// Add the standard library units to the `unit_dependencies`.
192- fn attach_std_deps (
193- state : & mut State < ' _ , ' _ > ,
194- std_roots : & HashMap < CompileKind , Vec < Unit > > ,
195- std_unit_deps : UnitGraph ,
196- ) {
197- // Attach the standard library as a dependency of every target unit.
198- let mut found = false ;
199- for ( unit, deps) in state. unit_dependencies . iter_mut ( ) {
200- if !unit. kind . is_host ( ) && !unit. mode . is_run_custom_build ( ) {
201- deps. extend ( std_roots[ & unit. kind ] . iter ( ) . map ( |unit| UnitDep {
202- unit : unit. clone ( ) ,
203- unit_for : UnitFor :: new_normal ( unit. kind ) ,
204- extern_crate_name : unit. pkg . name ( ) ,
205- dep_name : None ,
206- // TODO: Does this `public` make sense?
207- public : true ,
208- noprelude : true ,
209- } ) ) ;
210- found = true ;
193+ /// Add the dependencies of standard library units to the `unit_dependencies`.
194+ fn attach_std_deps ( state : & mut State < ' _ , ' _ > , std_unit_deps : UnitGraph ) {
195+ for ( unit, deps) in std_unit_deps. into_iter ( ) {
196+ if unit. pkg . package_id ( ) . name ( ) == "sysroot" {
197+ continue ;
211198 }
212- }
213- // And also include the dependencies of the standard library itself. Don't
214- // include these if no units actually needed the standard library.
215- if found {
216- for ( unit, deps) in std_unit_deps. into_iter ( ) {
217- if let Some ( other_unit) = state. unit_dependencies . insert ( unit, deps) {
218- panic ! ( "std unit collision with existing unit: {:?}" , other_unit) ;
219- }
199+ if let Some ( other_unit) = state. unit_dependencies . insert ( unit, deps) {
200+ panic ! ( "std unit collision with existing unit: {:?}" , other_unit) ;
220201 }
221202 }
222203}
@@ -333,16 +314,37 @@ fn compute_deps(
333314 ) ?;
334315 ret. push ( unit_dep) ;
335316 } else {
336- let unit_dep = new_unit_dep (
337- state,
338- unit,
339- dep_pkg,
340- dep_lib,
341- dep_unit_for,
342- unit. kind . for_target ( dep_lib) ,
343- mode,
344- IS_NO_ARTIFACT_DEP ,
345- ) ?;
317+ // if builtin, return from state.opaque_roots
318+ let unit_dep = if dep_pkg_id. source_id ( ) . is_builtin ( ) {
319+ let unit: Vec < _ > = state. opaque_roots [ & unit. kind . for_target ( dep_lib) ]
320+ . iter ( )
321+ . filter ( |& u| u. pkg . name ( ) == dep_pkg_id. name ( ) )
322+ . collect ( ) ;
323+ assert ! (
324+ unit. len( ) == 1 ,
325+ "libstd was resolved with all possible builtin deps as roots"
326+ ) ;
327+ let unit = unit[ 0 ] ;
328+ UnitDep {
329+ unit : unit. clone ( ) ,
330+ unit_for : UnitFor :: new_normal ( unit. kind ) ,
331+ extern_crate_name : unit. pkg . name ( ) ,
332+ dep_name : None ,
333+ public : true ,
334+ noprelude : true ,
335+ }
336+ } else {
337+ new_unit_dep (
338+ state,
339+ unit,
340+ dep_pkg,
341+ dep_lib,
342+ dep_unit_for,
343+ unit. kind . for_target ( dep_lib) ,
344+ mode,
345+ IS_NO_ARTIFACT_DEP ,
346+ ) ?
347+ } ;
346348 ret. push ( unit_dep) ;
347349 }
348350
0 commit comments