@@ -9,54 +9,40 @@ use crate::core::resolver::HasDevUnits;
9
9
use crate :: core:: { PackageId , PackageSet , Resolve , Workspace } ;
10
10
use crate :: ops:: { self , Packages } ;
11
11
use crate :: util:: errors:: CargoResult ;
12
- use crate :: GlobalContext ;
12
+
13
13
use std:: collections:: { HashMap , HashSet } ;
14
14
use std:: path:: PathBuf ;
15
15
16
16
use super :: BuildConfig ;
17
17
18
- /// Parse the `-Zbuild-std` flag.
19
- pub fn parse_unstable_flag ( value : Option < & str > ) -> Vec < String > {
18
+ fn std_crates < ' a > ( crates : & ' a [ String ] , units : Option < & [ Unit ] > ) -> HashSet < & ' a str > {
19
+ let mut crates = HashSet :: from_iter ( crates . iter ( ) . map ( |s| s . as_str ( ) ) ) ;
20
20
// This is a temporary hack until there is a more principled way to
21
21
// declare dependencies in Cargo.toml.
22
- let value = value. unwrap_or ( "std" ) ;
23
- let mut crates: HashSet < & str > = value. split ( ',' ) . collect ( ) ;
22
+ if crates. is_empty ( ) {
23
+ crates. insert ( "std" ) ;
24
+ }
24
25
if crates. contains ( "std" ) {
25
26
crates. insert ( "core" ) ;
26
27
crates. insert ( "alloc" ) ;
27
28
crates. insert ( "proc_macro" ) ;
28
29
crates. insert ( "panic_unwind" ) ;
29
30
crates. insert ( "compiler_builtins" ) ;
30
- } else if crates. contains ( "core" ) {
31
- crates. insert ( "compiler_builtins" ) ;
32
- }
33
- crates. into_iter ( ) . map ( |s| s. to_string ( ) ) . collect ( )
34
- }
35
-
36
- pub ( crate ) fn std_crates ( gctx : & GlobalContext , units : Option < & [ Unit ] > ) -> Option < Vec < String > > {
37
- let crates = gctx. cli_unstable ( ) . build_std . as_ref ( ) ?. clone ( ) ;
38
-
39
- // Only build libtest if it looks like it is needed.
40
- let mut crates = crates. clone ( ) ;
41
- // If we know what units we're building, we can filter for libtest depending on the jobs.
42
- if let Some ( units) = units {
43
- if units
44
- . iter ( )
45
- . any ( |unit| unit. mode . is_rustc_test ( ) && unit. target . harness ( ) )
46
- {
47
- // Only build libtest when libstd is built (libtest depends on libstd)
48
- if crates. iter ( ) . any ( |c| c == "std" ) && !crates. iter ( ) . any ( |c| c == "test" ) {
49
- crates. push ( "test" . to_string ( ) ) ;
31
+ // Only build libtest if it looks like it is needed (libtest depends on libstd)
32
+ // If we know what units we're building, we can filter for libtest depending on the jobs.
33
+ if let Some ( units) = units {
34
+ if units
35
+ . iter ( )
36
+ . any ( |unit| unit. mode . is_rustc_test ( ) && unit. target . harness ( ) )
37
+ {
38
+ crates. insert ( "test" ) ;
50
39
}
51
40
}
52
- } else {
53
- // We don't know what jobs are going to be run, so download libtest just in case.
54
- if !crates. iter ( ) . any ( |c| c == "test" ) {
55
- crates. push ( "test" . to_string ( ) )
56
- }
41
+ } else if crates. contains ( "core" ) {
42
+ crates. insert ( "compiler_builtins" ) ;
57
43
}
58
44
59
- Some ( crates)
45
+ crates
60
46
}
61
47
62
48
/// Resolve the standard library dependencies.
@@ -66,14 +52,16 @@ pub fn resolve_std<'gctx>(
66
52
build_config : & BuildConfig ,
67
53
crates : & [ String ] ,
68
54
) -> CargoResult < ( PackageSet < ' gctx > , Resolve , ResolvedFeatures ) > {
55
+ let crates = std_crates ( crates, None ) ;
56
+
69
57
if build_config. build_plan {
70
58
ws. gctx ( )
71
59
. shell ( )
72
60
. warn ( "-Zbuild-std does not currently fully support --build-plan" ) ?;
73
61
}
74
62
75
63
// check that targets support building std
76
- if crates. contains ( & "std" . to_string ( ) ) {
64
+ if crates. contains ( "std" ) {
77
65
let unsupported_targets = target_data. get_unsupported_std_targets ( ) ;
78
66
if !unsupported_targets. is_empty ( ) {
79
67
anyhow:: bail!(
@@ -95,7 +83,7 @@ pub fn resolve_std<'gctx>(
95
83
std_ws. set_require_optional_deps ( false ) ;
96
84
// `sysroot` is not in the default set because it is optional, but it needs
97
85
// to be part of the resolve in case we do need it or `libtest`.
98
- let mut spec_pkgs = Vec :: from ( crates) ;
86
+ let mut spec_pkgs: Vec < String > = crates. iter ( ) . map ( |s| s . to_string ( ) ) . collect ( ) ;
99
87
spec_pkgs. push ( "sysroot" . to_string ( ) ) ;
100
88
let spec = Packages :: Packages ( spec_pkgs) ;
101
89
let specs = spec. to_package_id_specs ( & std_ws) ?;
@@ -128,11 +116,13 @@ pub fn resolve_std<'gctx>(
128
116
) )
129
117
}
130
118
131
- /// Generate a list of root `Unit`s for the standard library.
119
+ /// Generates a map of root units for the standard library for each kind requested .
132
120
///
133
- /// The given slice of crate names is the root set.
121
+ /// * `crates` is the arg value from `-Zbuild-std`.
122
+ /// * `units` is the root units of the build.
134
123
pub fn generate_std_roots (
135
124
crates : & [ String ] ,
125
+ units : & [ Unit ] ,
136
126
std_resolve : & Resolve ,
137
127
std_features : & ResolvedFeatures ,
138
128
kinds : & [ CompileKind ] ,
@@ -141,8 +131,7 @@ pub fn generate_std_roots(
141
131
profiles : & Profiles ,
142
132
target_data : & RustcTargetData < ' _ > ,
143
133
) -> CargoResult < HashMap < CompileKind , Vec < Unit > > > {
144
- // Generate the root Units for the standard library.
145
- let std_ids = crates
134
+ let std_ids = std_crates ( crates, Some ( units) )
146
135
. iter ( )
147
136
. map ( |crate_name| std_resolve. query ( crate_name) )
148
137
. collect :: < CargoResult < Vec < PackageId > > > ( ) ?;
0 commit comments