Skip to content

fix: strip OUT_DIR from the object file name hash too - #1902

Merged
NobodyXu merged 2 commits into
rust-lang:mainfrom
windsunil:out-dir-object-name-reproducibility
Sep 15, 2026
Merged

NobodyXu merged 2 commits into
rust-lang:mainfrom
windsunil:out-dir-object-name-reproducibility

Conversation

@windsunil

Copy link
Copy Markdown
Contributor

Fixes #1901

objects_from_files hashes the source dir into the object name and strips CARGO_MANIFEST_DIR first (#1270). A source a build script writes into OUT_DIR is not under the manifest dir when the target dir is elsewhere, so the absolute path still goes into the hash. This strips OUT_DIR first and falls back to CARGO_MANIFEST_DIR; in-tree sources are unaffected.

Repro from the issue, before/after:

1.4.6:  e8a56c71b9820449-gen.o   334cae97e1210068-gen.o
fixed:  db3b6bfb95261072-gen.o   db3b6bfb95261072-gen.o

The new test fails on 1.4.6 and passes with this change. #1277 was an earlier attempt at the same thing, closed as covered by #1270.

rust-lang#1270 made the hash relative to CARGO_MANIFEST_DIR, but sources a build
script writes into OUT_DIR are not under the manifest dir when the
target dir is somewhere else, so the absolute OUT_DIR still ends up in
the hash and the object name changes with the build location.
compiler-builtins hits this with its generated lse_*.S on distro builds
and libcompiler_builtins comes out different per build path.

Try OUT_DIR first, then CARGO_MANIFEST_DIR. Adds a test that builds the
same source under two OUT_DIRs and checks the object name matches.

Fixes rust-lang#1901

Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>

@NobodyXu NobodyXu left a comment

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.

Thank you just one minor nit

Comment thread src/command_helpers.rs
Review suggestion from NobodyXu: have the closure produce the Cow
directly instead of wrapping at every call site. Kept the Option on
the outside so it type-checks, and the call site becomes an
or_else/unwrap_or chain.

@NobodyXu NobodyXu left a comment

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.

Thank you! LGTM

@NobodyXu
NobodyXu merged commit fe27e7b into rust-lang:main Sep 15, 2026
81 checks passed
@github-actions github-actions Bot mentioned this pull request Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Object names still hash the absolute OUT_DIR for generated sources (gap in #1270)

2 participants