From d4af1f2485e1f7c5c2214bf981abed409c7cd400 Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 25 Nov 2026 02:35:46 +0000 Subject: [PATCH] cl: pass the dev profile settings after the cargo subcommand cargo lets a --config given after the subcommand replace every --config given before it, so `cl test --config .config/cargo-ci.toml` built every crate, dependencies included, at opt-level 0. External subcommands (fmt) keep them before the subcommand. --- tools/cl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/cl b/tools/cl index fc3b8fc3e..9bcc5292a 100755 --- a/tools/cl +++ b/tools/cl @@ -94,6 +94,8 @@ APP_KEYS = { "test_threads": (int, None), } APP_BUILDING = {"test", "check", "build", "run", "bench", "clippy", "doc", "rustc"} +# cargo's own subcommands that resolve a profile; `cargo()` passes the dev settings after them. +CARGO_BUILDING = {"test", "check", "build", "run", "bench", "doc", "rustc", "metadata", "tree"} APP_FEATURE_FLAGS = ("--features", "-F", "--no-default-features") # Set by main() from the workspace's `[workspace.metadata.cl]` in an app workspace; None in craft-libs. APP = None @@ -379,9 +381,13 @@ def cargo(top, cargo_args, json_out=False, timings=True): RECORD["target"] = target if timings: cargo_args = cargo_args[:1] + ["--timings"] + cargo_args[1:] - # An app workspace keeps its own profile settings. + # An app workspace keeps its own profile settings. For cargo's own build commands they go after the subcommand: + # cargo lets a `--config` given there replace every `--config` given before it, so a caller's own `--config` + # (.config/cargo-ci.toml) would otherwise drop the dev settings and build every crate, dependencies included, at + # opt-level 0. An external subcommand (fmt) would read them as its own options, so they stay before it. config = [] if APP else [x for c in dev_profile_config() for x in ("--config", c)] - cmd = shlex.split(env.get("CL_LAUNCHER", "")) + ["cargo"] + config + cargo_args + split = 1 if cargo_args[:1] and cargo_args[0] in CARGO_BUILDING else 0 + cmd = shlex.split(env.get("CL_LAUNCHER", "")) + ["cargo"] + cargo_args[:split] + config + cargo_args[split:] print("cl: " + " ".join(cmd) + f" (target {target})", file=sys.stderr) sys.stdout.flush() if DRY_RUN: