Skip to content

Clean /out dir before compilation - #17675

Merged
weihanglo merged 2 commits into
rust-lang:masterfrom
ranger-ross:remove-out-dir-before-build
Nov 3, 2026
Merged

weihanglo merged 2 commits into
rust-lang:masterfrom
ranger-ross:remove-out-dir-before-build

Conversation

@ranger-ross

Copy link
Copy Markdown
Member

What does this PR try to resolve?

This PR cleans the build-dir/<profile>/build/<pkg>/<hash>/out for between each build.
This behavior already existing outputs (see #11122) but was explicit with which files it removed and lead to the rustc dep info files not being included in this. With the new build-dir layout, we can simplfiy this logic by just wiping the entire out directory instead of tracking and removing each output.

This is a precursor to #17453 as we want to prevent the risk of rustc writing to a hardlink saved in shared content addressible storage. #17512 will hopefully build on this work in the future.

Note this PR does not attempt to change the behavior for build scripts. I was unsure if proactively wiping the out dir for build scripts could lead to longer build times. (e.g. wiping a c projects cache instead of reusing the previous work)

Notes to reviewers

I'd suggest turn off whitespace while reviewing as most of the diffs are indenting.


🤖 LLM involvement:

r? @epage

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 2, 2026
@epage

epage commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

We'll eventually need to do this for build scripts. The question is whether we need to first introduce the temp dir or not. That doesn't make it blocking for this though.

Comment thread tests/testsuite/build.rs
.file("src/new.rs", "")
.build();

p.cargo("build")

@epage epage Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to build instead of check?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

its build to include the rlib in the assert_backup_unmodified(rlib) below.
it could be check, but it would no longer cover overwriting the rlib.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to cover every type of file or a representative set?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was trying to test all of the most common types like rmeta and rlib. But I'd imagine I did not exhaustively test it.

Do you think I am missing any file types that covering would be important?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In general, if we can get away with it, we prefer testing using check over build because build is slower and gets us closer to exhausting disk space in CI, so I'm wondering the other direction, if checking for a rmeta is good enough generally.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Personally I feel that explicitly checking that the rlib is unmodified in this test has value.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems fine to me. assert_backup_unmodified explicitly checks for rlib. That give an enough context.

This commit wipes the unit's out dir before we [re]build it to avoid
write to hardlinked files being used outside of build-dir.

The motivation for this commit is to prepare for deduplication for files
in the build-dir using shared content addressible storage. We want to
avoid overwriting a file that is hardlinked into the CAS.
@ranger-ross
ranger-ross force-pushed the remove-out-dir-before-build branch from 009c819 to 70f2154 Compare November 3, 2026 05:39
@rustbot

rustbot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

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.

Comment thread tests/testsuite/build.rs
.file("src/new.rs", "")
.build();

p.cargo("build")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems fine to me. assert_backup_unmodified explicitly checks for rlib. That give an enough context.

@weihanglo
weihanglo added this pull request to the merge queue Nov 3, 2026
Merged via the queue into rust-lang:master with commit 28c753a Nov 3, 2026
30 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 3, 2026
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Nov 4, 2026
Update cargo submodule

13 commits in 31d3246e0e8d3a80d4a90b54aa48ff180adb408b..3c747ea3ead23951c1b43a5edfcbdb449135ddeb
2026-10-27 13:54:39 +0000 to 2026-11-03 21:25:31 +0000
- Link to `cargo search` result's crates.io pages (rust-lang/cargo#17668)
- Clean `/out` dir before compilation  (rust-lang/cargo#17675)
- Allow `uncommon_codepoints` in confusable test (rust-lang/cargo#17676)
- test: Update https certificate failed messages (rust-lang/cargo#17679)
- chore(deps): update rust-lang/crates-io-auth-action action to v1.0.6 (rust-lang/cargo#17670)
- chore(deps): update actions/deploy-pages action to v5.0.1 (rust-lang/cargo#17669)
- Fix manifest schema generation: `TomlOptLevel` and `StringOrVec` (rust-lang/cargo#17660)
- remove deprecated tempdir (rust-lang/cargo#17663)
- chore(ci): remove Windows rustup PATH workaround (rust-lang/cargo#17667)
- test: probe stable cargo through rustup (rust-lang/cargo#17666)
- Update outdated registry function comments (rust-lang/cargo#17664)
- perf(windows): Delay-load system DLLs that most commands don't use (rust-lang/cargo#17623)
- Suppress `dead_code_pub_in_binary` for library test units (rust-lang/cargo#17608)
@rustbot rustbot added this to the 1.101.0 milestone Nov 4, 2026
RalfJung pushed a commit to JoJoDeveloping/miri that referenced this pull request Nov 8, 2026
Update cargo submodule

13 commits in 31d3246e0e8d3a80d4a90b54aa48ff180adb408b..3c747ea3ead23951c1b43a5edfcbdb449135ddeb
2026-10-27 13:54:39 +0000 to 2026-11-03 21:25:31 +0000
- Link to `cargo search` result's crates.io pages (rust-lang/cargo#17668)
- Clean `/out` dir before compilation  (rust-lang/cargo#17675)
- Allow `uncommon_codepoints` in confusable test (rust-lang/cargo#17676)
- test: Update https certificate failed messages (rust-lang/cargo#17679)
- chore(deps): update rust-lang/crates-io-auth-action action to v1.0.6 (rust-lang/cargo#17670)
- chore(deps): update actions/deploy-pages action to v5.0.1 (rust-lang/cargo#17669)
- Fix manifest schema generation: `TomlOptLevel` and `StringOrVec` (rust-lang/cargo#17660)
- remove deprecated tempdir (rust-lang/cargo#17663)
- chore(ci): remove Windows rustup PATH workaround (rust-lang/cargo#17667)
- test: probe stable cargo through rustup (rust-lang/cargo#17666)
- Update outdated registry function comments (rust-lang/cargo#17664)
- perf(windows): Delay-load system DLLs that most commands don't use (rust-lang/cargo#17623)
- Suppress `dead_code_pub_in_binary` for library test units (rust-lang/cargo#17608)
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants