Skip to content

Tooling: cargo xtask (ci, fmt, test, coverage, example) and CI through it - #7

Merged
samitbasu merged 2 commits into
mainfrom
tooling-xtask
Nov 7, 2026
Merged

samitbasu merged 2 commits into
mainfrom
tooling-xtask

Conversation

@samitbasu

Copy link
Copy Markdown
Owner

Closes #3, closes #4. Part of #6 (branch protection still pending).

Summary

  • The repo is now a workspace (xtask member, publish = false) with the alias cargo xtask. xtask dependencies stay out of the bullseye library's dependency tree.
  • Subcommands (clap derive, with --help on each): ci, fmt [--check], test [-- ARGS], coverage [--lcov], example [NAME] [--release].
  • Every task is built from Step values (name, cargo args, env). ci_steps() is the single ordered list consumed by run_all, so the snapshot step from Tooling: cargo xtask snapshots for reference screenshots #5 is one more entry appended there. Each step prints ==> name: command; a failure names the step and exits non-zero.
  • example with no name lists examples/ with the first //! line of each; examples/hello.rs is a trivial eframe window so there is something to list and run.
  • coverage prints the install command (cargo install cargo-llvm-cov) and fails if the tool is missing, and prints the report path on success.
  • Process hygiene (xtask/src/process.rs): each child starts in its own process group (before_spawn + process_group(0)); a guard SIGKILLs the group on drop (normal exit), and the SIGINT/SIGTERM handler kills every registered group and exits 130. Non-unix compiles via cfg (no group kill; the console delivers Ctrl-C to children).
  • CI workflow rewritten per Tooling: CI on GitHub Actions via cargo xtask ci #6: pull_request and push to main, concurrency cancelling superseded runs, jobs ci (only cargo xtask ci), msrv (1.96, cargo check --workspace --all-targets) and coverage (cargo xtask coverage --lcov, uploads lcov.info). The required status check name ci is unchanged.
  • CLAUDE.md project notes and README "Development" section list the commands.

Dependencies (xtask only)

  • clap (derive): the CLI, with generated help and debug_assert self-check.
  • duct: subprocesses, as specified in Tooling: adopt the cargo xtask pattern (clap + duct) #3; before_spawn is where the process group is set.
  • anyhow: error context for the step failures.
  • ctrlc (termination feature): handles SIGINT and SIGTERM (and SIGHUP) on one thread with a plain closure, and is portable (Windows console handler), which signal-hook would need more code for. Chosen over signal-hook for being the smaller API.
  • libc (unix only): the single kill(-pgid, SIGKILL) call; already in the tree transitively via ctrlc/nix.

Verification

  • cargo xtask ci passes locally (fmt, clippy, 11 library tests plus 16 xtask tests, doctests, rustdoc).
  • cargo xtask coverage and coverage --lcov work locally (cargo-llvm-cov).
  • SIGINT cleanup: started target/debug/xtask example hello in the background; the hello window process appeared in its own process group (pgid equal to its pid). kill -INT <xtask pid> ended both xtask and hello; no examples/hello process remained. Repeated with SIGTERM: both gone within a second.

Notes

  • Branch coverage is not enabled: cargo-llvm-cov --branch needs nightly. Line coverage only for now.
  • No system packages were added to the workflow; to be confirmed on the runner. If clippy --all-targets needs them for winit/eframe on ubuntu, an apt step goes in the ci job.
  • The coverage job installs llvm-tools-preview on the stable toolchain.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up

samitbasu and others added 2 commits November 6, 2026 23:07
Repetitive work should have one implementation that CI and developers both
run. The repo becomes a workspace with an xtask crate (clap + duct) providing
ci, fmt, test, coverage and example. Every task is a list of Step values;
ci_steps() is the single ordered list, leaving a place for the snapshot step.

Children run in their own process groups, killed on drop and on
SIGINT/SIGTERM (ctrlc), so nothing outlives xtask. A missing cargo-llvm-cov
prints its install command. examples/hello.rs gives `example` something to
list and run. The CI workflow now only calls `cargo xtask ci`, plus msrv and
coverage jobs, and runs on pull requests and pushes to main with superseded
runs cancelled.

Behavior change: CI no longer runs on every branch push.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
The From<bool> impls on FmtMode, Profile and ReportFormat let a naked
bool stand in for those enums anywhere in xtask, which CLAUDE.md rules
out. The clap struct is the foreign boundary, so the flags stay bools
there and are matched into the enums once, where they are parsed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
@samitbasu

Copy link
Copy Markdown
Owner Author

Review (main session): read the full diff; ran cargo xtask ci locally (green: 11 lib tests, 16 xtask tests, doctests, rustdoc); re-verified process cleanup myself: xtask example hello ran the window in its own process group, one SIGINT to xtask ended both, no leftovers. One fix pushed on top: removed the From<bool> impls on FmtMode/Profile/ReportFormat (naked bools under another name, per CLAUDE.md) and matched the clap flags into the enums at the boundary.

Known limits, accepted for now: line coverage only (branch coverage needs nightly); the non-unix path compiles but does not kill process groups; children are ended with SIGKILL, so a future child that needs graceful shutdown will need SIGTERM-then-KILL.

@samitbasu
samitbasu merged commit 3934bd5 into main Nov 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tooling: xtask targets ci, fmt, test, coverage, example Tooling: adopt the cargo xtask pattern (clap + duct)

1 participant