Skip to content

Commit da8138e

Browse files
committed
fix(build-std): remove hack on creating virtual std workspace
Starting from rust-lang/rust#128534 (nightly-2024-08-05), stnadard library has its own Cargo workspace. Hence `-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
1 parent 9af3930 commit da8138e

File tree

3 files changed

+14
-61
lines changed

3 files changed

+14
-61
lines changed

src/cargo/core/compiler/standard_lib.rs

+3-53
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ use crate::core::compiler::{CompileKind, CompileMode, RustcTargetData, Unit};
66
use crate::core::profiles::{Profiles, UnitFor};
77
use crate::core::resolver::features::{CliFeatures, FeaturesFor, ResolvedFeatures};
88
use crate::core::resolver::HasDevUnits;
9-
use crate::core::{Dependency, PackageId, PackageSet, Resolve, SourceId, Workspace};
9+
use crate::core::{PackageId, PackageSet, Resolve, Workspace};
1010
use crate::ops::{self, Packages};
1111
use crate::util::errors::CargoResult;
1212
use crate::GlobalContext;
1313
use std::collections::{HashMap, HashSet};
1414
use std::path::PathBuf;
15-
use std::rc::Rc;
1615

1716
use super::BuildConfig;
1817

@@ -74,60 +73,11 @@ pub fn resolve_std<'gctx>(
7473
}
7574

7675
let src_path = detect_sysroot_src_path(target_data)?;
77-
let to_patch = [
78-
"rustc-std-workspace-core",
79-
"rustc-std-workspace-alloc",
80-
"rustc-std-workspace-std",
81-
];
82-
let patches = to_patch
83-
.iter()
84-
.map(|&name| {
85-
let source_path = SourceId::for_path(&src_path.join("library").join(name))?;
86-
let dep = Dependency::parse(name, None, source_path)?;
87-
Ok(dep)
88-
})
89-
.collect::<CargoResult<Vec<_>>>()?;
90-
let crates_io_url = crate::sources::CRATES_IO_INDEX.parse().unwrap();
91-
let patch = HashMap::from([(crates_io_url, patches)]);
92-
let members = vec![
93-
String::from("library/std"),
94-
String::from("library/core"),
95-
String::from("library/alloc"),
96-
String::from("library/sysroot"),
97-
];
98-
let ws_config = crate::core::WorkspaceConfig::Root(crate::core::WorkspaceRootConfig::new(
99-
&src_path,
100-
&Some(members),
101-
/*default_members*/ &None,
102-
/*exclude*/ &None,
103-
/*inheritable*/ &None,
104-
/*custom_metadata*/ &None,
105-
));
106-
let virtual_manifest = crate::core::VirtualManifest::new(
107-
Rc::default(),
108-
Rc::new(toml_edit::ImDocument::parse("".to_owned()).expect("empty is valid TOML")),
109-
Rc::default(),
110-
Rc::default(),
111-
/*replace*/ Vec::new(),
112-
patch,
113-
ws_config,
114-
crate::core::Features::default(),
115-
None,
116-
);
117-
76+
let std_ws_manifest_path = src_path.join("library").join("Cargo.toml");
11877
let gctx = ws.gctx();
119-
// This is a delicate hack. In order for features to resolve correctly,
120-
// the resolver needs to run a specific "current" member of the workspace.
121-
// Thus, in order to set the features for `std`, we need to set `sysroot`
122-
// to be the "current" member. `sysroot` is the root, and all other
123-
// standard library crates are dependencies from there. Since none of the
124-
// other crates need to alter their features, this should be fine, for
125-
// now. Perhaps in the future features will be decoupled from the resolver
126-
// and it will be easier to control feature selection.
127-
let current_manifest = src_path.join("library/sysroot/Cargo.toml");
12878
// TODO: Consider doing something to enforce --locked? Or to prevent the
12979
// lock file from being written, such as setting ephemeral.
130-
let mut std_ws = Workspace::new_virtual(src_path, current_manifest, virtual_manifest, gctx)?;
80+
let mut std_ws = Workspace::new(&std_ws_manifest_path, gctx)?;
13181
// Don't require optional dependencies in this workspace, aka std's own
13282
// `[dev-dependencies]`. No need for us to generate a `Resolve` which has
13383
// those included because we'll never use them anyway.

tests/testsuite/mock-std/Cargo.toml

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[workspace]
2+
resolver = "1"
3+
members = [
4+
"std",
5+
"sysroot",
6+
]
7+
8+
[patch.crates-io]
9+
rustc-std-workspace-core = { path = 'rustc-std-workspace-core' }
10+
rustc-std-workspace-alloc = { path = 'rustc-std-workspace-alloc' }
11+
rustc-std-workspace-std = { path = 'rustc-std-workspace-std' }

0 commit comments

Comments
 (0)