Skip to content

Reorganize build unit directory layout for new build-dir layout#16542

Merged
epage merged 5 commits intorust-lang:masterfrom
ranger-ross:layout-rename-dirs
Feb 11, 2026
Merged

Reorganize build unit directory layout for new build-dir layout#16542
epage merged 5 commits intorust-lang:masterfrom
ranger-ross:layout-rename-dirs

Conversation

@ranger-ross
Copy link
Member

What does this PR try to resolve?

This PR makes more changes to the new build-dir layout as discussed in #16502 (comment).

The goal here is to have more general (and thus reusable) directories in the build unit structure.

Layout changes

  1. Rename {build-unit-dir}/deps to {build-unit-dir}/out
  2. Moved build-script OUT_DIR from {build-unit-dir}/build-script/out to {build-unit-dir}/out
  3. Renamed {build-unit-dir}/build-script to {build-unit-dir}/run
    • This makes the dir more general to any build unit that can execute an external process. (but currently only build-scripts use it)

The resulting structure looks like

build-dir/debug/build/<pkgname>/<HASH>
    fingerprint/
    out/
    run/
    .lock

Part of #15010

How to test and review this PR?

See the test updates included in each commit

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-build-scripts Area: build.rs scripts A-layout Area: target output directory layout, naming, and organization S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 22, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 22, 2026

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Comment on lines -282 to +287
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo[..][EXE]
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo[..].d
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/out/foo.txt
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/out/build_script_build[..].d
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/out/build_script_build[..][EXE]
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/out/build-script-build[EXE]
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/out/foo[..][EXE]
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/out/foo[..].d
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note on the diffs here: Now that both the build-script and build units use the same directory we run into the issue of

foo/[HASH]/out/foo[..][EXE]

matching foo.txt that is output from the build-script.

To solve this I moved the foo.txt before the foo[..][EXE] line so it would be matched earlier.
But after doing that I felt the order of the files was mislead as it makes it look like foo.txt and foo.txt are in the same directory which they are not. (HASH is different)
So I also moved the other build script files in hopes that it might be a bit more clear.

@weihanglo
Copy link
Member

weihanglo commented Jan 22, 2026

   error: unsupported rustdoc format v57 for file: /home/runner/work/cargo/cargo/target/semver-checks/local-build_rs-0_3_3-default-01666ec060466c14/target/doc/build_rs.json
  (supported formats are v53, v55, v56)

cargo-semver-checks already supported rustdoc JSON v57 but not yet released

But the check-version-bump job is not blocking. The issue is the other docs job failure.

/// New features should consider using this so we can avoid their migrations.
pub fn deps_new_layout(&self, pkg_dir: &str) -> PathBuf {
self.build_unit(pkg_dir).join("deps")
pub fn output(&self, pkg_dir: &str) -> PathBuf {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this output and not out?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I had original named them output but then changed the named to out and forgot to update this one.
Will change to out

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still seeing some output_dirs present

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is expected.

Note that there are 2 functions in CompilationFiles relevant in this PR:

  1. fn output_dir() -- (was previously out_dir) that gets the output path over many different types of units.
    • I renamed this in the first commit to 1) avoid confusion as it does NOT always point to the out dir in both the new and old layouts and 2) I wanted to use out_dir as the fn name for the path that does lead to the out dir.
    • I am up for renaming this fn to something else to make it even less confusing. I couldn't come up with anything more descriptive than "output" since its quiet general.
  2. fn out_dir() -- (previous fn deps_dir) points to target/<profile>/build/<build-unit>/out in the new layout and /target/<profile>/deps

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@weihanglo
Copy link
Member

See cd39acf in commit history. Rebase got messed up?

@ranger-ross
Copy link
Member Author

ahhh yeah, I think I did an --amend when I shouldn't have 🤦‍♂️

@rustbot

This comment has been minimized.

@ranger-ross
Copy link
Member Author

@epage gentle reminder this PR is waiting on review
Would appreciate if you could take a look when convenient.
Thanks

@epage
Copy link
Contributor

epage commented Feb 6, 2026

Still working through everything from when my family was sick.

Rename `fn out_dir` to `fn output_dir` to avoid naming collisions in
future layout changes.
Previously `deps` was only the compiler output. This commit renames it
to `out` to make it more general to any kind of build output.

The build script OUT_DIR will eventually be merged into this directory.
This was previously indirectly created by `OUT_DIR`, however in the
future `OUT_DIR` will not be nested in the build-script run dir so we
always want to create it.
This commit moves the build-script OUT_DIR location from `{build-unit-dir}/build-script-execution/out`
to `{build-unit-dir}/out` dir (that was previously `{build-unit-dir}/deps`)
This commit changes the build script execution dir from `{build-unit-dir}/build-script`
to `{build-unit-dir}/run`. The motivation behind this is to have a
general directory for units that execute some binary/external process
and output to stdout/err. Currently this is only used by build-scripts
but could be expanded in the future.
@rustbot
Copy link
Collaborator

rustbot commented Feb 11, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@epage epage added this pull request to the merge queue Feb 11, 2026
Merged via the queue into rust-lang:master with commit b79b1d4 Feb 11, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 11, 2026
rust-bors bot pushed a commit to rust-lang/rust that referenced this pull request Feb 12, 2026
Update cargo submodule

8 commits in 0c9e687d237ff04b53ccb67b4ce63e9483789e88..ce69df6f72a3b6a2b5c722ba68ddef255344b31c
2026-02-11 05:58:30 +0000 to 2026-02-12 12:39:45 +0000
- fix: apply `host.runner` only when `host-config` enabled (rust-lang/cargo#16631)
- fix(cli): Improve bad manifest error  (rust-lang/cargo#16630)
- fix: Adjust casing of error message (rust-lang/cargo#16625)
- Enable triagebot new `[view-all-comments-link]` feature (rust-lang/cargo#16629)
- test(help): snapshot cargo help tests (rust-lang/cargo#16626)
- Suggest a `workspace.members` entry even from outside the workspace root (rust-lang/cargo#16616)
- Reorganize build unit directory layout for new build-dir layout (rust-lang/cargo#16542)
- Make the error messaging for `cargo install` aware of `build.build-dir` (rust-lang/cargo#16623)
@rustbot rustbot added this to the 1.95.0 milestone Feb 12, 2026
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Feb 13, 2026
Update cargo submodule

8 commits in 0c9e687d237ff04b53ccb67b4ce63e9483789e88..ce69df6f72a3b6a2b5c722ba68ddef255344b31c
2026-02-11 05:58:30 +0000 to 2026-02-12 12:39:45 +0000
- fix: apply `host.runner` only when `host-config` enabled (rust-lang/cargo#16631)
- fix(cli): Improve bad manifest error  (rust-lang/cargo#16630)
- fix: Adjust casing of error message (rust-lang/cargo#16625)
- Enable triagebot new `[view-all-comments-link]` feature (rust-lang/cargo#16629)
- test(help): snapshot cargo help tests (rust-lang/cargo#16626)
- Suggest a `workspace.members` entry even from outside the workspace root (rust-lang/cargo#16616)
- Reorganize build unit directory layout for new build-dir layout (rust-lang/cargo#16542)
- Make the error messaging for `cargo install` aware of `build.build-dir` (rust-lang/cargo#16623)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-build-execution Area: anything dealing with executing the compiler A-build-scripts Area: build.rs scripts A-layout Area: target output directory layout, naming, and organization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants