Skip to content

feat(publish): Stabilize multi-package publishing #15636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions src/bin/cargo/commands/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use cargo::ops::PackageOpts;
pub fn cli() -> Command {
subcommand("package")
.about("Assemble the local package into a distributable tarball")
.arg_index("Registry index URL to prepare the package for (unstable)")
.arg_registry("Registry to prepare the package for (unstable)")
.arg_index("Registry index URL to prepare the package for")
.arg_registry("Registry to prepare the package for")
.arg(
flag(
"list",
Expand Down Expand Up @@ -57,22 +57,6 @@ pub fn cli() -> Command {
}

pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
if args._value_of("registry").is_some() {
gctx.cli_unstable().fail_if_stable_opt_custom_z(
"--registry",
13947,
"package-workspace",
gctx.cli_unstable().package_workspace,
)?;
}
if args._value_of("index").is_some() {
gctx.cli_unstable().fail_if_stable_opt_custom_z(
"--index",
13947,
"package-workspace",
gctx.cli_unstable().package_workspace,
)?;
}
let reg_or_index = args.registry_or_index(gctx)?;
let ws = args.workspace(gctx)?;
if ws.root_maybe().is_embedded() {
Expand Down
21 changes: 2 additions & 19 deletions src/bin/cargo/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub fn cli() -> Command {
.arg_silent_suggestion()
.arg_package_spec_no_all(
"Package(s) to publish",
"Publish all packages in the workspace (unstable)",
"Don't publish specified packages (unstable)",
"Publish all packages in the workspace",
"Don't publish specified packages",
)
.arg_features()
.arg_parallel()
Expand All @@ -45,23 +45,6 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
.into());
}

let unstable = gctx.cli_unstable();
let enabled = unstable.package_workspace;
if args.get_flag("workspace") {
unstable.fail_if_stable_opt_custom_z("--workspace", 10948, "package-workspace", enabled)?;
}
if args._value_of("exclude").is_some() {
unstable.fail_if_stable_opt_custom_z("--exclude", 10948, "package-workspace", enabled)?;
}
if args._values_of("package").len() > 1 {
unstable.fail_if_stable_opt_custom_z(
"--package (multiple occurrences)",
10948,
"package-workspace",
enabled,
)?;
}

ops::publish(
&ws,
&PublishOpts {
Expand Down
6 changes: 4 additions & 2 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,6 @@ unstable_cli_options!(
next_lockfile_bump: bool,
no_embed_metadata: bool = ("Avoid embedding metadata in library artifacts"),
no_index_update: bool = ("Do not update the registry index even if the cache is outdated"),
package_workspace: bool = ("Handle intra-workspace dependencies when packaging"),
panic_abort_tests: bool = ("Enable support to run tests with -Cpanic=abort"),
profile_rustflags: bool = ("Enable the `rustflags` option in profiles in .cargo/config.toml file"),
public_dependency: bool = ("Respect a dependency's `public` field in Cargo.toml to control public/private dependencies"),
Expand Down Expand Up @@ -939,6 +938,9 @@ const STABILIZED_CHECK_CFG: &str =

const STABILIZED_DOCTEST_XCOMPILE: &str = "Doctest cross-compiling is now always enabled.";

const STABILIZED_PACKAGE_WORKSPACE: &str =
"Workspace packaging and publishing (a.k.a. `-Zpackage-workspace`) is now always enabled.";

fn deserialize_comma_separated_list<'de, D>(
deserializer: D,
) -> Result<Option<Vec<String>>, D::Error>
Expand Down Expand Up @@ -1320,6 +1322,7 @@ impl CliUnstable {
"lints" => stabilized_warn(k, "1.74", STABILIZED_LINTS),
"registry-auth" => stabilized_warn(k, "1.74", STABILIZED_REGISTRY_AUTH),
"check-cfg" => stabilized_warn(k, "1.80", STABILIZED_CHECK_CFG),
"package-workspace" => stabilized_warn(k, "1.89", STABILIZED_PACKAGE_WORKSPACE),

// Unstable features
// Sorted alphabetically:
Expand Down Expand Up @@ -1363,7 +1366,6 @@ impl CliUnstable {
"mtime-on-use" => self.mtime_on_use = parse_empty(k, v)?,
"no-embed-metadata" => self.no_embed_metadata = parse_empty(k, v)?,
"no-index-update" => self.no_index_update = parse_empty(k, v)?,
"package-workspace" => self.package_workspace = parse_empty(k, v)?,
"panic-abort-tests" => self.panic_abort_tests = parse_empty(k, v)?,
"public-dependency" => self.public_dependency = parse_empty(k, v)?,
"profile-rustflags" => self.profile_rustflags = parse_empty(k, v)?,
Expand Down
4 changes: 1 addition & 3 deletions src/cargo/ops/cargo_package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ fn do_package<'a>(
let deps = local_deps(pkgs.iter().map(|(p, f)| ((*p).clone(), f.clone())));
let just_pkgs: Vec<_> = pkgs.iter().map(|p| p.0).collect();

let mut local_reg = if ws.gctx().cli_unstable().package_workspace {
let mut local_reg = {
// The publish registry doesn't matter unless there are local dependencies that will be
// resolved,
// so only try to get one if we need it. If they explicitly passed a
Expand All @@ -256,8 +256,6 @@ fn do_package<'a>(
let reg_dir = ws.build_dir().join("package").join("tmp-registry");
sid.map(|sid| TmpRegistry::new(ws.gctx(), reg_dir, sid))
.transpose()?
} else {
None
};

// Packages need to be created in dependency order, because dependencies must
Expand Down
23 changes: 6 additions & 17 deletions src/cargo/ops/registry/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,8 @@ pub struct PublishOpts<'gctx> {
}

pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
let multi_package_mode = ws.gctx().cli_unstable().package_workspace;
let specs = opts.to_publish.to_package_id_specs(ws)?;

if !multi_package_mode {
if specs.len() > 1 {
bail!("the `-p` argument must be specified to select a single package to publish")
}
if Packages::Default == opts.to_publish && ws.is_virtual() {
bail!("the `-p` argument must be specified in the root of a virtual workspace")
}
}

let member_ids: Vec<_> = ws.members().map(|p| p.package_id()).collect();
// Check that the specs match members.
for spec in &specs {
Expand All @@ -96,13 +86,12 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
// If `--workspace` is passed,
// the intent is more like "publish all publisable packages in this workspace",
// so skip `publish=false` packages.
let allow_unpublishable = multi_package_mode
&& match &opts.to_publish {
Packages::Default => ws.is_virtual(),
Packages::All(_) => true,
Packages::OptOut(_) => true,
Packages::Packages(_) => false,
};
let allow_unpublishable = match &opts.to_publish {
Packages::Default => ws.is_virtual(),
Packages::All(_) => true,
Packages::OptOut(_) => true,
Packages::Packages(_) => false,
};
if !unpublishable.is_empty() && !allow_unpublishable {
bail!(
"{} cannot be published.\n\
Expand Down
59 changes: 1 addition & 58 deletions src/doc/man/cargo-publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,64 +68,7 @@ which defaults to `crates-io`.

{{/options}}

### Package Selection

By default, when no package selection options are given, the packages selected
depend on the selected manifest file (based on the current working directory if
`--manifest-path` is not given). If the manifest is the root of a workspace then
the workspaces default members are selected, otherwise only the package defined
by the manifest will be selected.

The default members of a workspace can be set explicitly with the
`workspace.default-members` key in the root manifest. If this is not set, a
virtual workspace will include all workspace members (equivalent to passing
`--workspace`), and a non-virtual workspace will include only the root crate itself.

Selecting more than one package is unstable and available only on the
[nightly channel](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html)
and requires the `-Z package-workspace` flag to enable.
See <https://github.com/rust-lang/cargo/issues/10948> for more information.


{{#options}}

{{#option "`-p` _spec_..." "`--package` _spec_..."}}
{{actionverb}} only the specified packages. See {{man "cargo-pkgid" 1}} for the
SPEC format. This flag may be specified multiple times and supports common Unix
glob patterns like `*`, `?` and `[]`. However, to avoid your shell accidentally
expanding glob patterns before Cargo handles them, you must use single quotes or
double quotes around each pattern.

Selecting more than one package with this option is unstable and available only
on the
[nightly channel](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html)
and requires the `-Z package-workspace` flag to enable.
See <https://github.com/rust-lang/cargo/issues/10948> for more information.
{{/option}}

{{#option "`--workspace`" }}
{{actionverb}} all members in the workspace.

This option is unstable and available only on the
[nightly channel](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html)
and requires the `-Z package-workspace` flag to enable.
See <https://github.com/rust-lang/cargo/issues/10948> for more information.
{{/option}}

{{#option "`--exclude` _SPEC_..." }}
Exclude the specified packages. Must be used in conjunction with the
`--workspace` flag. This flag may be specified multiple times and supports
common Unix glob patterns like `*`, `?` and `[]`. However, to avoid your shell
accidentally expanding glob patterns before Cargo handles them, you must use
single quotes or double quotes around each pattern.

This option is unstable and available only on the
[nightly channel](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html)
and requires the `-Z package-workspace` flag to enable.
See <https://github.com/rust-lang/cargo/issues/10948> for more information.
{{/option}}

{{/options}}
{{> section-package-selection }}

### Compilation Options

Expand Down
26 changes: 2 additions & 24 deletions src/doc/man/generated_txt/cargo-publish.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ OPTIONS
passing --workspace), and a non-virtual workspace will include only the
root crate itself.

Selecting more than one package is unstable and available only on the
nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z package-workspace flag to enable. See
<https://github.com/rust-lang/cargo/issues/10948> for more information.

-p spec…, --package spec…
Publish only the specified packages. See cargo-pkgid(1) for the SPEC
format. This flag may be specified multiple times and supports
Expand All @@ -99,21 +93,11 @@ OPTIONS
them, you must use single quotes or double quotes around each
pattern.

Selecting more than one package with this option is unstable and
available only on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z package-workspace flag to enable. See
<https://github.com/rust-lang/cargo/issues/10948> for more
information.

--workspace
Publish all members in the workspace.

This option is unstable and available only on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z package-workspace flag to enable. See
<https://github.com/rust-lang/cargo/issues/10948> for more
information.
--all
Deprecated alias for --workspace.

--exclude SPEC…
Exclude the specified packages. Must be used in conjunction with the
Expand All @@ -123,12 +107,6 @@ OPTIONS
handles them, you must use single quotes or double quotes around
each pattern.

This option is unstable and available only on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z package-workspace flag to enable. See
<https://github.com/rust-lang/cargo/issues/10948> for more
information.

Compilation Options
--target triple
Publish for the given architecture. The default is the host
Expand Down
29 changes: 7 additions & 22 deletions src/doc/src/commands/cargo-publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ The default members of a workspace can be set explicitly with the
virtual workspace will include all workspace members (equivalent to passing
`--workspace`), and a non-virtual workspace will include only the root crate itself.

Selecting more than one package is unstable and available only on the
[nightly channel](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html)
and requires the `-Z package-workspace` flag to enable.
See <https://github.com/rust-lang/cargo/issues/10948> for more information.


<dl>

<dt class="option-term" id="option-cargo-publish--p"><a class="option-anchor" href="#option-cargo-publish--p"></a><code>-p</code> <em>spec</em>…</dt>
Expand All @@ -102,32 +96,23 @@ See <https://github.com/rust-lang/cargo/issues/10948> for more information.
SPEC format. This flag may be specified multiple times and supports common Unix
glob patterns like <code>*</code>, <code>?</code> and <code>[]</code>. However, to avoid your shell accidentally
expanding glob patterns before Cargo handles them, you must use single quotes or
double quotes around each pattern.</p>
<p>Selecting more than one package with this option is unstable and available only
on the
<a href="https://doc.rust-lang.org/book/appendix-07-nightly-rust.html">nightly channel</a>
and requires the <code>-Z package-workspace</code> flag to enable.
See <a href="https://github.com/rust-lang/cargo/issues/10948">https://github.com/rust-lang/cargo/issues/10948</a> for more information.</dd>
double quotes around each pattern.</dd>


<dt class="option-term" id="option-cargo-publish---workspace"><a class="option-anchor" href="#option-cargo-publish---workspace"></a><code>--workspace</code></dt>
<dd class="option-desc">Publish all members in the workspace.</p>
<p>This option is unstable and available only on the
<a href="https://doc.rust-lang.org/book/appendix-07-nightly-rust.html">nightly channel</a>
and requires the <code>-Z package-workspace</code> flag to enable.
See <a href="https://github.com/rust-lang/cargo/issues/10948">https://github.com/rust-lang/cargo/issues/10948</a> for more information.</dd>
<dd class="option-desc">Publish all members in the workspace.</dd>


<dt class="option-term" id="option-cargo-publish---all"><a class="option-anchor" href="#option-cargo-publish---all"></a><code>--all</code></dt>
<dd class="option-desc">Deprecated alias for <code>--workspace</code>.</dd>


<dt class="option-term" id="option-cargo-publish---exclude"><a class="option-anchor" href="#option-cargo-publish---exclude"></a><code>--exclude</code> <em>SPEC</em>…</dt>
<dd class="option-desc">Exclude the specified packages. Must be used in conjunction with the
<code>--workspace</code> flag. This flag may be specified multiple times and supports
common Unix glob patterns like <code>*</code>, <code>?</code> and <code>[]</code>. However, to avoid your shell
accidentally expanding glob patterns before Cargo handles them, you must use
single quotes or double quotes around each pattern.</p>
<p>This option is unstable and available only on the
<a href="https://doc.rust-lang.org/book/appendix-07-nightly-rust.html">nightly channel</a>
and requires the <code>-Z package-workspace</code> flag to enable.
See <a href="https://github.com/rust-lang/cargo/issues/10948">https://github.com/rust-lang/cargo/issues/10948</a> for more information.</dd>
single quotes or double quotes around each pattern.</dd>


</dl>
Expand Down
24 changes: 4 additions & 20 deletions src/etc/man/cargo-publish.1
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ The default members of a workspace can be set explicitly with the
virtual workspace will include all workspace members (equivalent to passing
\fB\-\-workspace\fR), and a non\-virtual workspace will include only the root crate itself.
.sp
Selecting more than one package is unstable and available only on the
\fInightly channel\fR <https://doc.rust\-lang.org/book/appendix\-07\-nightly\-rust.html>
and requires the \fB\-Z package\-workspace\fR flag to enable.
See <https://github.com/rust\-lang/cargo/issues/10948> for more information.
.sp
\fB\-p\fR \fIspec\fR\[u2026],
\fB\-\-package\fR \fIspec\fR\[u2026]
.RS 4
Expand All @@ -113,22 +108,16 @@ SPEC format. This flag may be specified multiple times and supports common Unix
glob patterns like \fB*\fR, \fB?\fR and \fB[]\fR\&. However, to avoid your shell accidentally
expanding glob patterns before Cargo handles them, you must use single quotes or
double quotes around each pattern.
.sp
Selecting more than one package with this option is unstable and available only
on the
\fInightly channel\fR <https://doc.rust\-lang.org/book/appendix\-07\-nightly\-rust.html>
and requires the \fB\-Z package\-workspace\fR flag to enable.
See <https://github.com/rust\-lang/cargo/issues/10948> for more information.
.RE
.sp
\fB\-\-workspace\fR
.RS 4
Publish all members in the workspace.
.RE
.sp
This option is unstable and available only on the
\fInightly channel\fR <https://doc.rust\-lang.org/book/appendix\-07\-nightly\-rust.html>
and requires the \fB\-Z package\-workspace\fR flag to enable.
See <https://github.com/rust\-lang/cargo/issues/10948> for more information.
\fB\-\-all\fR
.RS 4
Deprecated alias for \fB\-\-workspace\fR\&.
.RE
.sp
\fB\-\-exclude\fR \fISPEC\fR\[u2026]
Expand All @@ -138,11 +127,6 @@ Exclude the specified packages. Must be used in conjunction with the
common Unix glob patterns like \fB*\fR, \fB?\fR and \fB[]\fR\&. However, to avoid your shell
accidentally expanding glob patterns before Cargo handles them, you must use
single quotes or double quotes around each pattern.
.sp
This option is unstable and available only on the
\fInightly channel\fR <https://doc.rust\-lang.org/book/appendix\-07\-nightly\-rust.html>
and requires the \fB\-Z package\-workspace\fR flag to enable.
See <https://github.com/rust\-lang/cargo/issues/10948> for more information.
.RE
.SS "Compilation Options"
.sp
Expand Down
Loading