blob: e80ce2045365f150d3dde808e40a1178d7258940 [file] [log] [blame]
# 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(
"@pw_toolchain//cc_toolchain:defs.bzl",
"pw_cc_action_files",
"pw_cc_flag_set",
"pw_cc_toolchain",
)
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
filegroup(name = "empty")
pw_cc_flag_set(
name = "cortex-m0",
actions = [
"@pw_toolchain//actions:all_asm_actions",
"@pw_toolchain//actions:all_c_compiler_actions",
"@pw_toolchain//actions:all_cpp_compiler_actions",
"@pw_toolchain//actions:all_link_actions",
],
flags = [
"-mcpu=cortex-m0",
"-mfloat-abi=soft",
],
)
pw_cc_flag_set(
name = "cortex-m0plus",
actions = [
"@pw_toolchain//actions:all_asm_actions",
"@pw_toolchain//actions:all_c_compiler_actions",
"@pw_toolchain//actions:all_cpp_compiler_actions",
"@pw_toolchain//actions:all_link_actions",
],
flags = [
"-mcpu=cortex-m0plus",
"-mfloat-abi=soft",
],
)
pw_cc_flag_set(
name = "armv6m-none-eabi",
actions = [
"@pw_toolchain//actions:all_asm_actions",
"@pw_toolchain//actions:all_c_compiler_actions",
"@pw_toolchain//actions:all_cpp_compiler_actions",
"@pw_toolchain//actions:all_link_actions",
],
flags = [
"--target=armv6m-none-eabi",
],
)
pw_cc_flag_set(
name = "armv8m.main-none-eabi",
actions = [
"@pw_toolchain//actions:all_asm_actions",
"@pw_toolchain//actions:all_c_compiler_actions",
"@pw_toolchain//actions:all_cpp_compiler_actions",
"@pw_toolchain//actions:all_link_actions",
],
flags = [
"--target=armv8m.main-none-eabi",
],
)
pw_cc_flag_set(
name = "cxx_compiler_flags",
actions = [
"@pw_toolchain//actions:all_compiler_actions",
],
flags = [
"-fno-register-global-dtors-with-atexit",
"-fno-c++-static-destructors",
"-fno-use-cxa-atexit",
"-fno-threadsafe-statics",
"-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES",
],
)
pw_cc_flag_set(
name = "llvm-libc_link_flags",
actions = ["@pw_toolchain//actions:all_link_actions"],
flags = [
"-nostdlib++",
"-nostartfiles",
"-Wl,-lc++",
],
)
pw_cc_action_files(
name = "cxx-lib-config-files",
srcs = [
"//pw_libcxx:cxx_lib_configs",
],
actions = [
"@pw_toolchain//actions:all_compiler_actions",
],
)
pw_cc_action_files(
name = "llvm-libc_compile_files",
srcs = [
"@llvm_toolchain_device//:llvm-libc_arm-none-eabi_compile_files",
],
actions = [
"@pw_toolchain//actions:all_compiler_actions",
],
)
pw_cc_action_files(
name = "llvm-libc_link_files",
srcs = [
"@llvm_toolchain_device//:llvm-libc_arm-none-eabi_link_files",
],
actions = [
"@pw_toolchain//actions:all_link_actions",
],
)
pw_cc_flag_set(
name = "cortex_common",
actions = [
"@pw_toolchain//actions:all_c_compiler_actions",
"@pw_toolchain//actions:all_cpp_compiler_actions",
],
)
pw_cc_flag_set(
name = "cortex_common_link",
actions = ["@pw_toolchain//actions:all_link_actions"],
flags = [
"-Wl,--gc-sections",
],
)
# Additional arm_clang specific warning flags
pw_cc_flag_set(
name = "warnings",
actions = [
"@pw_toolchain//actions:all_c_compiler_actions",
"@pw_toolchain//actions:all_cpp_compiler_actions",
],
flags = [
# This can't be in common, because proto headers in host builds trigger
"-Wundef",
# Silence the really verbose ARM warnings.
"-Wno-psabi",
],
)
pw_cc_flag_set(
name = "thumb_abi",
actions = [
"@pw_toolchain//actions:all_asm_actions",
"@pw_toolchain//actions:all_c_compiler_actions",
"@pw_toolchain//actions:all_cpp_compiler_actions",
"@pw_toolchain//actions:all_link_actions",
],
flags = [
"-mabi=aapcs",
"-mthumb",
],
)
pw_cc_flag_set(
name = "cortex-m33",
actions = [
"@pw_toolchain//actions:all_asm_actions",
"@pw_toolchain//actions:all_c_compiler_actions",
"@pw_toolchain//actions:all_cpp_compiler_actions",
"@pw_toolchain//actions:all_link_actions",
],
flags = [
"-mcpu=cortex-m33",
"-mfloat-abi=soft",
],
)
pw_cc_toolchain(
name = "arm_clang_toolchain_cortex-m",
action_configs = [
"@llvm_toolchain_device//:ar",
"@llvm_toolchain_device//:clang",
"@llvm_toolchain_device//:clang++",
"@llvm_toolchain_device//:lld",
"@llvm_toolchain_device//:llvm-cov",
"@llvm_toolchain_device//:llvm-objcopy",
"@llvm_toolchain_device//:llvm-objdump",
"@llvm_toolchain_device//:llvm-strip",
],
compiler = "clang", # Useful for distinguishing gcc vs clang.
extra_action_files = [
":cxx-lib-config-files",
":llvm-libc_compile_files",
":llvm-libc_link_files",
],
flag_sets = [
":cxx_compiler_flags",
":llvm-libc_link_flags",
":thumb_abi",
":cortex_common",
":cortex_common_link",
":warnings",
"@pw_toolchain//flag_sets:oz",
"@pw_toolchain//flag_sets:debugging",
"@pw_toolchain//flag_sets:reduced_size",
"@pw_toolchain//flag_sets:no_canonical_prefixes",
"@pw_toolchain//flag_sets:no_rtti",
"@pw_toolchain//flag_sets:wno_register",
"@pw_toolchain//flag_sets:wnon_virtual_dtor",
"//pw_toolchain/cc:common_warnings",
"//pw_toolchain/cc:color_diagnostics",
] + select({
"@pw_toolchain//constraints/arm_mcpu:cortex-m0": [
":cortex-m0",
":armv6m-none-eabi",
],
"@pw_toolchain//constraints/arm_mcpu:cortex-m0plus": [
":cortex-m0plus",
":armv6m-none-eabi",
],
"@pw_toolchain//constraints/arm_mcpu:cortex-m33": [
":cortex-m33",
":armv8m.main-none-eabi",
],
"@pw_toolchain//constraints/arm_mcpu:none": [],
}),
tags = ["manual"], # Don't try to build this in wildcard builds.
target_compatible_with = select({
"@pw_toolchain//constraints/arm_mcpu:cortex-m0": [],
"@pw_toolchain//constraints/arm_mcpu:cortex-m0plus": [],
"@pw_toolchain//constraints/arm_mcpu:cortex-m33": [],
"@pw_toolchain//constraints/arm_mcpu:none": ["@platforms//:incompatible"],
}),
toolchain_features = [
"//pw_toolchain/cc:c++17_feature",
"//pw_toolchain/cc:c++20_feature",
],
toolchain_identifier = "arm-clang-toolchain",
visibility = ["//pw_toolchain:__pkg__"],
)
toolchain(
name = "arm_clang_cc_toolchain_cortex-m0",
target_compatible_with = [
"@pw_toolchain//constraints/arm_mcpu:cortex-m0",
],
toolchain = ":arm_clang_toolchain_cortex-m",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
toolchain(
name = "arm_clang_cc_toolchain_cortex-m0plus",
target_compatible_with = [
"@pw_toolchain//constraints/arm_mcpu:cortex-m0plus",
],
toolchain = ":arm_clang_toolchain_cortex-m",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
toolchain(
name = "arm_clang_cc_toolchain_cortex-m33",
target_compatible_with = [
"@pw_toolchain//constraints/arm_mcpu:cortex-m33",
],
toolchain = ":arm_clang_toolchain_cortex-m",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)