Skip to content

How to integrate first-party crates in a large Cargo workspace with Bazel? #3807

@CharlieSuP1

Description

@CharlieSuP1

Hi, I have a question about migrating a large Cargo project to Bazel.
We have a huge Cargo workspace with 100+ first-party crates and many third-party dependencies.
We're trying to add Bazel support to this project using crate_universe:

crates = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
crates.from_cargo(
    name = "crates",
    cargo_lockfile = "//:Cargo.lock",
    manifests = ["//:Cargo.toml"],
)
use_repo(crates, "crates")

I've noticed that crate_universe can parse dependencies, download third-party crates, and generate BUILD files for them.
However, it doesn't seem to handle first-party crates in the same way.
For our 100+ first-party crates, what's the recommended approach? I'm considering three options:

  • Modify crate_universe logic: Extend it to also generate local repositories and BUILD files for first-party crates
  • Manually maintain BUILD.bazel files: Keep BUILD.bazel files alongside each first-party crate's Cargo.toml
  • Use Gazelle: Automatically generate BUILD files and commit them to the repository

Which approach would you recommend for this use case?
Are there any best practices or examples for handling large monorepos with many first-party crates?
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions