README Source History Refs Reviews Compare Notes Search Review guide scoped cargo x commands
6c28ef1dc2c0999d795f532a12221089dac1fa2f
Oliver Jan Krylow <oliver@bugabinga.net > · 26 Sep 2026
unsigned
Browse files Compare with HEAD
Changed files (2) Diff layout Auto Unified Split
+1 / −0 text lines
47 47 - `smith-cli` unsafe only for OS terminal manipulation, with safe wrapper, `// SAFETY:`, and tests.- `smith-cli` unsafe only for OS terminal manipulation, with safe wrapper, `// SAFETY:`, and tests.48 48 - Public docs required.- Public docs required.49 49 - fmt, clippy, tests, docs, audit, arch, and architecture-test gates in CI.- fmt, clippy, tests, docs, audit, arch, and architecture-test gates in CI.
50 + - Every `cargo x` command accepts argument passthrough; `-p` scoping overrides workspace defaults. Lockfile-wide commands (`audit`, `bootstrap`) reject scope explicitly.51 52 ## Architecture ## Architecture xtask/src/main.rs Modified +98 / −53 text lines
53 53 if command.to_str () == Some ("dev" ) { if command.to_str () == Some ("dev" ) {54 54 return dev (& rest); return dev (& rest);56 - if command.to_str () == Some ("mutants" ) {57 - return cargo_mutants (& rest);59 - if ! rest.is_empty () {60 - return fail ("xtask accepts exactly one command\n" );
62 56 match command.to_str () { match command.to_str () {63 - Some ("check" ) => check (),64 - Some ("lint" ) => lint (),65 - Some ("fmt" ) => cargo (& ["fmt" ]),66 - Some ("test" ) => cargo_nextest (),67 - Some ("doc" ) => cargo (& ["doc" , "--workspace" , "--no-deps" ]),68 - Some ("arch" ) => arch (),69 - Some ("audit" ) => audit (),70 - Some ("bootstrap" ) => bootstrap (),57 + Some ("check" ) => check (& rest),58 + Some ("lint" ) => lint (& rest),59 + Some ("fmt" ) => cargo_fmt_step (& rest),60 + Some ("test" ) => cargo_nextest (& rest),61 + Some ("doc" ) => cargo_doc (& rest),62 + Some ("arch" ) => arch (& rest),63 + Some ("mutants" ) => cargo_mutants (& rest),64 + Some ("audit" ) => audit (& rest),65 + Some ("bootstrap" ) => bootstrap (& rest),71 66 _ => fail (HELP ), _ => fail (HELP ),75 - fn check () -> ExitCode {70 + fn check (extra: & [OsString]) -> ExitCode {87 - type Step = fn () -> ExitCode;85 + type Step = fn (& [ OsString ] ) -> ExitCode;89 - fn sequence (steps: & [Step]) -> ExitCode {87 + fn sequence (steps: & [Step], extra : & [OsString] ) -> ExitCode {90 88 for step in steps { for step in steps {89 + let code = step (extra );92 90 if code != ExitCode::SUCCESS { if code != ExitCode::SUCCESS {93 91 return code; return code;96 94 ExitCode::SUCCESS ExitCode::SUCCESS 99 - fn lint () -> ExitCode {100 - sequence (& [cargo_fmt, cargo_clippy])99 + fn scoped (base: & [&str ], extra: & [OsString]) -> Vec <OsString> {100 + let mut args: Vec <OsString> = base.iter ().map (OsString::from).collect ();101 + let narrows = extra.iter ().any (|arg| {102 + arg == "-p" || arg == "--package" || arg.to_string_lossy ().starts_with ("--package=" )105 + args.retain (|arg| arg != "--workspace" );107 + args.extend_from_slice (extra);103 - fn audit () -> ExitCode {104 - sequence (& [install_deny, install_audit, cargo_deny, cargo_audit])111 + fn lint (extra: & [OsString]) -> ExitCode {112 + sequence (& [cargo_fmt_step, cargo_clippy], extra)116 + fn audit (extra: & [OsString]) -> ExitCode {117 + if ! extra.is_empty () {118 + return fail ("audit is lockfile-wide and admits no scoping\n" );121 + & [install_deny, install_audit, cargo_deny, cargo_audit],161 - fn cargo_fmt () -> ExitCode {162 - cargo (& ["fmt" , "--check" ])180 + fn cargo_fmt_step (extra: & [OsString]) -> ExitCode {181 + let args = scoped (& ["fmt" , "--check" ], extra);182 + run_os ("cargo" , & args)165 - fn cargo_clippy () -> ExitCode {185 + fn cargo_clippy (extra : & [OsString] ) -> ExitCode {187 + & ["clippy" , "--workspace" , "--all-targets" , "--all-features" ],166 190 match Command::new("cargo" ) match Command::new("cargo" )167 191 .env ("CLIPPY_CONF_DIR" , ".config" ) .env ("CLIPPY_CONF_DIR" , ".config" )168 - .args (["clippy" , "--workspace" , "--all-targets" , "--all-features" ])169 193 .status () .status ()171 195 Ok (status) if status.success () => ExitCode::SUCCESS , Ok (status) if status.success () => ExitCode::SUCCESS ,177 - fn cargo_nextest () -> ExitCode {178 - nextest_run (& ["--workspace" , "--all-features" ])201 + fn cargo_nextest (extra : & [OsString] ) -> ExitCode {202 + let args = scoped (& ["--workspace" , "--all-features" ], extra);203 + nextest_run_os (& args)183 - fn nextest_run (args: & [&str ]) -> ExitCode {208 + fn nextest_run_os (args: & [OsString]) -> ExitCode {184 209 let mut child = match Command::new("cargo" ) let mut child = match Command::new("cargo" )185 210 .arg ("nextest" ) .arg ("nextest" )186 211 .arg ("run" ) .arg ("run" )219 - fn cargo_machete () -> ExitCode {244 + fn cargo_machete (_extra : & [OsString] ) -> ExitCode {220 245 let installed = tool_present_bin ("cargo-machete" , MACHETE_VERSION , || { let installed = tool_present_bin ("cargo-machete" , MACHETE_VERSION , || {222 247 "install" , "install" ,237 - fn ensure_mold () -> ExitCode {262 + fn ensure_mold (_extra : & [OsString] ) -> ExitCode {238 263 if cfg! (all ( if cfg! (all (239 264 target_arch = "x86_64" , target_arch = "x86_64" ,240 265 target_os = "linux" , target_os = "linux" ,263 - fn bootstrap () -> ExitCode {289 + fn bootstrap (extra : & [OsString] ) -> ExitCode {290 + if ! extra.is_empty () {291 + return fail ("bootstrap installs tools and admits no scoping\n" );264 293 let steps: [Step; 6 ] = [ let steps: [Step; 6 ] = [265 294 install_binstall, install_binstall,266 295 install_nextest, install_nextest,269 298 install_audit, install_audit,270 299 install_mutants, install_mutants,301 + sequence (& steps, extra )275 - fn install_machete () -> ExitCode {304 + fn install_machete (_extra : & [OsString] ) -> ExitCode {276 305 tool_present_bin ("cargo-machete" , MACHETE_VERSION , || { tool_present_bin ("cargo-machete" , MACHETE_VERSION , || {278 307 "install" , "install" ,287 - fn install_deny () -> ExitCode {316 + fn install_deny (_extra : & [OsString] ) -> ExitCode {288 317 tool_present_bin ("cargo-deny" , DENY_VERSION , || { tool_present_bin ("cargo-deny" , DENY_VERSION , || {290 319 "binstall" , "binstall" ,297 - fn install_audit () -> ExitCode {326 + fn install_audit (_extra : & [OsString] ) -> ExitCode {298 327 tool_present_bin ("cargo-audit" , AUDIT_VERSION , || { tool_present_bin ("cargo-audit" , AUDIT_VERSION , || {300 329 "binstall" , "binstall" ,307 - fn install_mutants () -> ExitCode {336 + fn install_mutants (_extra : & [OsString] ) -> ExitCode {308 337 tool_present_bin ("cargo-mutants" , MUTANTS_VERSION , || { tool_present_bin ("cargo-mutants" , MUTANTS_VERSION , || {310 339 "binstall" , "binstall" ,317 - fn install_binstall () -> ExitCode {346 + fn install_binstall (_extra : & [OsString] ) -> ExitCode {318 347 tool_present_bin ("cargo-binstall" , BINSTALL_VERSION , || { tool_present_bin ("cargo-binstall" , BINSTALL_VERSION , || {320 349 "install" , "install" ,331 - fn install_nextest () -> ExitCode {360 + fn install_nextest (_extra : & [OsString] ) -> ExitCode {332 361 tool_present_bin ("cargo-nextest" , NEXTEST_VERSION , || { tool_present_bin ("cargo-nextest" , NEXTEST_VERSION , || {334 363 "binstall" , "binstall" ,354 383 if pinned { ExitCode::SUCCESS } else { install () } if pinned { ExitCode::SUCCESS } else { install () }357 - fn cargo_doc () -> ExitCode {358 - cargo (& ["doc" , "--workspace" , "--no-deps" ])386 + fn cargo_doc (extra : & [OsString] ) -> ExitCode {387 + let args = scoped (& ["doc" , "--workspace" , "--no-deps" ], extra ); 388 + run_os ("cargo" , & args)361 - fn cargo_deny () -> ExitCode {391 + fn cargo_deny (_extra : & [OsString] ) -> ExitCode {362 392 cargo (& ["deny" , "--config" , ".config/deny.toml" , "check" ]) cargo (& ["deny" , "--config" , ".config/deny.toml" , "check" ])365 - fn cargo_audit () -> ExitCode {395 + fn cargo_audit (_extra : & [OsString] ) -> ExitCode {366 396 cargo (& ["audit" , "--deny" , "warnings" ]) cargo (& ["audit" , "--deny" , "warnings" ])428 458 let _ignored = std::io::stderr().write_all (message.as_bytes ()); let _ignored = std::io::stderr().write_all (message.as_bytes ());
461 + fn run_os (program: &str , args: & [OsString]) -> ExitCode {462 + match Command::new(program).args (args).status () {463 + Ok (status) if status.success () => ExitCode::SUCCESS ,464 + Ok (status) => fail (& format! ("{program} exited with {status}\n" )),465 + Err (error) => fail (& format! ("failed to run {program}: {error}\n" )),431 469 fn run (program: &str , args: & [&str ]) -> ExitCode {fn run (program: &str , args: & [&str ]) -> ExitCode {432 470 match Command::new(program).args (args).status () { match Command::new(program).args (args).status () {433 471 Ok (status) if status.success () => ExitCode::SUCCESS , Ok (status) if status.success () => ExitCode::SUCCESS ,439 - fn arch () -> ExitCode {477 + fn arch (extra : & [OsString] ) -> ExitCode {478 + let wanted: Vec <String > = extra480 + .map (|arg| arg.to_string_lossy ().into_owned ())440 482 for crate_name in CRATES { for crate_name in CRATES {441 483 if ! Path::new(crate_name).join ("Cargo.toml" ).is_file () { if ! Path::new(crate_name).join ("Cargo.toml" ).is_file () {442 484 return fail (& format! ("missing crate manifest: {crate_name}\n" )); return fail (& format! ("missing crate manifest: {crate_name}\n" ));445 487 for rule in dependency_rules () { for rule in dependency_rules () {
488 + if ! wanted.is_empty () && ! wanted.iter ().any (|name| name == rule.crate_name) {446 491 let manifest = match fs::read_to_string(Path::new(rule.crate_name).join ("Cargo.toml" )) { let manifest = match fs::read_to_string(Path::new(rule.crate_name).join ("Cargo.toml" )) {447 492 Ok (value) => value, Ok (value) => value,448 493 Err (error) => { Err (error) => {