diff --git a/MODULE.bazel b/MODULE.bazel index 991668e546..c599173173 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -175,8 +175,11 @@ register_toolchains( "//proto/prost:default_prost_toolchain", ) +bindgen = use_extension("//bindgen:extension.bzl", "bindgen") +use_repo(bindgen, "bindgen_toolchains") + register_toolchains( - "//bindgen:default_bindgen_toolchain", + "@bindgen_toolchains//:default_bindgen_toolchain", ) rust_host_tools = use_extension("//rust:extensions.bzl", "rust_host_tools") diff --git a/bindgen/BUILD.bazel b/bindgen/BUILD.bazel index 0ee90783ba..69ead2c8fd 100644 --- a/bindgen/BUILD.bazel +++ b/bindgen/BUILD.bazel @@ -1,5 +1,4 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -load("//bindgen:defs.bzl", "rust_bindgen_toolchain") package(default_visibility = ["//visibility:public"]) @@ -11,21 +10,18 @@ bzl_library( name = "bzl_lib", srcs = glob(["**/*.bzl"]), deps = [ - "//bindgen/3rdparty:bzl_lib", - "//bindgen/private:bzl_lib", - "//rust:bzl_lib", + "@rules_rust//bindgen/3rdparty:bzl_lib", + "@rules_rust//bindgen/private:bzl_lib", + "@rules_rust//rust:bzl_lib", ], ) -rust_bindgen_toolchain( +alias( name = "default_bindgen_toolchain_impl", - bindgen = "//bindgen/3rdparty:bindgen", - clang = "@llvm-project//clang:clang", - libclang = "@llvm-project//clang:libclang", + actual = "//bindgen/toolchain:default_bindgen_toolchain_impl", ) -toolchain( +alias( name = "default_bindgen_toolchain", - toolchain = "default_bindgen_toolchain_impl", - toolchain_type = "//bindgen:toolchain_type", + actual = "//bindgen/toolchain:default_bindgen_toolchain", ) diff --git a/bindgen/extension.bzl b/bindgen/extension.bzl new file mode 100644 index 0000000000..9a3212c6df --- /dev/null +++ b/bindgen/extension.bzl @@ -0,0 +1,15 @@ +"""Module extension for accessing a bindgen toolchain""" + +load("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository") +load(":repositories.bzl", "rust_bindgen_dependencies") +load(":transitive_repositories.bzl", "rust_bindgen_transitive_dependencies") + +def _bindgen_impl(_): + rust_bindgen_transitive_dependencies() + rust_bindgen_dependencies() + local_repository( + name = "bindgen_toolchains", + path = "bindgen/toolchain/", + ) + +bindgen = module_extension(implementation = _bindgen_impl) diff --git a/bindgen/toolchain/BUILD.bazel b/bindgen/toolchain/BUILD.bazel new file mode 100644 index 0000000000..21af90e50d --- /dev/null +++ b/bindgen/toolchain/BUILD.bazel @@ -0,0 +1,16 @@ +load("@rules_rust//bindgen:defs.bzl", "rust_bindgen_toolchain") + +package(default_visibility = ["//visibility:public"]) + +rust_bindgen_toolchain( + name = "default_bindgen_toolchain_impl", + bindgen = "@rules_rust//bindgen/3rdparty:bindgen", + clang = "@llvm-project//clang:clang", + libclang = "@llvm-project//clang:libclang", +) + +toolchain( + name = "default_bindgen_toolchain", + toolchain = "default_bindgen_toolchain_impl", + toolchain_type = "@rules_rust//bindgen:toolchain_type", +) diff --git a/bindgen/toolchain/REPO.bazel b/bindgen/toolchain/REPO.bazel new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/bindgen/toolchain/REPO.bazel @@ -0,0 +1 @@ + diff --git a/bindgen/transitive_repositories.bzl b/bindgen/transitive_repositories.bzl index 66c80ee5fc..9a400c8e52 100644 --- a/bindgen/transitive_repositories.bzl +++ b/bindgen/transitive_repositories.bzl @@ -8,7 +8,6 @@ def rust_bindgen_transitive_dependencies(): llvm_configure( name = "llvm-project", - repo_mapping = {"@llvm_zlib": "@zlib"}, targets = [ "AArch64", "X86",