cargo: cargo package --workspace is not very useful
Tracking
Unstable flag: -Zpackage-workspace
Stabilizing this would also close
Testing instructions: https://github.com/rust-lang/cargo/issues/10948#issuecomment-2540365225
Implementation
Changes since original plan
- Added
--registryand--indexflags tocargo packageto know what registry will be used for generating theCargo.lockfile as if the internal dependencies were already published cargo publishis not atomic but it does verify all before publish
Open questions
- Are we ok with a slight compatibility breakage in
cargo package? See https://github.com/rust-lang/cargo/issues/10948#issuecomment-2253530842 - Are we ok stabilizing this and #1169 at the same time? Currently, they are behind the same flag
- What is the desired behavior for the publish timeout? #14433 uploads the crates in batches (depending on the dependency graph), and we only timeout if nothing in the batch is available within the timeout, deferring the rest to the next wait-for-publish. So for example, if you have packages
a,b,cthen we’ll wait up to 60 seconds and if onlyaandbwere ready in that time, we’ll then wait another 60 seconds forc. - What is the desired behavior when publishing some packages in a workspace that have
publish = false? #14433 raises an error whenever any of the selected packages haspublish = false, so it will error oncargo publish --workspacein a workspace with an unpublishable package. An alternative interface would implicitly exclude unpublishable packages in this case, but still error out if you explicitly select an unpublishable package with-p package-name(see #14356). #14433 behavior is the most conservative one as it can change from an error to implicit excludes later.
Known issues
Non-blocking issues
Problem
Let’s say you have a workspace
workspace/
package_a/
Cargo.toml (name="a", version="0.1.0")
package_b/
Cargo.toml (name="a", version="0.1.0", [dependencies] a="0.1.0")
Cargo.toml (members = ["package_a","package_b"])
If you have already published a to crates.io, then cargo package --workspace will complete successfully.
Now, you update a to 0.1.1, and update b to use that new minimum version. If you try cargo package --workspace again, it will no longer work. You will get an error that 0.1.1 was not found.
This happens because cargo package makes a dummy package for your verification and it strips out all workspace and path information. This means it tries to retrieve the a 0.1.1 from the registry, which it fails to do.
Proposed Solution
If you have a workspace where some package b depends on another package a, where a is both specified by a version AND a path, AND that path is within the workspace members, then the following will happen:
cargo package --workspace
will make the new dummy project to verify the crates, but it will leave in the path information for a within b.
Notes
In my experience, I’ve never had a workspace where all crates are independent. There’s always at least one that depends on another crate. When managing private registries, it’s not uncommon to cargo package and upload the .crate file manually.
Currently, it’s necessary to package each workspace member individually and upload them in the order they depend.
Ideally, we can run a single
cargo package --workspace
after bumping all versions, then get all of the .crate files and upload them in a batch.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 7
- Comments: 28 (19 by maintainers)
Commits related to this issue
- Auto merge of #13926 - tweag:overlay, r=epage Add local registry overlays This PR adds (private to cargo internals) support for local registry overlays, in which you can locally pretend to add packa... — committed to rust-lang/cargo by bors 2 years ago
- Auto merge of #13947 - tweag:package-workspace, r=epage Package workspaces Adds support for packaging an entire workspace, even when there are dependencies between the crates. The generated packages... — committed to rust-lang/cargo by bors 2 years ago
- Auto merge of #14496 - tweag:cargo-package-doc, r=epage Document -Zpackage-workspace Adds some unstable documentation on the `-Zpackage-workspace` feature, as requested in [#10948](https://github.co... — committed to rust-lang/cargo by bors 2 years ago
- Auto merge of #14433 - tweag:multi-package-publishing-rebased, r=epage Publish workspace Adds support for simultaneously publishing multiple (possibly inter-dependent) packages in a workspace, gated... — committed to rust-lang/cargo by bors 2 years ago
- fix(publish): Report all unpublishable packages I didn't extend this to multiple packages restricted to specific registries. It seems less likely to be a problem and more complex to gather and report... — committed to epage/cargo by epage 2 years ago
- fix(publish): Report all unpublishable packages (#15070) ### What does this PR try to resolve? I didn't extend this to multiple packages restricted to specific registries. It seems less likely to be... — committed to rust-lang/cargo by weihanglo 2 years ago
- fix(package): Register workspace member renames in overlay This was reported at https://github.com/rust-lang/cargo/issues/10948#issuecomment-2674289330 I suspect there is a second bug here because m... — committed to epage/cargo by epage 2 years ago
- fix(package): Register workspace member renames in overlay This was reported at https://github.com/rust-lang/cargo/issues/10948#issuecomment-2674289330 I suspect there is a second bug here because m... — committed to epage/cargo by epage 2 years ago
- fix(package): Register workspace member renames in overlay This was reported at https://github.com/rust-lang/cargo/issues/10948#issuecomment-2674289330 I suspect there is a second bug here because m... — committed to epage/cargo by epage 2 years ago
- fix(package): Register workspace member renames in overlay (#15228) ### What does this PR try to resolve? This was reported at https://github.com/rust-lang/cargo/issues/10948#issuecomment-267428933... — committed to rust-lang/cargo by epage 2 years ago
- feat(publish): Stabilize multi-package publishing 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 p... — committed to epage/cargo by epage a year ago
- feat(publish): Stabilize multi-package publishing 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 p... — committed to epage/cargo by epage a year ago
- feat(publish): Stabilize multi-package publishing 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 p... — committed to epage/cargo by epage a year ago
- feat(publish): Stabilize multi-package publishing 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 p... — committed to epage/cargo by epage a year ago
- feat(publish): Stabilize multi-package publishing 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 p... — committed to epage/cargo by epage a year ago
- feat(publish): Stabilize multi-package publishing 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 p... — committed to epage/cargo by epage a year ago
- feat(publish): Stabilize multi-package publishing (#15636) ### What does this PR try to resolve? A user will now be able to use flags like `--workspace` with `cargo publish`. `cargo package` will no... — committed to rust-lang/cargo by weihanglo a year ago
Call for testing
cargo package --workspaceis now available and we’re looking for feedback to see if this can be stabilized!Basic steps:
Requirements:
Try
cargo package -Zpublic-dependencyin your existing workflows and with various combinations of multiple packages being selected (--workspace,--exclude,-p foo -p bar)In particular, consider
--dry-runworks?Please leave feedback on this issue
Got a fix for renamed packages at #15228.
This seems to be a relatively large feature in terms of lines of code. Should we have an unstable doc section under https://doc.rust-lang.org/nightly/cargo/reference/unstable.html for it?
Re-opening to track stabilization