Skip to content

Commit

Permalink
Expose bindgen toolchain through bzlmod
Browse files Browse the repository at this point in the history
  • Loading branch information
jwnrt committed Aug 30, 2024
1 parent 347f5c0 commit b8a817a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
5 changes: 4 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
18 changes: 7 additions & 11 deletions bindgen/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("//bindgen:defs.bzl", "rust_bindgen_toolchain")

package(default_visibility = ["//visibility:public"])

Expand All @@ -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",
)
15 changes: 15 additions & 0 deletions bindgen/extension.bzl
Original file line number Diff line number Diff line change
@@ -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(ctx):
rust_bindgen_transitive_dependencies()
rust_bindgen_dependencies()
local_repository(
name = "bindgen_toolchains",
path = str(ctx.path(Label("//bindgen/toolchain:BUILD.bazel")).dirname),
)

bindgen = module_extension(implementation = _bindgen_impl)
16 changes: 16 additions & 0 deletions bindgen/toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
)
1 change: 1 addition & 0 deletions bindgen/toolchain/REPO.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 0 additions & 1 deletion bindgen/transitive_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def rust_bindgen_transitive_dependencies():

llvm_configure(
name = "llvm-project",
repo_mapping = {"@llvm_zlib": "@zlib"},
targets = [
"AArch64",
"X86",
Expand Down

0 comments on commit b8a817a

Please sign in to comment.