Skip to content

Commit eae2cbf

Browse files
committed
Enable Cargo's new build-dir layout in boostrap
1 parent 27dbdb5 commit eae2cbf

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,16 +2644,18 @@ pub enum ArtifactKeepMode {
26442644

26452645
pub fn run_cargo(
26462646
builder: &Builder<'_>,
2647-
cargo: Cargo,
2647+
mut cargo: Cargo,
26482648
tail_args: Vec<String>,
26492649
stamp: &BuildStamp,
26502650
additional_target_deps: Vec<(PathBuf, DependencyType)>,
26512651
artifact_keep_mode: ArtifactKeepMode,
26522652
) -> Vec<PathBuf> {
2653+
cargo.arg("-Zbuild-dir-new-layout");
2654+
26532655
// `target_root_dir` looks like $dir/$target/release
26542656
let target_root_dir = stamp.path().parent().unwrap();
2655-
// `target_deps_dir` looks like $dir/$target/release/deps
2656-
let target_deps_dir = target_root_dir.join("deps");
2657+
// `target_build_dir` looks like $dir/$target/release/build
2658+
let target_build_dir = target_root_dir.join("build");
26572659
// `host_root_dir` looks like $dir/release
26582660
let host_root_dir = target_root_dir
26592661
.parent()
@@ -2724,7 +2726,7 @@ pub fn run_cargo(
27242726

27252727
// If this was output in the `deps` dir then this is a precise file
27262728
// name (hash included) so we start tracking it.
2727-
if filename.starts_with(&target_deps_dir) {
2729+
if filename.starts_with(&target_build_dir) {
27282730
deps.push((filename.to_path_buf(), DependencyType::Target));
27292731
continue;
27302732
}
@@ -2759,11 +2761,18 @@ pub fn run_cargo(
27592761

27602762
// Ok now we need to actually find all the files listed in `toplevel`. We've
27612763
// got a list of prefix/extensions and we basically just need to find the
2762-
// most recent file in the `deps` folder corresponding to each one.
2763-
let contents = target_deps_dir
2764+
// most recent file in the `build` folder corresponding to each one.
2765+
//
2766+
// Cargo's build folder is structured as `build/<pkg>/<hash>/out/<artifacts>` so
2767+
// we need to traverse multiple directory layers to get to actual files.
2768+
let read_dir = |path: &Path| path.read_dir().ok().into_iter().flatten().filter_map(Result::ok);
2769+
let contents = target_build_dir
27642770
.read_dir()
2765-
.unwrap_or_else(|e| panic!("Couldn't read {}: {}", target_deps_dir.display(), e))
2766-
.map(|e| t!(e))
2771+
.unwrap_or_else(|e| panic!("Couldn't read {}: {}", target_build_dir.display(), e))
2772+
.map(|e| e.unwrap())
2773+
.flat_map(|e| read_dir(&e.path()))
2774+
.flat_map(|e| read_dir(&e.path()))
2775+
.flat_map(|e| read_dir(&e.path()))
27672776
.map(|e| (e.path(), e.file_name().into_string().unwrap(), t!(e.metadata())))
27682777
.collect::<Vec<_>>();
27692778
for (prefix, extension, expected_len) in toplevel {

0 commit comments

Comments
 (0)