| # Copyright 2026 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") |
| load("@rules_cc//cc/toolchains:toolchain.bzl", "cc_toolchain") |
| load("//build_config:repo_paths.bzl", "get_repo_root") |
| |
| package(default_visibility = ["//visibility:public"]) |
| |
| licenses(["notice"]) |
| |
| # Additional arm_gcc specific warning flags |
| cc_args( |
| name = "warnings", |
| actions = [ |
| "@rules_cc//cc/toolchains/actions:compile_actions", |
| ], |
| args = [ |
| # This can't be in common, because proto headers in host builds trigger |
| "-Wundef", |
| # Silence the really verbose ARM warnings. |
| "-Wno-psabi", |
| ], |
| ) |
| |
| cc_args( |
| name = "thumb_abi", |
| actions = [ |
| "@rules_cc//cc/toolchains/actions:assembly_actions", |
| "@rules_cc//cc/toolchains/actions:compile_actions", |
| "@rules_cc//cc/toolchains/actions:link_actions", |
| ], |
| args = [ |
| "-mabi=aapcs", |
| "-mthumb", |
| ], |
| ) |
| |
| # This flag prevents Arm GCC from printing the resolved paths of symlinks, |
| # which prevents compilation actions from being hermetic. See |
| # https://github.com/bazelbuild/bazel/issues/21981 and |
| # https://pwbug.dev/319665090. |
| cc_args( |
| name = "no_canonical_system_headers", |
| actions = [ |
| "@rules_cc//cc/toolchains/actions:compile_actions", |
| ], |
| args = [ |
| "-fno-canonical-system-headers", |
| ], |
| ) |
| |
| cc_args( |
| name = "cortex_common", |
| actions = [ |
| "@rules_cc//cc/toolchains/actions:compile_actions", |
| ], |
| ) |
| |
| cc_feature( |
| name = "cortex_libc", |
| args = [":cortex_common_link"], |
| feature_name = "cortex_libc_linking", |
| ) |
| |
| cc_args( |
| name = "cortex_common_link", |
| actions = ["@rules_cc//cc/toolchains/actions:link_actions"], |
| args = [ |
| "-Wl,--gc-sections", |
| "-lstdc++", |
| "-lc", |
| "-lm", |
| ], |
| ) |
| |
| cc_args( |
| name = "cortex-m4", |
| actions = [ |
| "@rules_cc//cc/toolchains/actions:assembly_actions", |
| "@rules_cc//cc/toolchains/actions:compile_actions", |
| "@rules_cc//cc/toolchains/actions:link_actions", |
| ], |
| args = [ |
| "-mcpu=cortex-m4", |
| ], |
| ) |
| |
| cc_args( |
| name = "cortex-m7", |
| actions = [ |
| "@rules_cc//cc/toolchains/actions:assembly_actions", |
| "@rules_cc//cc/toolchains/actions:compile_actions", |
| "@rules_cc//cc/toolchains/actions:link_actions", |
| ], |
| args = [ |
| "-mcpu=cortex-m7", |
| ], |
| ) |
| |
| cc_args( |
| name = "cortex-m33", |
| actions = [ |
| "@rules_cc//cc/toolchains/actions:assembly_actions", |
| "@rules_cc//cc/toolchains/actions:compile_actions", |
| "@rules_cc//cc/toolchains/actions:link_actions", |
| ], |
| args = [ |
| "-mcpu=cortex-m33", |
| ], |
| ) |
| |
| cc_args( |
| name = "cortex-m55", |
| actions = [ |
| "@rules_cc//cc/toolchains/actions:assembly_actions", |
| "@rules_cc//cc/toolchains/actions:compile_actions", |
| "@rules_cc//cc/toolchains/actions:link_actions", |
| ], |
| args = [ |
| "-mcpu=cortex-m55", |
| ], |
| ) |
| |
| cc_args( |
| name = "cortex-m85", |
| actions = [ |
| "@rules_cc//cc/toolchains/actions:assembly_actions", |
| "@rules_cc//cc/toolchains/actions:compile_actions", |
| "@rules_cc//cc/toolchains/actions:link_actions", |
| ], |
| args = [ |
| "-mcpu=cortex-m85", |
| ], |
| ) |
| |
| _ZEPHYR_SDK_ARM_TOOLCHAIN_ROOT = get_repo_root("@zephyr_sdk_arm") |
| |
| # In some cases, Zephyr adds "-nostdinc" flag to the compiler flags, and that |
| # will mask compiler includes like stddef.h. Zephyr adds them back using |
| # -isystem. We do it here. |
| cc_args( |
| name = "add_stddef", |
| actions = [ |
| "@rules_cc//cc/toolchains/actions:c_compile_actions", |
| "@rules_cc//cc/toolchains/actions:cpp_compile_actions", |
| ], |
| args = [ |
| "-isystem", |
| _ZEPHYR_SDK_ARM_TOOLCHAIN_ROOT + "/lib/gcc/arm-zephyr-eabi/12.2.0/include", |
| "-isystem", |
| _ZEPHYR_SDK_ARM_TOOLCHAIN_ROOT + "/lib/gcc/arm-zephyr-eabi/12.2.0/include-fixed", |
| ], |
| ) |
| |
| cc_args( |
| name = "add_cxx_headers", |
| actions = [ |
| "@rules_cc//cc/toolchains/actions:cpp_compile_actions", |
| ], |
| args = [ |
| "-isystem", |
| _ZEPHYR_SDK_ARM_TOOLCHAIN_ROOT + "/arm-zephyr-eabi/include/c++/12.2.0", |
| "-isystem", |
| _ZEPHYR_SDK_ARM_TOOLCHAIN_ROOT + "/arm-zephyr-eabi/include/c++/12.2.0/arm-zephyr-eabi", |
| ], |
| ) |
| |
| cc_toolchain( |
| name = "cortex-m_gcc", |
| args = [ |
| "//toolchain/args:oz", |
| "//toolchain/args:debugging", |
| "//toolchain/args:reduced_size", |
| "//toolchain/args:no_canonical_prefixes", |
| "//toolchain/args:common_warnings", |
| "//toolchain/args:color_diagnostics", |
| "//toolchain/args:zephyr_common", |
| ] + select({ |
| "@zephyr//constraints/arm:cortex-m33": [":cortex-m33"], |
| "@zephyr//constraints/arm:cortex-m4": [":cortex-m4"], |
| "@zephyr//constraints/arm:cortex-m7": [":cortex-m7"], |
| "@zephyr//constraints/arm:cortex-m55": [":cortex-m55"], |
| "@zephyr//constraints/arm:cortex-m85": [":cortex-m85"], |
| "@zephyr//constraints/arm:none": [], |
| }) + [ |
| ":thumb_abi", |
| ":cortex_common", |
| ":no_canonical_system_headers", |
| ":warnings", |
| ":add_stddef", |
| ":add_cxx_headers", |
| ], |
| enabled_features = [ |
| "@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features", |
| "//toolchain/capability:compiler_is_gcc", |
| "//toolchain/capability:linker_is_gcc", |
| # This MUST be the last feature!!!! |
| ":cortex_libc", |
| ], |
| known_features = [ |
| "//toolchain/capability:known_toolchain_types", |
| ], |
| supports_param_files = 0, |
| tags = ["manual"], |
| tool_map = "@zephyr_sdk_arm//:arm_tools", |
| ) |
| |
| toolchain( |
| name = "cortex-m_gcc_cc_cortex-m4", |
| target_compatible_with = [ |
| "@zephyr//constraints/arm:cortex-m4", |
| ], |
| toolchain = ":cortex-m_gcc", |
| toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", |
| ) |
| |
| toolchain( |
| name = "cortex-m_gcc_cc_cortex-m7", |
| target_compatible_with = [ |
| "@zephyr//constraints/arm:cortex-m7", |
| ], |
| toolchain = ":cortex-m_gcc", |
| toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", |
| ) |
| |
| toolchain( |
| name = "cortex-m_gcc_cc_cortex-m33", |
| target_compatible_with = [ |
| "@zephyr//constraints/arm:cortex-m33", |
| ], |
| toolchain = ":cortex-m_gcc", |
| toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", |
| ) |
| |
| toolchain( |
| name = "cortex-m_gcc_cc_cortex-m55", |
| target_compatible_with = [ |
| "@zephyr//constraints/arm:cortex-m55", |
| ], |
| toolchain = ":cortex-m_gcc", |
| toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", |
| ) |
| |
| toolchain( |
| name = "cortex-m_gcc_cc_cortex-m85", |
| target_compatible_with = [ |
| "@zephyr//constraints/arm:cortex-m85", |
| ], |
| toolchain = ":cortex-m_gcc", |
| toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", |
| ) |