Skip to content

feat: Restructure mutest-driver and cargo-mutest CLIs#7

Merged
zalanlevai merged 19 commits into
mainfrom
cli-restructure
Jul 7, 2026
Merged

feat: Restructure mutest-driver and cargo-mutest CLIs#7
zalanlevai merged 19 commits into
mainfrom
cli-restructure

Conversation

@zalanlevai

@zalanlevai zalanlevai commented Jun 30, 2026

Copy link
Copy Markdown
Owner

This PR restructures the mutest-driver and cargo-mutest CLIs with the following goals in mind:

  • Remove subcommands (build, print) from mutest-driver to create a simpler interface more similar to rustc-driver. Replace the subcommands with a more flexible --emit=[info|metadata|test-bin...] option, which controls both which outputs are generated, and when the compilation can be stopped, i.e., once all emission goals are met. This change also removes the --no-write-json flag from mutest-driver, which is now represented by a lack of --emit=metadata.
  • Consolidate the cargo-mutest subcommands for invoking mutest-driver (run, build, print) under a single run subcommand. Replace the print subcommand with the --no-build flag (corresponds to --emit=info in mutest-driver), and the build subcommand with the --no-eval flag (corresponds to --emit=info,test-bin in mutest-driver). This simplifies argument ordering: because there are now no global arguments, all arguments follow the subcommand, e.g., cargo mutest run -p package --print=mutations --isolate=all.
    • The above change required renaming the evaluation --print option to --eval-print to avoid collision with the compilation --print option.
  • Align the naming of the json options with the new metadata naming in --emit:
    • Rename --no-write-json to --no-emit-metadata in cargo-mutest, which now controls JSON metadata emission through the exclusion of the --emit=metadata option. Other json options have also been renamed to use metadata instead, such as --json-out-root-dir becoming --metadata-out-root-dir.
  • Support standalone, non-Cargo invocations of cargo-mutest.
  • Allow controlling the underlying Cargo invocation's verbosity using the CARGO_VERBOSITY environment variable.
  • Support standalone, non-Cargo invocations of mutest-driver by removing invocation requirements based on Cargo-specific behaviors.

These changes prepare cargo-mutest to be more than just a Cargo-compatible wrapper around mutest-driver, and for cargo-mutest to have more subcommands in the future. They also improve the standalone usage of mutest-driver from build systems other than Cargo.

@zalanlevai
zalanlevai force-pushed the cli-restructure branch 2 times, most recently from e82dde0 to 90f13ce Compare June 30, 2026 23:00
This change replaces the `build` and `print` subcommands with a a more flexible `--emit=[info|metadata|test-bin...]` option, which controls both which outputs are generated, and when the compilation can be stopped, i.e., once all emission goals are met. This change also removes the `--no-write-json flag` from mutest-driver, which is now represented by a lack of `--emit=metadata`.
@zalanlevai
zalanlevai force-pushed the cli-restructure branch 5 times, most recently from 6d961e8 to beced43 Compare July 6, 2026 15:17
zalanlevai added 14 commits July 7, 2026 17:34
This change moves the various Cargo and mutest-driver global arguments in cargo-mutest under the `run` subcommand. This allows us to introduce other subcommands, such as `inspect` to run the inspector on a previous run, by removing Cargo and mutest-driver-specific options from the global argument namespace. It also removes the requirement for Cargo and compilation options to be provided before the `run` subcommand and evaluation options after it, simplifying usage.

This change required changing the `--print` evaluation option to `--eval-print` to avoid collision with the `--print` generation option.
When originally implementing mutest-driver based on clippy-driver, we carried over the behavior that turned the `SYSROOT` environment variable into a `--sysroot` argument. This feature is only needed for using clippy during Rust bootstrapping, and is not relevant to us. Furthermore, the sysroot fallback behavior actually caused issues in certain cases, because it included the sysroot according to rustc from PATH. This change removes this faulty, unused behavior entirely. The sysroot can still be overridden using the standard `--sysroot` argument, just like with rustc.
This change removes the difference in argument handling behavior when the first argument is a path to rustc, as is the case when being invoked by Cargo through RUSTC_WRAPPER / RUSTC_WORKSPACE_WRAPPER. This ensures that mutest-driver provides a rustc-compatible interface regardless of whether it is invoked as a rustc-wrapper or not.
Showing mutest-driver information rather than generic rustc information for these flags does not break rustc compatibility, but greatly simplifies basic usage and the discovery of usage in practice.
Previously, we used to fall back to a rustc invocation if the crate was not part of the Cargo primary package (the set of packages selected by a Cargo invocation), even for non-Cargo invocations. This change ensures that we only expect CARGO_PRIMARY_PACKAGE if we are invoked by Cargo in the first place, otherwise defaulting to invoking mutest-rs behavior.
This change adds fallback behavior for when `--crate-type` is not explicitly provided as a rustc argument, falling back to the `#![crate_type = "..."]` crate root attributes. These attributes are parsed as part of the pseudo-pass for getting the compiler-parsed compiler config.

This change also disables mutations for proc-macro crates, falling back to a rustc invocation instead.
@zalanlevai
zalanlevai marked this pull request as ready for review July 7, 2026 17:15
@zalanlevai
zalanlevai merged commit 98ed91d into main Jul 7, 2026
3 checks passed
@zalanlevai
zalanlevai deleted the cli-restructure branch July 7, 2026 17:15
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.

1 participant