Skip to content

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

Comment on lines 283 to 285
pub fn out_dir(&self, unit: &Unit) -> PathBuf {
let dir = self.pkg_dir(unit);
self.layout(unit.kind).build_dir().deps(&dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this is going to get confusing with us sometimes calling deps out_dir or deps

Copy link
Member Author

Choose a reason for hiding this comment

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

err yeah, self.layout(...).build_dir().deps(...) should really be self.layout(...).build_dir().out(...).

This issue it that we already have an BuildDirLayout::out() that only supports the new layout.
I'll rename the current out() to out_force_new_layout() and deps() to out() that way everything is consistent

Comment on lines 397 to 403
pub fn build_script_out_dir(&self, unit: &Unit, is_new_layout: bool) -> PathBuf {
if is_new_layout {
self.out_dir(unit)
} else {
self.build_script_run_dir(unit).join("out")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

When implementing unstable features, I'd recommend considering the process for removal on stabilization. Here, we will delete this function and update all callers to call out_dir, removing the parameter as w do so. Instead, if we put the conditional in the caller, then it is just a matter of deleting 4 lines in each call site, with it being obvious what to do.

I feel like I'd just put this conditional in the caller so it becomes straighforward to identify that we need to delete one branch and exclusively call one function.

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, that works for me. I'll pull the feature flag out of this fn to the callsite.

@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 🤦‍♂️

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 Jan 25, 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.

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 S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants