rules_rust icon indicating copy to clipboard operation
rules_rust copied to clipboard

Expose bindgen toolchain through bzlmod

Open jwnrt opened this issue 1 year ago • 9 comments

With this change I was able to use the default bindgen toolchain with bzlmod by adding this to my MODULE.bazel:

bindgen = use_extension("@rules_rust//bindgen:extension.bzl", "bindgen")
use_repo(bindgen, "bindgen_toolchains")

register_toolchains("@bindgen_toolchains//:default_bindgen_toolchain")

Had to backport a change from recent versions of LLVM which use this WORKSPACE_ROOT environment variable to fix paths to generated files. Updating the LLVM archive would also fix that problem.

Happy to add tests and documentation if this matches what you had in mind for getting this working.

jwnrt avatar Jul 12 '24 16:07 jwnrt

@jwnrt any chance you could pick this up again? Seems like this would fix https://github.com/bazelbuild/rules_rust/issues/2787

lalten avatar Aug 29 '24 20:08 lalten

@jwnrt any chance you could pick this up again? Seems like this would fix https://github.com/bazelbuild/rules_rust/issues/2787

Sorry, I took my eye off this when I realised I wouldn't need it for OpenTitan.

I'm happy to finish it off but I won't have time for at least a week. Happy for anyone else to take it over if they get there before me.

Aside, it turns out the local_repository thing I switched to using isn't available in Bazel 6, so that might be blocked on https://github.com/bazelbuild/rules_rust/pull/2812. I'll switch it back to the manual re-implementation for now.

I still have no resolution for the repo_mapping thing. It's not supported in Bzlmod, but may break non-bzlmod users who depend on a different version of zlib if removed. The best solution would be for Bzlmod to stop erroring on that parameter and just ignore it. That would be an upstream change.

jwnrt avatar Aug 30 '24 15:08 jwnrt

@jwnrt Hello James, is there any plan to fix this issue? Has a bug been filed with bazelbuild for the repo_mapping issue? Thanks!

AlexOrozco1256 avatar Sep 13 '24 16:09 AlexOrozco1256

Thanks for the reminder, I've updated the PR to resolve those issues.

Based on https://github.com/bazelbuild/bazel/issues/21846 it seems to me that Bazel are moving away from supporting repo_mapping entirely. Even if upstream Bazel stops erroring on repo_mapping for Bzlmod, rules_rust would have to greatly increase its minimum supported Bazel version to benefit.

I've worked around it by making repo_mapping optional (but used by default). I've documented it as being unstable / subject to change.

jwnrt avatar Sep 13 '24 18:09 jwnrt

@jwnrt Thanks for your effort, sounds like a good solution to me. @UebelAndre Could you take another look, so we can merge this PR? The issue blocks the transition of rules_ros2 to bzlmod.

ahans avatar Sep 27 '24 13:09 ahans

@jwnrt Thank you!! Sorry it took me a while to get back but I appreciate your help!

AlexOrozco1256 avatar Sep 27 '24 17:09 AlexOrozco1256

(just a drive by that this is an exciting change and it would be great to have it merged - thanks @jwnrt and @UebelAndre)

hlopko avatar Oct 08 '24 07:10 hlopko

I also keep rebasing this because I need it. Anything I can do to help get this merged?

ajwerner avatar Dec 01 '24 16:12 ajwerner

Hello, is there anything I can do to help get this merged? I've received inquiries from other teams that would like to use bindgen + bzlmod. Thanks!

AlexOrozco1256 avatar Mar 27 '25 17:03 AlexOrozco1256