From 812ccc5cb0b7e91fd2223a546adc2a71269c37fb Mon Sep 17 00:00:00 2001 From: Marcel Hlopko Date: Tue, 16 Jul 2024 11:26:06 +0200 Subject: [PATCH] Make rustfmt toolchain optional in bindgen --- bindgen/private/bindgen.bzl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bindgen/private/bindgen.bzl b/bindgen/private/bindgen.bzl index 06f0595db2..3732fa9a29 100644 --- a/bindgen/private/bindgen.bzl +++ b/bindgen/private/bindgen.bzl @@ -234,7 +234,7 @@ def _rust_bindgen_impl(ctx): # Vanilla usage of bindgen produces formatted output, here we do the same if we have `rustfmt` in our toolchain. rustfmt_toolchain = ctx.toolchains[Label("//rust/rustfmt:toolchain_type")] - if toolchain.default_rustfmt: + if rustfmt_toolchain and toolchain.default_rustfmt: # Bindgen is able to find rustfmt using the RUSTFMT environment variable env.update({"RUSTFMT": rustfmt_toolchain.rustfmt.path}) tools = depset(transitive = [tools, rustfmt_toolchain.all_files]) @@ -375,10 +375,10 @@ rust_bindgen = rule( outputs = {"out": "%{name}.rs"}, fragments = ["cpp"], toolchains = [ - str(Label("//bindgen:toolchain_type")), - str(Label("//rust:toolchain_type")), - str(Label("//rust/rustfmt:toolchain_type")), - "@bazel_tools//tools/cpp:toolchain_type", + config_common.toolchain_type("//bindgen:toolchain_type"), + config_common.toolchain_type("//rust:toolchain_type"), + config_common.toolchain_type("//rust/rustfmt:toolchain_type", mandatory = False), + config_common.toolchain_type("@bazel_tools//tools/cpp:toolchain_type"), ], )