cargo: `-Zpackage-workspace` is not smart about `publish = false`
Problem
I was hoping to include -Zpackage-workspace as part of a workspace’s CI so that it doesn’t repeat certain embarrassing mistakes, but it didn’t work as expected with respect to certain crates that have publish = false on them.
Steps
After bumping the versions of all packages I wished to publish a new release for, I used this on the workspace with the following command:
$ cargo +nightly package --workspace -Zpackage-workspace
Locking 7 packages to latest compatible versions
Updating cargo-pgrx v0.12.0-beta.3 (/home/jubilee/tcdi/pgrx/cargo-pgrx) -> v0.12.0-beta.4
Updating pgrx v0.12.0-beta.3 (/home/jubilee/tcdi/pgrx/pgrx) -> v0.12.0-beta.4
Updating pgrx-macros v0.12.0-beta.3 (/home/jubilee/tcdi/pgrx/pgrx-macros) -> v0.12.0-beta.4
Updating pgrx-pg-config v0.12.0-beta.3 (/home/jubilee/tcdi/pgrx/pgrx-pg-config) -> v0.12.0-beta.4
Updating pgrx-pg-sys v0.12.0-beta.3 (/home/jubilee/tcdi/pgrx/pgrx-pg-sys) -> v0.12.0-beta.4
Updating pgrx-sql-entity-graph v0.12.0-beta.3 (/home/jubilee/tcdi/pgrx/pgrx-sql-entity-graph) -> v0.12.0-beta.4
Updating pgrx-tests v0.12.0-beta.3 (/home/jubilee/tcdi/pgrx/pgrx-tests) -> v0.12.0-beta.4
error: `aggregate` cannot be packaged.
The registry `crates-io` is not listed in the `package.publish` value in Cargo.toml.
Possible Solution(s)
This seems a curious error, given that this is intentional? I wish to not publish that crate and thus do not wish to package it for publishing?
Cargo has the option of doing the “smart” thing (“What I mean”) here and simply ignoring such packages. The other obvious alternative is that it can simply continue to fail-fast, but if so it should probably have a more helpful error message. Note these are “leaf” packages on which nothing depends, so automatically excluding them would work.
Notes
I do have the option of simply removing it from the workspace, but it all gets a bit awkward. To complicate matters further, these packages being in the workspace does affect feature resolution which also affects whether or not basic cargo check or cargo test work (as the library is one of those “you must enable one and only one of these features” sorts).
Related:
Version
cargo 1.82.0-nightly (b5d44db1d 2024-07-26)
release: 1.82.0-nightly
commit-hash: b5d44db1daf0469b227a6211b987162a39a54730
commit-date: 2024-07-26
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.8.0-DEV (sys:0.4.73+curl-8.8.0 vendored ssl:OpenSSL/3.3.1)
ssl: OpenSSL 3.3.1 4 Jun 2024
os: Arch Linux Rolling Release [64-bit]
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (15 by maintainers)
Commits related to this issue
- Test that pgrx can build after publishing (#1796) Test that pgrx will always build after we publish it. It should never again take an excessive amount of time to release pgrx, because we will alway... — committed to pgcentralfoundation/pgrx by workingjubilee 2 years ago
- Auto merge of #14408 - tweag:infer-registry-ignore-unpublishable, r=epage Be more permissive while packaging unpublishable crates. This PR allows for packaging workspaces that include `publish = fal... — 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
- Test that pgrx can build after publishing (#1796) Test that pgrx will always build after we publish it. It should never again take an excessive amount of time to release pgrx, because we will alway... — committed to tensorchord/pgrx by workingjubilee 2 years ago
I carried out the repo refactoring I mentioned. Obviously, what I “really want” is
cargo publsih --workspace --dry-run, but that doesn’t exist today. That day seems like a long way off. Even if it suddenly exists, and works as expected, it seemed likely I would be frustrated by it for other reasons with my current half-published half-not workspace. Thus the refactoring seemed useful, even if some details wound up quite gnarly.For now, I am quite pleased that
cargo package --workspace(actuallycargo +nightly package --workspace -Zpackage-workspacebut whatever) seems to now do exactly what I want it to do with this feature, as for a while now I have not had confidence that the pgrx repository can be released. This is both because of the whole “publishing an entire workspace isn’t an atomic step” thing, and also because some changes in Cargo.toml can break packaged code while not affecting the usual tests, thus creating the oddity of code that passes CI but does not work in its actual release. If I don’t pay close attention and notice that e.g. the docs.rs build is broken (which is a very indirect sign!), I can miss that happening. I want to do more repository-level refactoring, so having this in-place, and it being so easy… I thought I’d have to write my own non-integrated tooling, which is necessarily more verbose, and thus a slog… really helps.Because
publish = falseallowscargo packageto run today, we would need to maintain that. So in this case,cargo +nightly package --workspace -Zpackage-workspaceshould succeed with every workspace member packaged.