cargo-mutants icon indicating copy to clipboard operation
cargo-mutants copied to clipboard

Support Bazel or other build systems

Open sourcefrog opened this issue 3 years ago • 4 comments

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.

cc @kupiakos

sourcefrog avatar Aug 20 '22 23:08 sourcefrog

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:

  1. a realistic Bazel Rust tree to test on
  2. some user who cares about doing mutation testing in such a tree

I'll mention this in the manual as a current limitation.

sourcefrog avatar Dec 04 '23 16:12 sourcefrog

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.

sourcefrog avatar Sep 11 '24 18:09 sourcefrog

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?

matte1 avatar Sep 07 '25 05:09 matte1

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_package https://github.com/sourcefrog/cargo-mutants/blob/c07ee283d907ab6c5ab2a5925db3b88493eebda3/src/visit.rs#L84 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.

sourcefrog avatar Sep 07 '25 13:09 sourcefrog