Skip to content

feat(publish): Stabilize multi-package publishing #15636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2025

Conversation

epage
Copy link
Contributor

@epage epage commented Jun 5, 2025

What does this PR try to resolve?

A user will now be able to use flags like --workspace with cargo publish.
cargo package will now also work with those flags without having to pass --no-verify --exclude-lockfile.

Many release tools have come out that solve this problem. They will still need a lot of the logic that went into that for other parts of the release process.
However, a cargo-native solution allows for:

  • Verification during dry-run
  • Better strategies for waiting for the publish timeout

cargo publish is non-atomic at this time.
If there is a server side error, network error, or rate limit during the publish, the workspace will be left in a partially published state. Verification is done before any publishing so that won't affect things. There are multiple strategies we can employ for improving this over time, including

This includes support for --dry-run verification. As release tools didn't have a way to do this before, users may be surprised at how slow this is because a cargo build is done instead of a cargo check. This is being tracked in #14941.

This adds to cargo package the --registry and --index flags to help with resolving dependencies when depending on a package being packaged at that moment.
These flags are only needed when a cargo package --workspace operation would have failed before due to inability to find a locally created dependency.

Regarding the publish timeout, cargo publish --workspace publishes packages in batches and we only timeout if nothing in the batch has finished being published within the timeout, deferring the rest to the next wait-for-publish. So for example, if you have packages a, b, c then we'll wait up to 60 seconds and if only a and b were ready in that time, we'll then wait another 60 seconds for c.

During testing, users ran into issues with .crate checksums:

Fixes #1169
Fixes #10948

How to test and review this PR?

By stabilizing this, Cargo's behavior becomes dependent on an overlay registry.
When generating a lockfile or verifying a package, we overlay the locally generated .crate files on top of the registry so the registry appears as it would and everything works.
If there is a conflict with a version, the local version wins which is important for the dry-run mode of release tools as they won't have bumped the version yet.
Our concern for the overlay registry is dependency confusion attacks. Considering this is not accessible for general user operations, this should be fine.

@epage epage added the T-cargo Team: Cargo label Jun 5, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 5, 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 A-cli Area: Command-line interface, option parsing, etc. A-cli-help Area: built-in command-line help A-documenting-cargo-itself Area: Cargo's documentation A-interacts-with-crates.io Area: interaction with registries A-unstable Area: nightly unstable support Command-package Command-publish S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 5, 2025
@epage
Copy link
Contributor Author

epage commented Jun 5, 2025

@rfcbot fcp merge

See the PR description for details

@rfcbot
Copy link
Collaborator

rfcbot commented Jun 5, 2025

Team member @epage has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period An FCP proposal has started, but not yet signed off. disposition-merge FCP with intent to merge labels Jun 5, 2025
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Code change has no issues

@epage
Copy link
Contributor Author

epage commented Jun 9, 2025

I have gotten a reproduction case for 1 of the 2 checksum issues, see #15647.

Copy link

@re-masashi re-masashi left a comment

Choose a reason for hiding this comment

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

looks fine to me

@epage epage force-pushed the stabilize-workspace-package branch from a6c8597 to 5a2230e Compare June 23, 2025 20:15
@epage
Copy link
Contributor Author

epage commented Jun 27, 2025

As an update, #15647 is being fixed in #15711. Both are scoped only for cargo publish --dry-run and cargo package continues to error. Whether to error or not in cargo package is a workflow question.

Also, I forgot to note #15622 in the stabilization report. While it can be reproduced with consecutive cargo publish calls, making it not directly related to this stabilization, it is tied to the workflows that are used with this feature so I figured it is worth noting.

@rfcbot rfcbot added final-comment-period FCP — a period for last comments before action is taken and removed proposed-final-comment-period An FCP proposal has started, but not yet signed off. labels Jun 27, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented Jun 27, 2025

🔔 This is now entering its final comment period, as per the review above. 🔔

A user will now be able to use flags like `--workspace` with `cargo
publish`.
`cargo package` will now also work with those flags without having to
pass `--no-verify --exclude-lockfile`.

Many release tools have come out that solve this problem.
They will still need a lot of the logic that went into that for other
parts of the release process.
However, a cargo-native solution allows for:
- Verification during dry-run
- Better strategies for waiting for the publish timeout

