Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hack around libsysroot instead of libtest #12088

Merged
merged 1 commit into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <alex@alexcrichton.com>"]
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 = []