Description
This is about the unstable -Zpackage-workspace
feature. Discussion branched from #1169 (comment).
Problem
In a large workspace, there might be many packages to publish, and many packages that should not be published (for development only, or applications that are distributed by means other than Cargo). cargo publish -Zpackage-workspace
will attempt to publish the workspace’s default members, whether or not they are marked unpublishable with package.publish = false
, and error out if any of them are.
This seems to me a missing feature; it should be possible to choose to use package.publish
metadata to control whether a package is selected for publishing.
Proposed Solution
-
Alternative 1: Add a new flag (with what name?) which selects packages, from members or default-members, as follows:
- If a package has
package.publish = false
, it is not selected. - If a package has
package.publish = true
, it is selected. - If neither of the above applies, error out and do not publish anything.
This flag would be compatible with
--workspace
but incompatible with--package
.This version encourages workspace authors to explicitly think about whether each package should be published if they wish to use this feature, which seems to me the best outcome. However, it gives new semantics to
package.publish = true
, which was previously identical to the field being absent. I think this is a good thing (publishing should be more opt-in, since it is close to irrevocable), but it would be new. - If a package has
-
Alternative 2: Add a new flag
--exclude-unpublishable
.- if a package was selected due to being in
default-members
or due to--workspace
being passed, and it haspackage.publish = false
, then it is excluded from selection as if by--exclude
. - If a package was selected by
--package
and it haspackage.publish = false
, this is still an error.
- if a package was selected due to being in
-
Alternative 3: Automatically skip
publish = false
packages without any specific flag.This might be too “DWIM” but it is the behavior I was implicitly expecting when I tried out
-Zpackage-workspace
for the first time.
Notes
In the status quo, it would be possible to use the workspace’s default-members
to control which packages are published. I think this is not sufficient, because default-members
should be a package selection which is appropriate for routine development, which will usually be much more common than publishing. In particular, a package whose job is entirely tests should not be published, but should be run by default with cargo test
.
@rustbot label +Z-package-workspace
Activity