From 0aa2680ac1dbc6c4eae5626bffb7cc847aa159b4 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Mon, 5 Aug 2024 23:22:35 -0400 Subject: [PATCH] fix(build-std): Starting from rust-lang/rust#128534 (nightly-2024-08-05), stnadard library has its own Cargo workspace. `-Zbuild-std` no longer need to fake a virtual workspace. This also adjusts Cargo.toml in `mock-std` to align with std's Cargo.toml --- src/cargo/core/compiler/standard_lib.rs | 56 ++------------------- tests/testsuite/mock-std/Cargo.toml | 8 --- tests/testsuite/mock-std/library/Cargo.toml | 11 ++++ 3 files changed, 14 insertions(+), 61 deletions(-) delete mode 100644 tests/testsuite/mock-std/Cargo.toml create mode 100644 tests/testsuite/mock-std/library/Cargo.toml diff --git a/src/cargo/core/compiler/standard_lib.rs b/src/cargo/core/compiler/standard_lib.rs index 8b24cf7cdcbe..92b3474d3f00 100644 --- a/src/cargo/core/compiler/standard_lib.rs +++ b/src/cargo/core/compiler/standard_lib.rs @@ -6,13 +6,12 @@ use crate::core::compiler::{CompileKind, CompileMode, RustcTargetData, Unit}; use crate::core::profiles::{Profiles, UnitFor}; use crate::core::resolver::features::{CliFeatures, FeaturesFor, ResolvedFeatures}; use crate::core::resolver::HasDevUnits; -use crate::core::{Dependency, PackageId, PackageSet, Resolve, SourceId, Workspace}; +use crate::core::{PackageId, PackageSet, Resolve, Workspace}; use crate::ops::{self, Packages}; use crate::util::errors::CargoResult; use crate::GlobalContext; use std::collections::{HashMap, HashSet}; use std::path::PathBuf; -use std::rc::Rc; use super::BuildConfig; @@ -74,60 +73,11 @@ pub fn resolve_std<'gctx>( } let src_path = detect_sysroot_src_path(target_data)?; - let to_patch = [ - "rustc-std-workspace-core", - "rustc-std-workspace-alloc", - "rustc-std-workspace-std", - ]; - let patches = to_patch - .iter() - .map(|&name| { - let source_path = SourceId::for_path(&src_path.join("library").join(name))?; - let dep = Dependency::parse(name, None, source_path)?; - Ok(dep) - }) - .collect::>>()?; - let crates_io_url = crate::sources::CRATES_IO_INDEX.parse().unwrap(); - let patch = HashMap::from([(crates_io_url, patches)]); - let members = vec![ - String::from("library/std"), - String::from("library/core"), - String::from("library/alloc"), - String::from("library/sysroot"), - ]; - let ws_config = crate::core::WorkspaceConfig::Root(crate::core::WorkspaceRootConfig::new( - &src_path, - &Some(members), - /*default_members*/ &None, - /*exclude*/ &None, - /*inheritable*/ &None, - /*custom_metadata*/ &None, - )); - let virtual_manifest = crate::core::VirtualManifest::new( - Rc::default(), - Rc::new(toml_edit::ImDocument::parse("".to_owned()).expect("empty is valid TOML")), - Rc::default(), - Rc::default(), - /*replace*/ Vec::new(), - patch, - ws_config, - crate::core::Features::default(), - None, - ); - + let std_ws_manifest_path = src_path.join("library").join("Cargo.toml"); let gctx = ws.gctx(); - // 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 `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/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, gctx)?; + let mut std_ws = Workspace::new(&std_ws_manifest_path, gctx)?; // 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. diff --git a/tests/testsuite/mock-std/Cargo.toml b/tests/testsuite/mock-std/Cargo.toml deleted file mode 100644 index a69aa4b88fa2..000000000000 --- a/tests/testsuite/mock-std/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[workspace] -members = [ - "library/alloc", - "library/core", - "library/proc_macro", - "library/std", - "library/test", -] diff --git a/tests/testsuite/mock-std/library/Cargo.toml b/tests/testsuite/mock-std/library/Cargo.toml new file mode 100644 index 000000000000..f44d7bef23a9 --- /dev/null +++ b/tests/testsuite/mock-std/library/Cargo.toml @@ -0,0 +1,11 @@ +[workspace] +resolver = "1" +members = [ + "std", + "sysroot", +] + +[patch.crates-io] +rustc-std-workspace-core = { path = 'rustc-std-workspace-core' } +rustc-std-workspace-alloc = { path = 'rustc-std-workspace-alloc' } +rustc-std-workspace-std = { path = 'rustc-std-workspace-std' }