From b918438adf9b07ad557e81e7a66d68c00db21e7b Mon Sep 17 00:00:00 2001 From: Oliver Lee Date: Mon, 16 Jan 2023 13:17:51 -0800 Subject: [PATCH] Define aliased tools as native binaries (#171) Define aliased tools as native binaries instead of simple file aliases, so that their `files_to_run.executable` attribute can be used in starlark. --- toolchain/BUILD.toolchain.tpl | 1 + toolchain/aliases.bzl | 2 ++ toolchain/deps.bzl | 13 +++++++++++++ toolchain/internal/configure.bzl | 5 +++-- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/toolchain/BUILD.toolchain.tpl b/toolchain/BUILD.toolchain.tpl index 97f7982a..1200c170 100644 --- a/toolchain/BUILD.toolchain.tpl +++ b/toolchain/BUILD.toolchain.tpl @@ -14,6 +14,7 @@ package(default_visibility = ["//visibility:public"]) +load("@bazel_skylib//rules:native_binary.bzl", "native_binary") load("@rules_cc//cc:defs.bzl", "cc_toolchain", "cc_toolchain_suite") load("%{cc_toolchain_config_bzl}", "cc_toolchain_config") diff --git a/toolchain/aliases.bzl b/toolchain/aliases.bzl index 86bf8ac7..67b08a6b 100644 --- a/toolchain/aliases.bzl +++ b/toolchain/aliases.bzl @@ -20,6 +20,8 @@ aliased_libs = [ ] aliased_tools = [ + "clang-apply-replacements", "clang-format", + "clang-tidy", "llvm-cov", ] diff --git a/toolchain/deps.bzl b/toolchain/deps.bzl index bb6f8264..bbe66b2a 100644 --- a/toolchain/deps.bzl +++ b/toolchain/deps.bzl @@ -23,3 +23,16 @@ def bazel_toolchain_dependencies(): strip_prefix = "rules_cc-726dd8157557f1456b3656e26ab21a1646653405", urls = ["https://github.com/bazelbuild/rules_cc/archive/726dd8157557f1456b3656e26ab21a1646653405.tar.gz"], ) + + # Load bazel_skylib if the user has not defined them. + if not native.existing_rule("bazel_skylib"): + http_archive( + name = "bazel_skylib", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz", + ], + sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506", + ) + + # Skip bazel_skylib_workspace because we are not using lib/unittest.bzl diff --git a/toolchain/internal/configure.bzl b/toolchain/internal/configure.bzl index 10c02b34..02651ca8 100644 --- a/toolchain/internal/configure.bzl +++ b/toolchain/internal/configure.bzl @@ -511,9 +511,10 @@ cc_import( tool_target_strs = [] for name in _aliased_tools: template = """ -alias( +native_binary( name = "{name}", - actual = "{{llvm_dist_label_prefix}}bin/{name}", + out = "{name}", + src = "{{llvm_dist_label_prefix}}bin/{name}", )""".format(name = name) tool_target_strs.append(template)