Skip to content

Support Bazel or other build systems  #77

Open

Description

@sourcefrog

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

Activity

  1. added
    enhancement
    help wanted
    on Aug 20, 2022
  2. sourcefrog commented on Dec 4, 2023

    @sourcefrog
    OwnerAuthor

    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.

  3. added a commit that references this issue on Aug 24, 2024
    0c46315
  4. sourcefrog commented on Sep 11, 2024

    @sourcefrog
    OwnerAuthor

    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.

  5. matte1 commented on Sep 7, 2025

    @matte1

    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?

  6. sourcefrog commented on Sep 7, 2025

    @sourcefrog
    OwnerAuthor

    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

    fn walk_package(
    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.

  7. matte1 commented on Feb 23, 2026

    @matte1

    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?

  8. sourcefrog commented on Feb 24, 2026

    @sourcefrog
    OwnerAuthor

    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?

  9. matte1 commented on Feb 27, 2026

    @matte1

    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.

  10. matte1 commented on Apr 3, 2026

    @matte1

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions