Skip to content

Commit

Permalink
Auto merge of #12088 - weihanglo:build-std-fix, r=epage
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed May 5, 2023
2 parents 2d693e2 + 3df35ed commit b0f118f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/cargo/core/compiler/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn resolve_std<'cfg>(
String::from("library/std"),
String::from("library/core"),
String::from("library/alloc"),
String::from("library/test"),
String::from("library/sysroot"),
];
let ws_config = crate::core::WorkspaceConfig::Root(crate::core::WorkspaceRootConfig::new(
&src_path,
Expand All @@ -114,24 +114,24 @@ pub fn resolve_std<'cfg>(
let config = ws.config();
// This is a delicate hack. In order for features to resolve correctly,
// the resolver needs to run a specific "current" member of the workspace.
// Thus, in order to set the features for `std`, we need to set `libtest`
// to be the "current" member. `libtest` is the root, and all other
// Thus, in order to set the features for `std`, we need to set `sysroot`
// to be the "current" member. `sysroot` is the root, and all other
// standard library crates are dependencies from there. Since none of the
// other crates need to alter their features, this should be fine, for
// now. Perhaps in the future features will be decoupled from the resolver
// and it will be easier to control feature selection.
let current_manifest = src_path.join("library/test/Cargo.toml");
let current_manifest = src_path.join("library/sysroot/Cargo.toml");
// TODO: Consider doing something to enforce --locked? Or to prevent the
// lock file from being written, such as setting ephemeral.
let mut std_ws = Workspace::new_virtual(src_path, current_manifest, virtual_manifest, config)?;
// Don't require optional dependencies in this workspace, aka std's own
// `[dev-dependencies]`. No need for us to generate a `Resolve` which has
// those included because we'll never use them anyway.
std_ws.set_require_optional_deps(false);
// `test` is not in the default set because it is optional, but it needs
// to be part of the resolve in case we do need it.
// `sysroot` is not in the default set because it is optional, but it needs
// to be part of the resolve in case we do need it or `libtest`.
let mut spec_pkgs = Vec::from(crates);
spec_pkgs.push("test".to_string());
spec_pkgs.push("sysroot".to_string());
let spec = Packages::Packages(spec_pkgs);
let specs = spec.to_package_id_specs(&std_ws)?;
let features = match &config.cli_unstable().build_std_features {
Expand Down
15 changes: 15 additions & 0 deletions tests/testsuite/mock-std/library/sysroot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "sysroot"
version = "0.1.0"
edition = "2018"

[dependencies]
proc_macro = { path = "../proc_macro" }
std = { path = "../std" }
test = { path = "../test" }

[features]
panic-unwind = []
backtrace = []
feature1 = ["std/feature1"]
default = []
1 change: 1 addition & 0 deletions tests/testsuite/mock-std/library/sysroot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Intentionally left blank.
7 changes: 0 additions & 7 deletions tests/testsuite/mock-std/library/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ authors = ["Alex Crichton <[email protected]>"]
edition = "2018"

[dependencies]
proc_macro = { path = "../proc_macro" }
std = { path = "../std" }
panic_unwind = { path = "../panic_unwind" }
compiler_builtins = { path = "../compiler_builtins" }
registry-dep-using-std = { version = "*", features = ['mockbuild'] }

[features]
panic-unwind = []
backtrace = []
feature1 = ["std/feature1"]
default = []

0 comments on commit b0f118f

Please sign in to comment.