You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cargo-mutants has limited dependencies on Cargo and could in principle be used with any other build tool.
This bug is primarily blocked on someone providing a realistic example of a Rust tree that builds with something other than Cargo. A minimized example would be good, but it should correspond to some real tree to give confidence that any solution actually works at scale. Preferably there would be an open source tree as a real example on which this could be tested.
Add a command-line option or configuration option saying which build system to use: or maybe auto-detect.
Add some kind of build system trait.
Find the root of the tree to copy. For cargo this is cargo locate-project.
Find the sources for non-test targets within a directory. Currently this is from cargo metadata. For Bazel we could potentially look at bazel query?
Work out how to adjust any relative dependency paths in the scratch tree.
Generate commands to build and test the targets. It may be less clear, in Bazel, how to run the tests for changes to some given package, since tests can be in a different directory.
#72 adds some knowledge of cargo workspaces. These very loosely correspond to Bazel packages.
I think this is still very feasible, but I'm going to close it for now, because I'm not likely to proactively work on it unless or until there is both:
a realistic Bazel Rust tree to test on
some user who cares about doing mutation testing in such a tree
I'll mention this in the manual as a current limitation.
Met some people who are using Rust with Bazel, so I will at least reopen this. Apparently there is a realistic example in the Bazel Rust rules repo, and there is a Slack channel about it.
I’m interested in trying to add bazel support. Any recommendations on where to start if I just wanted to poke around with generating mutants for arbitrary rust code?
should be more or less able to generate mutants from any Rust source tree regardless of what build tool it uses.
There are cargo-specific bits both ahead of and after generating mutants. Before finding mutants we use cargo to find the root of the tree, the packages, etc. After generating mutants we need to of course build and run the tests.
Coming back to this after a while. I would like to get your thoughts on splitting out a library that just does the mutant generation as a step towards adding support for bazel? I'm not quite sure what that looks like; maybe a different crate workspace?
Hi! I recently added -Zmutate-file which will write out, in json, all the generated mutants, including the diff to apply. If copying the tree and running the build/test/etc is taken care of externally then maybe this is enough to prototype testing mutants under Bazel.
I'm not necessarily opposed to splitting out a separate crate, but I'd like to think or know a bit more about what is a good boundary of functionality and also what the UI should be. Perhaps cargo mutants should do the right thing in a Bazel-managed tree? Or is there a natural way to invoke it from inside Bazel?
I'm not 100% either what the right way to integrate this with bazel is right now. In my ideal world we could integrate tightly with rules_rust in a way where you could flip a flag on your rust_test or have a rust_mutation_test that would generate the mutations, run the tests, and collect the results. Then doing bazel test //... or bazel test //path/to:target would just work.
I think that lends itself more to a world in which expose the mutation generation via a library or this -Zmutate flag that I need to look into.
Activity
sourcefrog commentedon Dec 4, 2023
I think this is still very feasible, but I'm going to close it for now, because I'm not likely to proactively work on it unless or until there is both:
I'll mention this in the manual as a current limitation.
Note about supporting Bazel
sourcefrog commentedon Sep 11, 2024
Met some people who are using Rust with Bazel, so I will at least reopen this. Apparently there is a realistic example in the Bazel Rust rules repo, and there is a Slack channel about it.
matte1 commentedon Sep 7, 2025
I’m interested in trying to add bazel support. Any recommendations on where to start if I just wanted to poke around with generating mutants for arbitrary rust code?
sourcefrog commentedon Sep 7, 2025
I would start by reading https://github.com/sourcefrog/cargo-mutants/blob/main/DESIGN.md which gives an overview of the code structure, and https://github.com/sourcefrog/cargo-mutants/blob/main/CONTRIBUTING.md.
walk_packagecargo-mutants/src/visit.rs
Line 84 in c07ee28
There are cargo-specific bits both ahead of and after generating mutants. Before finding mutants we use cargo to find the root of the tree, the packages, etc. After generating mutants we need to of course build and run the tests.
matte1 commentedon Feb 23, 2026
Coming back to this after a while. I would like to get your thoughts on splitting out a library that just does the mutant generation as a step towards adding support for bazel? I'm not quite sure what that looks like; maybe a different crate workspace?
sourcefrog commentedon Feb 24, 2026
Hi! I recently added
-Zmutate-filewhich will write out, in json, all the generated mutants, including the diff to apply. If copying the tree and running the build/test/etc is taken care of externally then maybe this is enough to prototype testing mutants under Bazel.I'm not necessarily opposed to splitting out a separate crate, but I'd like to think or know a bit more about what is a good boundary of functionality and also what the UI should be. Perhaps
cargo mutantsshould do the right thing in a Bazel-managed tree? Or is there a natural way to invoke it from inside Bazel?matte1 commentedon Feb 27, 2026
I'm not 100% either what the right way to integrate this with bazel is right now. In my ideal world we could integrate tightly with rules_rust in a way where you could flip a flag on your
rust_testor have arust_mutation_testthat would generate the mutations, run the tests, and collect the results. Then doingbazel test //...orbazel test //path/to:targetwould just work.I think that lends itself more to a world in which expose the mutation generation via a library or this
-Zmutateflag that I need to look into.matte1 commentedon Apr 3, 2026
We have a proof of concept here at https://github.com/periareon/rules_rust_mutants! It builds a hermetic version of cargo-mutants and then uses that within the bazel rules_rust framework to generate mutants. Its definitely a very rough first pass at bazel support