`cargo publish` is non-atomic at this time.
If there is a server side error, network error, or rate limit during the publish,
the workspace will be left in a partially published state.
Verification is done before any publishing so that won't affect things.
There are multiple strategies we can employ for improving this over time,
including
- atomic publish
- `--idempotent` (rust-lang#13397)
- leave this to release tools to manage

This includes support for `--dry-run` verification.
As release tools didn't have a way to do this before,
users may be surprised at how slow this is because a `cargo build` is
done instead of a `cargo check`.  This is being tracked in rust-lang#14941.

This adds to `cargo package` the `--registry` and `--index` flags to
help with resolving dependencies when depending on a package being
packaged at that moment.
These flags are only needed when a `cargo package --workspace` operation
would have failed before due to inability to find a locally created
dependency.

Regarding the publish timeout, `cargo publish --workspace` publishes
packages in batches and we only timeout if nothing in the batch has
finished being published within the timeout, deferring the rest to the
next wait-for-publish. So for example, if you have packages `a`, `b`, `c` then
we'll wait up to 60 seconds and if only `a` and `b` were ready in that time,
we'll then wait another 60 seconds for `c`.

During testing, users ran into issues with `.crate` checksums that we've
not been able to reproduce since:
- rust-lang#1169 (comment)
- rust-lang#14396

By stabilizing this, Cargo's behavior becomes dependent on an overlay
registry.
When generating a lockfile or verifying a package, we overlay the
locally generated `.crate` files on top of the registry so the registry
appears as it would and everything works.
If there is a conflict with a version, the local version wins which is
important for the dry-run mode of release tools as they won't have
bumped the version yet.
Our concern for the overlay registry is dependency confusion attacks.
Considering this is not accessible for general user operations, this
should be fine.

Fixes rust-lang#1169
Fixes rust-lang#10948
@epage epage force-pushed the stabilize-workspace-package branch 2 times, most recently from 262ffc6 to d2f7220 Compare June 30, 2025 20:21
@rfcbot rfcbot added finished-final-comment-period FCP complete and removed final-comment-period FCP — a period for last comments before action is taken labels Jul 7, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented Jul 7, 2025

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@weihanglo weihanglo added this pull request to the merge queue Jul 7, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 7, 2025
@epage epage force-pushed the stabilize-workspace-package branch 2 times, most recently from 14f4057 to c8bf409 Compare July 7, 2025 21:03
@epage
Copy link
Contributor Author

epage commented Jul 7, 2025

@weihanglo CI is green again

@weihanglo weihanglo added this pull request to the merge queue Jul 7, 2025
Merged via the queue into rust-lang:master with commit 0322bdd Jul 7, 2025
24 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 7, 2025
bors added a commit to rust-lang/rust that referenced this pull request Jul 12, 2025
Update cargo

14 commits in 930b4f62cfcd1f0eabdb30a56d91bf6844b739bf..eabb4cd923deb73e714f7ad3f5234d68ca284dbe
2025-06-28 14:58:43 +0000 to 2025-07-09 22:07:55 +0000
- feat: Implementation and tests for `multiple-build-scripts` (rust-lang/cargo#15704)
- perf: Speed up TOML parsing by upgrading toml (rust-lang/cargo#15736)
- Mark cachelock tests that rely on interprocess blocking behaviour as unsupported on AIX. (rust-lang/cargo#15734)
- feat(publish): Stabilize multi-package publishing (rust-lang/cargo#15636)
- Update to Rust 2024 (rust-lang/cargo#15732)
- Clarify package ID specifications in SBOMs are fully qualified (rust-lang/cargo#15731)
- chore(deps): update cargo-semver-checks to v0.42.0 (rust-lang/cargo#15730)
- test: Switch config tests to use snapshots (rust-lang/cargo#15729)
- implement package feature unification (rust-lang/cargo#15684)
- chore: Upgrade dependencies (rust-lang/cargo#15722)
- Report valid file name when we can't find a build target for `name = "foo.rs"` (rust-lang/cargo#15707)
- chore(release): Publish build-rs on release (rust-lang/cargo#15708)
- Override `Cargo.lock` checksums when doing a dry-run `publish` (rust-lang/cargo#15711)
- test(rustfix): Update for nightly (rust-lang/cargo#15717)

r? ghost
@rustbot rustbot added this to the 1.90.0 milestone Jul 12, 2025
@epage epage deleted the stabilize-workspace-package branch July 17, 2025 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area: Command-line interface, option parsing, etc. A-cli-help Area: built-in command-line help A-documenting-cargo-itself Area: Cargo's documentation A-interacts-with-crates.io Area: interaction with registries A-unstable Area: nightly unstable support Command-package Command-publish disposition-merge FCP with intent to merge finished-final-comment-period FCP complete T-cargo Team: Cargo to-announce
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

cargo package --workspace is not very useful cargo publish multiple packages at once
5 participants