Skip to content

cargo publish should optionally skip unpublishable packages #15006

Open
@kpreid

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.

  • 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 has package.publish = false, then it is excluded from selection as if by --exclude.
    • If a package was selected by --package and it has package.publish = false, this is still an error.
  • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-publishS-triageStatus: This issue is waiting on initial triage.Z-package-workspaceNightly: package-workspace

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions