Skip to content

Commit

Permalink
pw_toolchain: llvm_clang.BUILD -> llvm_clang_legacy.BUILD part 1/2
Browse files Browse the repository at this point in the history
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 🤖 <[email protected]>
Docs-Not-Needed: Armando Montanez <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
Reviewed-by: Ted Pudlik <[email protected]>
Pigweed-Auto-Submit: Armando Montanez <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
  • Loading branch information
armandomontanez authored and CQ Bot Account committed Sep 16, 2024
1 parent 170ea86 commit 461c43a
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 5 deletions.
4 changes: 2 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down
4 changes: 2 additions & 2 deletions pw_toolchain/register_toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ 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,
)

# 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,
)
Expand Down
230 changes: 230 additions & 0 deletions pw_toolchain_bazel/build_external/llvm_clang_legacy.BUILD
Original file line number Diff line number Diff line change
@@ -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"],
)
2 changes: 1 addition & 1 deletion pw_toolchain_bazel/get_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 461c43a

Please sign in to comment.