Skip to content

Conversation

epage
Copy link
Contributor

@epage epage commented Sep 3, 2025

When target_dir == build_dir, ensure cargo publish doesn't put intermediate artifacts in the final artifact location of cargo package.

What does this PR try to resolve?

In #15910, users could identify that .crate files from cargo publish are not final artifacts by setting a custom build-dir. This extends that to all users, ie when build-dir = target-dir (the default currently), making it clear that these files are internal.

This also cleans things up by consolidating all of the uplifting logic and avoids dealing with overlapping target_dir and build_dir.

How to test and review this PR?

Notes

We could optimize this further by doing a rename and only doing a copy if that fails, effectively a rename_or_copy as opposed to our hardlink_or_copy we normally use for uplifting. The difference is that we don't do change tracking for .crate files but fully re-generate, so we don't benefit from keeping the .crate around in the original location.

When `target_dir == build_dir`, ensure `cargo publish` doesn't put
intermediate artifacts in the final artifact location of `cargo
package`.

If anyone was relying on this behavior of `cargo publish`, it will break
them.
We could avoid this and instead consider the location change to be part
of the opt-in of using `build-dir` (until we make it opt-out).
Note that we expect to be able to change the layouf of content written
to `build-dir` even if users aren't opting in.

On the other hand, this will help identify people relying on
intermediate artifacts.

While there aren't any performance benefits to this, it consolidates all
of the uplifting logic and avoids dealing with overlapping `target_dir`
and `build_dir`.
We could optimize this further by doing a `rename` and only doing a copy
if that fails.
@epage epage marked this pull request as draft September 3, 2025 18:24
@rustbot
Copy link
Collaborator

rustbot commented Sep 3, 2025

r? @weihanglo

rustbot has assigned @weihanglo.
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

@rustbot rustbot added Command-package S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 3, 2025
Comment on lines +163 to +164
let dir = ws.build_dir().join("package").join("tmp-crate");
let dst = dir.open_rw_exclusive_create(&filename, gctx, "package scratch space")?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As this will cause a behavior change, Ive marked this as a draft while we wait for #15910 to propagate to users so they can prepare.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Command-package 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.

3 participants