From 6a140b21a8d1241cda4d1eda4f792748948b3153 Mon Sep 17 00:00:00 2001 From: Marcel Hlopko Date: Wed, 17 Jul 2024 16:00:46 +0200 Subject: [PATCH] Make rustfmt toolchain optional in bindgen (#2744) --- 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 c598b14de1..2155ccadff 100644 --- a/bindgen/private/bindgen.bzl +++ b/bindgen/private/bindgen.bzl @@ -235,7 +235,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]) @@ -379,10 +379,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"), ], )