Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in configuring crates_universe when included as a Bazel module #1348

Open
tel opened this issue May 15, 2024 · 6 comments
Open

Error in configuring crates_universe when included as a Bazel module #1348

tel opened this issue May 15, 2024 · 6 comments

Comments

@tel
Copy link

tel commented May 15, 2024

I'm attempting to include CXX as a Bzlmod module. Since it is not published on the Bazel Central Registry I'm doing so via a git_override

git_override(
    module_name = "cxx.rs",
    commit = "462896c80629a51ddcdc72fa55af0bb4befbb675",
    patches = [
        "//repo_patches:add_rules_cc_to_cxx.patch",
    ],
    remote = "https://github.com/dtolnay/cxx.git",
)

where the add_rules_cc_to_cxx.patch modifies cxx's MODULE.bazel file to include an explicit dependency on rules_cc, something that I found was necessary to allow Bazel to even attempt to build any targets in @cxx.rs//.

Unfortunately, this still fails due to a repo lookup failure that gets memorialized into the MODULE.bazel.lock file. The details are available in this minimal reproduction

https://github.com/tel/cxx_bzlmod_repro

I think this may be an error in rules_rust or how crate_universe is being configured, but I wanted to start here and escalate if necessary.

@nyurik
Copy link

nyurik commented Aug 7, 2024

Hi @tel, have you been able to integrate CXX into a Bazel build? I am very new to Bazel, and would like to add Rust+CXX to maplibre-native, but failing. Mostly I am just struggling with the best approach to integrating it - there seem to be tons of varying docs but none seem to fit. Thx!

@sthornington
Copy link

I got furthest when using tag 110, prior to the switch to bzlmod. Haven’t had time to figure it out completely maybe next week.

@nyurik
Copy link

nyurik commented Aug 7, 2024

@sthornington not sure what you mean by tag 110 - which repo, or is this a version of something? thx!

@tel
Copy link
Author

tel commented Aug 12, 2024

@nyurik I did end up getting it working, albeit with in a hacky fashion. Here's some instructions I just wrote up for someone else asking the same thing.


I did end up getting it working... though it's not pretty. I'd love for cxx to just support something like bzlmod and end up in a registry, but until that point what I've done is the following:

  • I first vendored the cxx repo into a place in my repo, here third-party/cxx
  • I am including a repo for crates.io using bzlmod and rules_rust, so I added copied all of the crate dependencies from the cxx repo into that crates.io vendored repo.
    • For instance, I'm not personally using clap, but the cxx codegen application does, so I include it crates_io.spec(package = "clap", version = "4.5")
  • Then I modified the third-party/cxx/BUILD definition so that all of the dependencies reference my @crates_io repo, e.g. rust_binary(name = "codegen", ..., deps = ["@crates.io//:clap", ...])
  • Finally, I can reference the cxx tools at paths like //third-party/cxx:codegen. For instance, to build my cxx C++ modules I have a genrule like this
run_binary(
    name = "bridge",
    srcs = ["src/ffi.rs"],
    outs = [
        "ffi.rs.cc",
        "ffi.rs.h",
    ],
    args = [
        "$(location src/ffi.rs)",
        "-o",
        "$(location ffi.rs.h)",
        "-o",
        "$(location ffi.rs.cc)",
    ],
    tool = "//third-party/cxx:codegen",
)

Actually getting the cxx outputs properly integrated into Bazel is a bit messy, but at this point you should be able to mostly follow the examples from the repo. I'm happy to share more, but this should be enough to get you started.

@nyurik
Copy link

nyurik commented Aug 12, 2024

This is awesome, I'll try it shortly. What steps are needed to actually publish cxx as a reusable module?

@tel
Copy link
Author

tel commented Aug 12, 2024

@nyurik I'm not sure.

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

No branches or pull requests

3 participants