From 5ceebc08a482536a723e4414e327d8ada48b7f4d Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Mon, 18 Dec 2023 15:29:32 +0000 Subject: [PATCH] Include all toolchain files in the current toolchain (#2336) rustc assumes it can read things like librustc_driver, and if you don't include it, it gets sad. --- rust/private/toolchain_utils.bzl | 11 +---------- test/toolchain/BUILD.bazel | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/rust/private/toolchain_utils.bzl b/rust/private/toolchain_utils.bzl index c89a447e11..f92ad9ca76 100644 --- a/rust/private/toolchain_utils.bzl +++ b/rust/private/toolchain_utils.bzl @@ -81,20 +81,11 @@ toolchain_files = rule( def _current_rust_toolchain_impl(ctx): toolchain = ctx.toolchains[str(Label("@rules_rust//rust:toolchain_type"))] - files = [ - toolchain.rustc, - toolchain.rust_doc, - toolchain.cargo, - ] - - if toolchain.rustfmt: - files.append(toolchain.rustfmt) - return [ toolchain, toolchain.make_variables, DefaultInfo( - files = depset(files), + files = toolchain.all_files, ), ] diff --git a/test/toolchain/BUILD.bazel b/test/toolchain/BUILD.bazel index b42717221a..6400af931e 100644 --- a/test/toolchain/BUILD.bazel +++ b/test/toolchain/BUILD.bazel @@ -1,3 +1,19 @@ +load("@bazel_skylib//rules:build_test.bzl", "build_test") load(":toolchain_test.bzl", "toolchain_test_suite") toolchain_test_suite(name = "toolchain_test_suite") + +genrule( + name = "inspect", + outs = ["rustc-cfg"], + # rustc assumes it can read things like librustc_driver in order to run this command. + # This is a test to ensure we supply all of the files rustc needs as part of the current_rust_toolchain. + cmd = "$(RUSTC) --print=cfg > $@", + toolchains = ["@rules_rust//rust/toolchain:current_rust_toolchain"], + tools = ["@rules_rust//rust/toolchain:current_rust_toolchain"], +) + +build_test( + name = "inspect_build_test", + targets = [":inspect"], +)