From 461c43a49e425e973644b4a58ebc5a2ab3e86c04 Mon Sep 17 00:00:00 2001 From: Armando Montanez Date: Mon, 16 Sep 2024 22:25:18 +0000 Subject: [PATCH] pw_toolchain: llvm_clang.BUILD -> llvm_clang_legacy.BUILD part 1/2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Copies the toolchain build file to an alternative name as part of a non-breaking transition to move the file. Bug: b/346388161 Change-Id: I088b11a466df859b27e7b75d0e2e90cae43317c7 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/229730 Lint: Lint 🤖 Docs-Not-Needed: Armando Montanez Commit-Queue: Auto-Submit Reviewed-by: Ted Pudlik Pigweed-Auto-Submit: Armando Montanez Presubmit-Verified: CQ Bot Account --- MODULE.bazel | 4 +- pw_toolchain/register_toolchains.bzl | 4 +- .../build_external/llvm_clang_legacy.BUILD | 230 ++++++++++++++++++ pw_toolchain_bazel/get_started.rst | 2 +- 4 files changed, 235 insertions(+), 5 deletions(-) create mode 100644 pw_toolchain_bazel/build_external/llvm_clang_legacy.BUILD diff --git a/MODULE.bazel b/MODULE.bazel index f323cca804..ed176ddaf0 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -119,14 +119,14 @@ cipd_repository = use_repo_rule("//pw_env_setup/bazel/cipd_setup:cipd_rules.bzl" # Fetch llvm toolchain. cipd_repository( name = "llvm_toolchain", - build_file = "@pw_toolchain//build_external:llvm_clang.BUILD", + build_file = "@pw_toolchain//build_external:llvm_clang_legacy.BUILD", path = "fuchsia/third_party/clang/${os}-${arch}", tag = "git_revision:c58bc24fcf678c55b0bf522be89eff070507a005", ) cipd_repository( name = "llvm_toolchain_device", - build_file = "@pw_toolchain//build_external:llvm_clang.BUILD", + build_file = "@pw_toolchain//build_external:llvm_clang_legacy.BUILD", path = "fuchsia/third_party/clang/${os}-${arch}", tag = "git_revision:0dcada94bb1ae79f0edd91013038098c62a96b3b", ) diff --git a/pw_toolchain/register_toolchains.bzl b/pw_toolchain/register_toolchains.bzl index e90ccae849..d6680d53fe 100644 --- a/pw_toolchain/register_toolchains.bzl +++ b/pw_toolchain/register_toolchains.bzl @@ -70,7 +70,7 @@ def register_pigweed_cxx_toolchains( # Fetch llvm toolchain for device. cipd_repository( name = "llvm_toolchain_device", - build_file = "@pw_toolchain//build_external:llvm_clang.BUILD", + build_file = "@pw_toolchain//build_external:llvm_clang_legacy.BUILD", path = "fuchsia/third_party/clang/${os}-${arch}", tag = "git_revision:b5e4d323badbd24324bfab4366b670977b16df07" if not clang_tag else clang_tag, ) @@ -78,7 +78,7 @@ def register_pigweed_cxx_toolchains( # Fetch llvm toolchain for host. cipd_repository( name = "llvm_toolchain", - build_file = "@pw_toolchain//build_external:llvm_clang.BUILD", + build_file = "@pw_toolchain//build_external:llvm_clang_legacy.BUILD", path = "fuchsia/third_party/clang/${os}-${arch}", tag = "git_revision:e894df6392beea3723627329009f3e6d51d16f47" if not clang_tag else clang_tag, ) diff --git a/pw_toolchain_bazel/build_external/llvm_clang_legacy.BUILD b/pw_toolchain_bazel/build_external/llvm_clang_legacy.BUILD new file mode 100644 index 0000000000..16ac06a5ca --- /dev/null +++ b/pw_toolchain_bazel/build_external/llvm_clang_legacy.BUILD @@ -0,0 +1,230 @@ +# Copyright 2024 The Pigweed Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +load("@bazel_skylib//rules:native_binary.bzl", "native_binary") +load( + "@pw_toolchain//cc_toolchain:defs.bzl", + "pw_cc_action_config", + "pw_cc_tool", +) + +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +# This build file defines a complete set of tools for a LLVM-based toolchain. + +exports_files(glob(["**"])) + +filegroup( + name = "all", + srcs = glob(["**"]), + visibility = ["//visibility:public"], +) + +filegroup( + name = "llvm-libc_arm-none-eabi_compile_files", + srcs = glob([ + "include/armv*-unknown-none-eabi/**", + ]), + visibility = ["//visibility:public"], +) + +filegroup( + name = "llvm-libc_arm-none-eabi_link_files", + srcs = glob([ + "lib/armv*-unknown-none-eabi/**", + "lib/clang/*/lib/armv*-unknown-none-eabi/**", + ]), + visibility = ["//visibility:public"], +) + +# TODO(amontanez): Add sysroot for macos to the `data` field selection once +# Pigweed migrates to use rules_cc toolchains. +native_binary( + name = "clang-tidy", + src = select({ + "@platforms//os:windows": "//:bin/clang-tidy.exe", + "//conditions:default": "//:bin/clang-tidy", + }), + data = glob([ + "include/**", + "lib/clang/**/include/**", + ]) + select({ + "@platforms//os:linux": ["@linux_sysroot//:all"], + "//conditions:default": [], + }), + out = select({ + "@platforms//os:windows": "clang-tidy.exe", + "//conditions:default": "clang-tidy", + }), + visibility = ["//visibility:public"], +) + +pw_cc_tool( + name = "ar_tool", + tool = select({ + "@platforms//os:windows": "//:bin/llvm-ar.exe", + "//conditions:default": "//:bin/llvm-ar", + }), + additional_files = glob(["bin/llvm"]), +) + +pw_cc_tool( + name = "llvm_libtool_darwin_tool", + tool = "//:bin/llvm-libtool-darwin", + additional_files = glob(["bin/llvm"]), +) + +pw_cc_action_config( + name = "ar", + action_names = ["@pw_toolchain//actions:all_ar_actions"], + # Unlike most legacy features required to compile code, these features + # aren't enabled by default, and are instead only implied by the built-in + # action configs. We imply the features here to match the behavior of the + # built-in action configs so flags are actually passed to `ar`. + implies = [ + "@pw_toolchain//features/legacy:archiver_flags", + "@pw_toolchain//features/legacy:linker_param_file", + ], + tools = select({ + "@platforms//os:macos": [":llvm_libtool_darwin_tool"], + "//conditions:default": [":ar_tool"], + }), +) + +pw_cc_tool( + name = "clang++_tool", + tool = select({ + "@platforms//os:windows": "//:bin/clang++.exe", + "//conditions:default": "//:bin/clang++", + }), + additional_files = glob([ + "bin/llvm", + "include/**", + "lib/clang/**/include/**", + ]), +) + +pw_cc_action_config( + name = "clang++", + action_names = ["@pw_toolchain//actions:all_cpp_compiler_actions"], + tools = [":clang++_tool"], +) + +pw_cc_tool( + name = "clang_tool", + tool = select({ + "@platforms//os:windows": "//:bin/clang.exe", + "//conditions:default": "//:bin/clang", + }), + additional_files = glob([ + "bin/llvm", + "include/**", + "lib/clang/**/include/**", + ]), +) + +pw_cc_action_config( + name = "clang", + action_names = [ + "@pw_toolchain//actions:all_asm_actions", + "@pw_toolchain//actions:all_c_compiler_actions", + ], + tools = [":clang_tool"], +) + +# This tool is actually just clang++ under the hood, we just enumerate this +# tool differently to specify a different set of additional files. +pw_cc_tool( + name = "lld_tool", + tool = select({ + "@platforms//os:windows": "//:bin/clang++.exe", + "//conditions:default": "//:bin/clang++", + }), + additional_files = glob([ + "bin/llvm", + "bin/lld*", + "bin/ld*", + "lib/**/*.a", + "lib/**/*.so*", + "lib/**/*.o", + ]), +) + +pw_cc_action_config( + name = "lld", + action_names = ["@pw_toolchain//actions:all_link_actions"], + tools = [":lld_tool"], +) + +pw_cc_tool( + name = "llvm_cov_tool", + tool = select({ + "@platforms//os:windows": "//:bin/llvm-cov.exe", + "//conditions:default": "//:bin/llvm-cov", + }), + additional_files = glob(["bin/llvm"]), +) + +pw_cc_action_config( + name = "llvm-cov", + action_names = ["@pw_toolchain//actions:all_coverage_actions"], + tools = [":llvm_cov_tool"], +) + +pw_cc_tool( + name = "llvm_objcopy_tool", + tool = select({ + "@platforms//os:windows": "//:bin/llvm-objcopy.exe", + "//conditions:default": "//:bin/llvm-objcopy", + }), + additional_files = glob(["bin/llvm"]), +) + +pw_cc_action_config( + name = "llvm-objcopy", + action_names = ["@pw_toolchain//actions:all_objcopy_actions"], + tools = [":llvm_objcopy_tool"], +) + +pw_cc_tool( + name = "llvm_objdump_tool", + tool = select({ + "@platforms//os:windows": "//:bin/llvm-objdump.exe", + "//conditions:default": "//:bin/llvm-objdump", + }), + additional_files = glob(["bin/llvm"]), +) + +pw_cc_action_config( + name = "llvm-objdump", + action_names = ["@pw_toolchain//actions:all_objdump_actions"], + tools = [":llvm_objdump_tool"], +) + +pw_cc_tool( + name = "llvm_strip_tool", + tool = select({ + "@platforms//os:windows": "//:bin/llvm-strip.exe", + "//conditions:default": "//:bin/llvm-strip", + }), + additional_files = glob(["bin/llvm"]), +) + +pw_cc_action_config( + name = "llvm-strip", + action_names = ["@pw_toolchain//actions:all_strip_actions"], + tools = [":llvm_strip_tool"], +) diff --git a/pw_toolchain_bazel/get_started.rst b/pw_toolchain_bazel/get_started.rst index 946dd8cb68..f059c7faa8 100644 --- a/pw_toolchain_bazel/get_started.rst +++ b/pw_toolchain_bazel/get_started.rst @@ -140,7 +140,7 @@ package. These build files can be attached to an external repository in your # Declare a toolchain tool suite for Linux. http_archive( name = "linux_clang_toolchain", - build_file = "@pw_toolchain//build_external:llvm_clang.BUILD", + build_file = "@pw_toolchain//build_external:llvm_clang_legacy.BUILD", sha256 = "884ee67d647d77e58740c1e645649e29ae9e8a6fe87c1376be0f3a30f3cc9ab3", strip_prefix = "clang+llvm-17.0.6-x86_64-linux-gnu-ubuntu-22.04", url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.6/clang+llvm-17.0.6-x86_64-linux-gnu-ubuntu-22.04.tar.xz",