1# Copyright 2024 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15load("@rules_cc//cc/toolchains:args.bzl", "cc_args") 16load("@rules_cc//cc/toolchains:toolchain.bzl", "cc_toolchain") 17 18package(default_visibility = ["//visibility:public"]) 19 20licenses(["notice"]) 21 22filegroup(name = "empty") 23 24cc_args( 25 name = "cortex-m0", 26 actions = [ 27 "@rules_cc//cc/toolchains/actions:assembly_actions", 28 "@rules_cc//cc/toolchains/actions:c_compile_actions", 29 "@rules_cc//cc/toolchains/actions:cpp_compile_actions", 30 "@rules_cc//cc/toolchains/actions:link_actions", 31 ], 32 args = [ 33 "-mcpu=cortex-m0", 34 "-mfloat-abi=soft", 35 ], 36) 37 38cc_args( 39 name = "cortex-m0plus", 40 actions = [ 41 "@rules_cc//cc/toolchains/actions:assembly_actions", 42 "@rules_cc//cc/toolchains/actions:c_compile_actions", 43 "@rules_cc//cc/toolchains/actions:cpp_compile_actions", 44 "@rules_cc//cc/toolchains/actions:link_actions", 45 ], 46 args = [ 47 "-mcpu=cortex-m0plus", 48 "-mfloat-abi=soft", 49 ], 50) 51 52cc_args( 53 name = "armv6m-none-eabi", 54 actions = [ 55 "@rules_cc//cc/toolchains/actions:assembly_actions", 56 "@rules_cc//cc/toolchains/actions:c_compile_actions", 57 "@rules_cc//cc/toolchains/actions:cpp_compile_actions", 58 "@rules_cc//cc/toolchains/actions:link_actions", 59 ], 60 args = [ 61 "--target=armv6m-none-eabi", 62 ], 63) 64 65cc_args( 66 name = "armv8m.main-none-eabi", 67 actions = [ 68 "@rules_cc//cc/toolchains/actions:assembly_actions", 69 "@rules_cc//cc/toolchains/actions:c_compile_actions", 70 "@rules_cc//cc/toolchains/actions:cpp_compile_actions", 71 "@rules_cc//cc/toolchains/actions:link_actions", 72 ], 73 args = [ 74 "--target=armv8m.main-none-eabi", 75 ], 76) 77 78cc_args( 79 name = "cxx_compiler_flags", 80 actions = [ 81 "@rules_cc//cc/toolchains/actions:compile_actions", 82 ], 83 args = [ 84 "-fno-register-global-dtors-with-atexit", 85 "-fno-c++-static-destructors", 86 "-fno-use-cxa-atexit", 87 "-fno-threadsafe-statics", 88 "-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES", 89 ], 90 data = [ 91 "//pw_libcxx:cxx_lib_configs", 92 ], 93) 94 95cc_args( 96 name = "cortex_common", 97 actions = [ 98 "@rules_cc//cc/toolchains/actions:c_compile_actions", 99 "@rules_cc//cc/toolchains/actions:cpp_compile_actions", 100 ], 101) 102 103cc_args( 104 name = "cortex_common_link", 105 actions = ["@rules_cc//cc/toolchains/actions:link_actions"], 106 args = [ 107 "-Wl,--gc-sections", 108 ], 109) 110 111# Additional arm_clang specific warning flags 112cc_args( 113 name = "warnings", 114 actions = [ 115 "@rules_cc//cc/toolchains/actions:c_compile_actions", 116 "@rules_cc//cc/toolchains/actions:cpp_compile_actions", 117 ], 118 args = [ 119 # This can't be in common, because proto headers in host builds trigger 120 "-Wundef", 121 # Silence the really verbose ARM warnings. 122 "-Wno-psabi", 123 ], 124) 125 126cc_args( 127 name = "thumb_abi", 128 actions = [ 129 "@rules_cc//cc/toolchains/actions:assembly_actions", 130 "@rules_cc//cc/toolchains/actions:c_compile_actions", 131 "@rules_cc//cc/toolchains/actions:cpp_compile_actions", 132 "@rules_cc//cc/toolchains/actions:link_actions", 133 ], 134 args = [ 135 "-mabi=aapcs", 136 "-mthumb", 137 ], 138) 139 140cc_args( 141 name = "cortex-m33", 142 actions = [ 143 "@rules_cc//cc/toolchains/actions:assembly_actions", 144 "@rules_cc//cc/toolchains/actions:c_compile_actions", 145 "@rules_cc//cc/toolchains/actions:cpp_compile_actions", 146 "@rules_cc//cc/toolchains/actions:link_actions", 147 ], 148 args = [ 149 "-mcpu=cortex-m33", 150 "-mfloat-abi=soft", 151 ], 152) 153 154cc_toolchain( 155 name = "arm_clang_toolchain_cortex-m", 156 args = [ 157 ":cxx_compiler_flags", 158 "@llvm_toolchain_device//:llvm-libc_args", 159 ":thumb_abi", 160 ":cortex_common", 161 ":cortex_common_link", 162 ":warnings", 163 "//pw_toolchain/cc/args:oz", 164 "//pw_toolchain/cc/args:debugging", 165 "//pw_toolchain/cc/args:reduced_size", 166 "//pw_toolchain/cc/args:no_canonical_prefixes", 167 "//pw_toolchain/cc/args:no_rtti", 168 "//pw_toolchain/cc/args:wno_register", 169 "//pw_toolchain/cc/args:wnon_virtual_dtor", 170 "//pw_toolchain/cc/args:common_warnings", 171 "//pw_toolchain/cc/args:color_diagnostics", 172 ] + select({ 173 "@pw_toolchain//constraints/arm_mcpu:cortex-m0": [ 174 ":cortex-m0", 175 ":armv6m-none-eabi", 176 ], 177 "@pw_toolchain//constraints/arm_mcpu:cortex-m0plus": [ 178 ":cortex-m0plus", 179 ":armv6m-none-eabi", 180 ], 181 "@pw_toolchain//constraints/arm_mcpu:cortex-m33": [ 182 ":cortex-m33", 183 ":armv8m.main-none-eabi", 184 ], 185 "@pw_toolchain//constraints/arm_mcpu:none": [], 186 }), 187 enabled_features = [ 188 "@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features", 189 "//pw_toolchain/cc/capability:compiler_is_clang", 190 "//pw_toolchain/cc/capability:linker_is_clang", 191 ] + select({ 192 "//pw_toolchain/cc:c++17_enabled": ["//pw_toolchain/cc/args:c++17_feature"], 193 "//conditions:default": [], 194 }) + select({ 195 "//pw_toolchain/cc:c++20_enabled": ["//pw_toolchain/cc/args:c++20_feature"], 196 "//conditions:default": [], 197 }), 198 tags = ["manual"], # Don't try to build this in wildcard builds. 199 target_compatible_with = select({ 200 "@pw_toolchain//constraints/arm_mcpu:cortex-m0": [], 201 "@pw_toolchain//constraints/arm_mcpu:cortex-m0plus": [], 202 "@pw_toolchain//constraints/arm_mcpu:cortex-m33": [], 203 "@pw_toolchain//constraints/arm_mcpu:none": ["@platforms//:incompatible"], 204 }), 205 tool_map = "@llvm_toolchain_device//:all_tools", 206 visibility = ["//pw_toolchain:__pkg__"], 207) 208 209toolchain( 210 name = "arm_clang_cc_toolchain_cortex-m0", 211 target_compatible_with = [ 212 "@pw_toolchain//constraints/arm_mcpu:cortex-m0", 213 ], 214 toolchain = ":arm_clang_toolchain_cortex-m", 215 toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", 216) 217 218toolchain( 219 name = "arm_clang_cc_toolchain_cortex-m0plus", 220 target_compatible_with = [ 221 "@pw_toolchain//constraints/arm_mcpu:cortex-m0plus", 222 ], 223 toolchain = ":arm_clang_toolchain_cortex-m", 224 toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", 225) 226 227toolchain( 228 name = "arm_clang_cc_toolchain_cortex-m33", 229 target_compatible_with = [ 230 "@pw_toolchain//constraints/arm_mcpu:cortex-m33", 231 ], 232 toolchain = ":arm_clang_toolchain_cortex-m", 233 toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", 234) 235