-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pw_toolchain: Migrate host clang to rules_cc toolchains
Migrates Pigweed to use the toolchain rules upstreamed to rules_cc. Bug: b/346388161 Change-Id: I692153827f1f2fc871828bc8f594dcf82378f5f5 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/207550 Pigweed-Auto-Submit: Armando Montanez <amontanez@google.com> Docs-Not-Needed: Armando Montanez <amontanez@google.com> Commit-Queue: Armando Montanez <amontanez@google.com> Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com> Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ted Pudlik <tpudlik@google.com>
- Loading branch information
1 parent
0ffb69d
commit 130903f
Showing
14 changed files
with
1,317 additions
and
3,104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# 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. | ||
|
||
package(default_visibility = ["//visibility:public"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# 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. | ||
"""A programatic list of all known Cortex-M CPUs.""" | ||
|
||
ALL_CORTEX_M_CPUS = ( | ||
"@platforms//cpu:armv6-m", | ||
"@platforms//cpu:armv7-m", | ||
"@platforms//cpu:armv7e-m", | ||
# TODO: https://github.com/bazelbuild/platforms/issues/100 - Kept for legacy | ||
# reasons. | ||
"@platforms//cpu:armv7e-mf", | ||
# TODO: https://github.com/bazelbuild/platforms/issues/104 - Kept for legacy | ||
# reasons. | ||
"@platforms//cpu:armv8-m", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# 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("@rules_cc//cc/toolchains:actions.bzl", "cc_action_type") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
# TODO: https://pwbug.dev/367352331 - Rename and upstream this to Bazel | ||
# (rules_cc, bazeltools). | ||
cc_action_type( | ||
name = "objdump", | ||
action_name = "objdump_embed_data", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,252 @@ | ||
# 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("@rules_cc//cc/toolchains:args.bzl", "cc_args") | ||
load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
# The common set of warnings for clang and arm_gcc. | ||
cc_args( | ||
name = "common_warnings", | ||
actions = [ | ||
"@rules_cc//cc/toolchains/actions:c_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:cpp_compile_actions", | ||
], | ||
args = [ | ||
"-Wall", | ||
"-Wextra", | ||
"-Wimplicit-fallthrough", | ||
"-Wcast-qual", | ||
"-Wpointer-arith", | ||
"-Wshadow", | ||
"-Wredundant-decls", | ||
# TODO: b/259746255 - Enable implicit conversion warnings once fixed. | ||
# "-Wconversion", | ||
# Make all warnings errors, except for the exemptions below. | ||
"-Werror", | ||
"-Wno-error=cpp", # preprocessor #warning statement | ||
"-Wno-error=deprecated-declarations", # [[deprecated]] attribute | ||
], | ||
) | ||
|
||
# This config contains warnings that are enabled for upstream Pigweed. | ||
# This config MUST NOT be used downstream to allow for warnings to be | ||
# added in the future without breaking downstream. | ||
cc_args( | ||
name = "internal_strict_warnings_flags", | ||
actions = [ | ||
"@rules_cc//cc/toolchains/actions:c_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:cpp_compile_actions", | ||
], | ||
args = [ | ||
"-Wswitch-enum", | ||
"-Wextra-semi", | ||
] + select({ | ||
"@platforms//os:windows": [], | ||
# TODO: b/243069432 - Enable pedantic warnings on Windows once passing. | ||
"//conditions:default": [":pedantic_warnings"], | ||
}), | ||
visibility = ["//:__subpackages__"], | ||
) | ||
|
||
# Add `--features=internal_strict_warnings` to your Bazel invocation to enable. | ||
cc_feature( | ||
name = "internal_strict_warnings", | ||
args = [":internal_strict_warnings_flags"], | ||
feature_name = "internal_strict_warnings", | ||
visibility = ["//:__subpackages__"], | ||
) | ||
|
||
# Allow uses of the register keyword, which may appear in C headers. | ||
cc_args( | ||
name = "wno_register", | ||
actions = ["@rules_cc//cc/toolchains/actions:cpp_compile_actions"], | ||
args = ["-Wno-register"], | ||
) | ||
|
||
# Issue a warning when a class appears to be polymorphic, yet it declares a | ||
# non-virtual destructor | ||
cc_args( | ||
name = "wnon_virtual_dtor", | ||
actions = ["@rules_cc//cc/toolchains/actions:cpp_compile_actions"], | ||
args = ["-Wnon-virtual-dtor"], | ||
) | ||
|
||
# Prevent relative paths from being converted to absolute paths. | ||
cc_args( | ||
name = "no_canonical_prefixes", | ||
actions = [ | ||
"@rules_cc//cc/toolchains/actions:c_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:cpp_compile_actions", | ||
], | ||
args = ["-no-canonical-prefixes"], | ||
) | ||
|
||
# Enables colors in compiler diagnostics. This uses the GCC spelling of the | ||
# flag, which Clang supports as an undocumented extension. | ||
cc_args( | ||
name = "color_diagnostics", | ||
actions = [ | ||
"@rules_cc//cc/toolchains/actions:assembly_actions", | ||
"@rules_cc//cc/toolchains/actions:c_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:cpp_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:link_actions", | ||
], | ||
args = ["-fdiagnostics-color"], | ||
) | ||
|
||
cc_args( | ||
name = "debugging", | ||
actions = [ | ||
"@rules_cc//cc/toolchains/actions:c_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:cpp_compile_actions", | ||
], | ||
args = ["-g"], | ||
) | ||
|
||
# Compile without runtime type information (RTTI). This produces smaller binaries. | ||
cc_args( | ||
name = "no_rtti", | ||
actions = ["@rules_cc//cc/toolchains/actions:cpp_compile_actions"], | ||
args = ["-fno-rtti"], | ||
) | ||
|
||
# Optimization level option | ||
cc_args( | ||
name = "o2", | ||
actions = [ | ||
"@rules_cc//cc/toolchains/actions:c_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:cpp_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:link_actions", | ||
], | ||
args = ["-O2"], | ||
) | ||
|
||
# Optimization aggressively for size rather than speed option | ||
cc_args( | ||
name = "oz", | ||
actions = [ | ||
"@rules_cc//cc/toolchains/actions:c_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:cpp_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:link_actions", | ||
], | ||
args = ["-Oz"], | ||
) | ||
|
||
# Standard compiler flags to reduce output binary size. | ||
cc_args( | ||
name = "reduced_size", | ||
actions = [ | ||
"@rules_cc//cc/toolchains/actions:c_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:cpp_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:link_actions", | ||
], | ||
args = [ | ||
"-fno-common", | ||
"-fno-exceptions", | ||
"-ffunction-sections", | ||
"-fdata-sections", | ||
], | ||
) | ||
|
||
cc_feature( | ||
name = "c++17_feature", | ||
args = [":c++17"], | ||
feature_name = "c++17", | ||
) | ||
|
||
# Compile for the C++17 standard. | ||
cc_args( | ||
name = "c++17", | ||
actions = [ | ||
"@rules_cc//cc/toolchains/actions:cpp_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:link_actions", | ||
], | ||
args = ["-std=c++17"], | ||
) | ||
|
||
cc_feature( | ||
name = "c++20_feature", | ||
args = [":c++20"], | ||
feature_name = "c++20", | ||
) | ||
|
||
# Compile for the C++20 standard. | ||
cc_args( | ||
name = "c++20", | ||
actions = [ | ||
"@rules_cc//cc/toolchains/actions:cpp_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:link_actions", | ||
], | ||
args = ["-std=c++20"], | ||
) | ||
|
||
cc_args( | ||
name = "asan", | ||
actions = [ | ||
"@rules_cc//cc/toolchains/actions:c_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:cpp_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:link_actions", | ||
], | ||
args = [ | ||
"-fsanitize=address", | ||
"-DADDRESS_SANITIZER", | ||
], | ||
) | ||
|
||
# TODO: https://pwbug.dev/346388161 - Push this to upstream rules_cc. | ||
cc_args( | ||
name = "ubsan", | ||
actions = [ | ||
"@rules_cc//cc/toolchains/actions:c_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:cpp_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:link_actions", | ||
], | ||
args = [ | ||
"-fsanitize=undefined", | ||
"-DUNDEFINED_SANITIZER", | ||
], | ||
) | ||
|
||
# TODO: https://pwbug.dev/346388161 - Push this to upstream rules_cc. | ||
cc_args( | ||
name = "tsan", | ||
actions = [ | ||
"@rules_cc//cc/toolchains/actions:c_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:cpp_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:link_actions", | ||
], | ||
args = [ | ||
"-fsanitize=thread", | ||
"-DTHREAD_SANITIZER", | ||
], | ||
) | ||
|
||
cc_args( | ||
name = "fuzztest", | ||
actions = [ | ||
"@rules_cc//cc/toolchains/actions:c_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:cpp_compile_actions", | ||
"@rules_cc//cc/toolchains/actions:link_actions", | ||
], | ||
args = [ | ||
"-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION", | ||
"-UNDEBUG", | ||
"-D_LIBCPP_ENABLE_ASSERTIONS=1", | ||
] + select({ | ||
"@platforms//cpu:x86_64": ["-mcrc32"], | ||
"//conditions:default": [], | ||
}), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# 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. | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
licenses(["notice"]) |
Oops, something went wrong.