Skip to content

Commit b0f118f

Browse files
committed
Auto merge of #12088 - weihanglo:build-std-fix, r=epage
fix: hack around `libsysroot` instead of `libtest` ### What does this PR try to resolve? This is a fix in response to rust-lang/rust#108865. Cargo `-Zbuild-std` now use `sysroot` crate to resolve cargo features instead of the old hack around `libtest`. `sysroot` is just a dummy crate depending on other standard library crates.
2 parents 2d693e2 + 3df35ed commit b0f118f

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

src/cargo/core/compiler/standard_lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn resolve_std<'cfg>(
9292
String::from("library/std"),
9393
String::from("library/core"),
9494
String::from("library/alloc"),
95-
String::from("library/test"),
95+
String::from("library/sysroot"),
9696
];
9797
let ws_config = crate::core::WorkspaceConfig::Root(crate::core::WorkspaceRootConfig::new(
9898
&src_path,
@@ -114,24 +114,24 @@ pub fn resolve_std<'cfg>(
114114
let config = ws.config();
115115
// This is a delicate hack. In order for features to resolve correctly,
116116
// the resolver needs to run a specific "current" member of the workspace.
117-
// Thus, in order to set the features for `std`, we need to set `libtest`
118-
// to be the "current" member. `libtest` is the root, and all other
117+
// Thus, in order to set the features for `std`, we need to set `sysroot`
118+
// to be the "current" member. `sysroot` is the root, and all other
119119
// standard library crates are dependencies from there. Since none of the
120120
// other crates need to alter their features, this should be fine, for
121121
// now. Perhaps in the future features will be decoupled from the resolver
122122
// and it will be easier to control feature selection.
123-
let current_manifest = src_path.join("library/test/Cargo.toml");
123+
let current_manifest = src_path.join("library/sysroot/Cargo.toml");
124124
// TODO: Consider doing something to enforce --locked? Or to prevent the
125125
// lock file from being written, such as setting ephemeral.
126126
let mut std_ws = Workspace::new_virtual(src_path, current_manifest, virtual_manifest, config)?;
127127
// Don't require optional dependencies in this workspace, aka std's own
128128
// `[dev-dependencies]`. No need for us to generate a `Resolve` which has
129129
// those included because we'll never use them anyway.
130130
std_ws.set_require_optional_deps(false);
131-
// `test` is not in the default set because it is optional, but it needs
132-
// to be part of the resolve in case we do need it.
131+
// `sysroot` is not in the default set because it is optional, but it needs
132+
// to be part of the resolve in case we do need it or `libtest`.
133133
let mut spec_pkgs = Vec::from(crates);
134-
spec_pkgs.push("test".to_string());
134+
spec_pkgs.push("sysroot".to_string());
135135
let spec = Packages::Packages(spec_pkgs);
136136
let specs = spec.to_package_id_specs(&std_ws)?;
137137
let features = match &config.cli_unstable().build_std_features {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "sysroot"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
[dependencies]
7+
proc_macro = { path = "../proc_macro" }
8+
std = { path = "../std" }
9+
test = { path = "../test" }
10+
11+
[features]
12+
panic-unwind = []
13+
backtrace = []
14+
feature1 = ["std/feature1"]
15+
default = []
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Intentionally left blank.

tests/testsuite/mock-std/library/test/Cargo.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@ authors = ["Alex Crichton <alex@alexcrichton.com>"]
55
edition = "2018"
66

77
[dependencies]
8-
proc_macro = { path = "../proc_macro" }
98
std = { path = "../std" }
109
panic_unwind = { path = "../panic_unwind" }
1110
compiler_builtins = { path = "../compiler_builtins" }
1211
registry-dep-using-std = { version = "*", features = ['mockbuild'] }
13-
14-
[features]
15-
panic-unwind = []
16-
backtrace = []
17-
feature1 = ["std/feature1"]
18-
default = []

0 commit comments

Comments
 (0)