Skip to content

cargo package and cargo publish order of registry selection differ from documentation #14958

Open
@YutaoMa

Description

@YutaoMa

Problem

The Cargo book explains that for cargo publish / cargo package commands, the order by which it decides which registry to publish to is as follows:

  1. --registry CLI arg
  2. package.publish field in Cargo.toml if a single entry
  3. otherwise registry.default key in config

However the current code checks registry.default prior to the manifest file. This causes error like below when both registry.default and package.publish are specified, and no CLI arg is supplied.

% cargo package
error: `demo-registry` cannot be packaged.
The registry `crates-io` is not listed in the `package.publish` value in Cargo.toml

Steps

  1. cargo new demo-registry
  2. In .cargo/config.toml [registry] add default = "crates-io" and some alternative registry
  3. In Cargo.toml [package] add publish = ["some alternative registry"]
  4. Both cargo package and cargo publish fails

Possible Solution(s)

Not sure which is the intended behavior, can either update the code or the documentation. It would be useful to let each crate's own manifest file decide the registry in a workspace setting, so switching the order in code might be better. I tried this change to move default config check after manifest infer and it now works as documented: YutaoMa#1

Notes

No response

Version

cargo 1.83.0 (5ffbef321 2024-10-29)
release: 1.83.0
commit-hash: 5ffbef3211a8c378857905775a15c5b32a174d3b
commit-date: 2024-10-29
host: aarch64-apple-darwin
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.7.1 (sys:0.4.74+curl-8.9.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Mac OS 15.2.0 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions