Skip to content

Commit

Permalink
Adds support for packaging workspaces.
Browse files Browse the repository at this point in the history
Takes local dependencies into account when packaging a workspace. Builds
a temporary package registry to provide local dependencies, and overlays
it on the upstream registry.

This adds `--registry` and `--index` flags to `cargo package`. They act
much like the same arguments to `cargo publish`, except that of course
we are not actually publishing to the specified registry. Instead, these
arguments affect lock-file generation for intra-workspace dependencies:
when simultaneously packaging a crate and one of its dependencies, the
lock-file will be generated under the assumption that the dependency
will be published to the specified registry.

Co-Authored-By: Tor Hovland <55164+torhovland@users.noreply.github.com>
  • Loading branch information
jneem and torhovland committed Jul 15, 2024
1 parent 7560bb8 commit 2f1b6cb
Show file tree
Hide file tree
Showing 17 changed files with 685 additions and 201 deletions.
12 changes: 12 additions & 0 deletions src/bin/cargo/commands/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use cargo::ops::{self, 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(
flag(
"list",
Expand Down Expand Up @@ -41,6 +43,15 @@ 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("--registry", 13947)?;
}
if args._value_of("index").is_some() {
gctx.cli_unstable()
.fail_if_stable_opt("--registry", 13947)?;
}
let reg_or_index = args.registry_or_index(gctx)?;
let ws = args.workspace(gctx)?;
if ws.root_maybe().is_embedded() {
return Err(anyhow::format_err!(
Expand All @@ -64,6 +75,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
jobs: args.jobs()?,
keep_going: args.keep_going(),
cli_features: args.cli_features()?,
reg_or_index,
},
)?;

Expand Down
2 changes: 2 additions & 0 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ unstable_cli_options!(
mtime_on_use: bool = ("Configure Cargo to update the mtime of used files"),
next_lockfile_bump: bool,
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 @@ -1276,6 +1277,7 @@ impl CliUnstable {
// can also be set in .cargo/config or with and ENV
"mtime-on-use" => self.mtime_on_use = 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
Loading

0 comments on commit 2f1b6cb

Please sign in to comment.