Skip to content

Commit

Permalink
perf(xtask): Split xtask binaries
Browse files Browse the repository at this point in the history
This will allow running an xtask without requiring building the world.
In most cases, a user will already have been building cargo but not in
CI.

The packages keep an `xtask-` prefix to help raise awareness of them but
exposed as `cargo <suffix>` to avoid having a direction proxy to wrap
`cargo run -p xtask-<suffix>` as `cargo xtask <suffix>`.
  • Loading branch information
epage committed Apr 26, 2023
1 parent c6f8ee9 commit 5b13963
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[alias]
xtask = "run --package xtask --"
unpublished = "run --package xtask-unpublished --"
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "xtask"
name = "xtask-unpublished"
version = "0.0.0"
edition = "2021"
publish = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod unpublished;
mod xtask;

fn main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,76 @@ use cargo::core::SourceId;
use cargo::util::command_prelude::*;

pub fn cli() -> clap::Command {
clap::Command::new("unpublished")
clap::Command::new("xtask-unpublished")
.arg(
opt(
"verbose",
"Use verbose output (-vv very verbose/build.rs output)",
)
.short('v')
.action(ArgAction::Count)
.global(true),
)
.arg_quiet()
.arg(
opt("color", "Coloring: auto, always, never")
.value_name("WHEN")
.global(true),
)
.arg(flag("frozen", "Require Cargo.lock and cache are up to date").global(true))
.arg(flag("locked", "Require Cargo.lock is up to date").global(true))
.arg(flag("offline", "Run without accessing the network").global(true))
.arg(multi_opt("config", "KEY=VALUE", "Override a configuration value").global(true))
.arg(
Arg::new("unstable-features")
.help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details")
.short('Z')
.value_name("FLAG")
.action(ArgAction::Append)
.global(true),
)
}

pub fn exec(args: &clap::ArgMatches, config: &mut cargo::util::Config) -> cargo::CliResult {
config_configure(config, args)?;

unpublished(args, config)?;

Ok(())
}

fn config_configure(config: &mut Config, args: &ArgMatches) -> CliResult {
let verbose = args.verbose();
// quiet is unusual because it is redefined in some subcommands in order
// to provide custom help text.
let quiet = args.flag("quiet");
let color = args.get_one::<String>("color").map(String::as_str);
let frozen = args.flag("frozen");
let locked = args.flag("locked");
let offline = args.flag("offline");
let mut unstable_flags = vec![];
if let Some(values) = args.get_many::<String>("unstable-features") {
unstable_flags.extend(values.cloned());
}
let mut config_args = vec![];
if let Some(values) = args.get_many::<String>("config") {
config_args.extend(values.cloned());
}
config.configure(
verbose,
quiet,
color,
frozen,
locked,
offline,
&None,
&unstable_flags,
&config_args,
)?;
Ok(())
}

fn unpublished(args: &clap::ArgMatches, config: &mut cargo::util::Config) -> cargo::CliResult {
let ws = args.workspace(config)?;
let mut results = Vec::new();
{
Expand Down Expand Up @@ -84,3 +150,8 @@ pub fn exec(args: &clap::ArgMatches, config: &mut cargo::util::Config) -> cargo:

Ok(())
}

#[test]
fn verify_cli() {
cli().debug_assert();
}
83 changes: 0 additions & 83 deletions crates/xtask/src/xtask.rs

This file was deleted.

0 comments on commit 5b13963

Please sign in to comment.