Skip to content

Commit 3a86ae1

Browse files
committed
bindgen: Make libclang optional in the toolchain
1 parent cdaf15f commit 3a86ae1

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

extensions/bindgen/private/bindgen.bzl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,22 +216,24 @@ def _rust_bindgen_impl(ctx):
216216
toolchain = ctx.toolchains[Label("//:toolchain_type")]
217217
bindgen_bin = toolchain.bindgen
218218
clang_bin = toolchain.clang
219-
libclang = toolchain.libclang
220-
libstdcxx = toolchain.libstdcxx
219+
libclang = getattr(toolchain, "libclang", None)
220+
libstdcxx = getattr(toolchain, "libstdcxx", None)
221221

222222
output = ctx.outputs.out
223223

224224
cc_toolchain, feature_configuration = find_cc_toolchain(ctx = ctx)
225225

226226
tools = depset(([clang_bin] if clang_bin else []), transitive = [cc_toolchain.all_files])
227227

228-
# libclang should only have 1 output file
229-
libclang_dir = _get_libs_for_static_executable(libclang).to_list()[0].dirname
230-
231228
env = {
232-
"LIBCLANG_PATH": libclang_dir,
233229
"RUST_BACKTRACE": "1",
234230
}
231+
232+
if libclang:
233+
# libclang should only have 1 output file
234+
libclang_dir = _get_libs_for_static_executable(libclang).to_list()[0].dirname
235+
env["LIBCLANG_PATH"] = libclang_dir
236+
235237
if clang_bin:
236238
env["CLANG_PATH"] = clang_bin.path
237239

@@ -378,8 +380,9 @@ def _rust_bindgen_impl(ctx):
378380
[header],
379381
transitive = [
380382
cc_lib[CcInfo].compilation_context.headers,
381-
_get_libs_for_static_executable(libclang),
382383
] + ([
384+
_get_libs_for_static_executable(libclang),
385+
] if libclang else []) + ([
383386
_get_libs_for_static_executable(libstdcxx),
384387
] if libstdcxx else []),
385388
),
@@ -529,6 +532,7 @@ For additional information, see the [Bazel toolchains documentation](https://doc
529532
cfg = "exec",
530533
providers = [CcInfo],
531534
allow_files = True,
535+
mandatory = False,
532536
),
533537
"libstdcxx": attr.label(
534538
doc = "A cc_library that satisfies libclang's libstdc++ dependency. This is used to make the execution of clang hermetic. If None, system libraries will be used instead.",

0 commit comments

Comments
 (0)