@@ -8,6 +8,7 @@ use crate::core::resolver::HasDevUnits;
8
8
use crate :: core:: { Dependency , PackageId , PackageSet , Resolve , SourceId , Workspace } ;
9
9
use crate :: ops:: { self , Packages } ;
10
10
use crate :: util:: errors:: CargoResult ;
11
+ use std:: collections:: hash_map:: Entry ;
11
12
use std:: collections:: { HashMap , HashSet } ;
12
13
use std:: env;
13
14
use std:: path:: PathBuf ;
@@ -133,7 +134,8 @@ pub fn generate_std_roots(
133
134
crates : & [ String ] ,
134
135
std_resolve : & Resolve ,
135
136
std_features : & ResolvedFeatures ,
136
- kinds : & [ CompileKind ] ,
137
+ requested_kinds : & [ CompileKind ] ,
138
+ explicit_host_kind : CompileKind ,
137
139
package_set : & PackageSet < ' _ > ,
138
140
interner : & UnitInterner ,
139
141
profiles : & Profiles ,
@@ -147,41 +149,51 @@ pub fn generate_std_roots(
147
149
let std_pkgs = package_set. get_many ( std_ids) ?;
148
150
// Generate a map of Units for each kind requested.
149
151
let mut ret = HashMap :: new ( ) ;
150
- for pkg in std_pkgs {
152
+
153
+ let std_pkg_infos: Vec < _ > = std_pkgs. iter ( ) . map ( |pkg| {
151
154
let lib = pkg
152
155
. targets ( )
153
156
. iter ( )
154
157
. find ( |t| t. is_lib ( ) )
155
158
. expect ( "std has a lib" ) ;
156
159
let unit_for = UnitFor :: new_normal ( ) ;
157
- // I don't think we need to bother with Check here, the difference
158
- // in time is minimal, and the difference in caching is
159
- // significant.
160
- let mode = CompileMode :: Build ;
161
160
let features = std_features. activated_features ( pkg. package_id ( ) , FeaturesFor :: NormalOrDev ) ;
161
+ ( pkg, lib, unit_for, features)
162
+ } ) . collect ( ) ;
162
163
164
+ for kinds in package_set. packages ( ) . map ( |pkg| pkg. explicit_kinds ( requested_kinds, explicit_host_kind) ) {
163
165
for kind in kinds {
164
- let list = ret. entry ( * kind) . or_insert_with ( Vec :: new) ;
165
- let profile = profiles. get_profile (
166
- pkg. package_id ( ) ,
167
- /*is_member*/ false ,
168
- /*is_local*/ false ,
169
- unit_for,
170
- mode,
171
- * kind,
172
- ) ;
173
- list. push ( interner. intern (
174
- pkg,
175
- lib,
176
- profile,
177
- * kind,
178
- mode,
179
- features. clone ( ) ,
180
- /*is_std*/ true ,
181
- /*dep_hash*/ 0 ,
182
- ) ) ;
166
+ if let Entry :: Vacant ( e) = ret. entry ( kind) {
167
+ let units = std_pkg_infos. iter ( ) . map ( |( pkg, lib, unit_for, features) | {
168
+ // I don't think we need to bother with Check here, the difference
169
+ // in time is minimal, and the difference in caching is
170
+ // significant.
171
+ let mode = CompileMode :: Build ;
172
+ let profile = profiles. get_profile (
173
+ pkg. package_id ( ) ,
174
+ /*is_member*/ false ,
175
+ /*is_local*/ false ,
176
+ * unit_for,
177
+ mode,
178
+ kind,
179
+ ) ;
180
+ interner. intern (
181
+ pkg,
182
+ lib,
183
+ profile,
184
+ kind,
185
+ mode,
186
+ features. clone ( ) ,
187
+ /*is_std*/ true ,
188
+ /*dep_hash*/ 0 ,
189
+ )
190
+ } ) ;
191
+
192
+ e. insert ( units. collect ( ) ) ;
193
+ }
183
194
}
184
195
}
196
+
185
197
Ok ( ret)
186
198
}
187
199
0 commit comments