blob: 791a13e1dc2777bec0aa68a21203131fe06a2aec [file] [edit]
# 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:toolchain.bzl", "cc_toolchain")
load("//build_config:repo_paths.bzl", "get_repo_root")
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
# This pairs with symbol_garbage_collection to allow symbols to be garbage
# collected by the linker.
cc_args(
name = "data_and_function_sections",
actions = [
"@rules_cc//cc/toolchains/actions:assembly_actions",
"@rules_cc//cc/toolchains/actions:c_compile_actions",
"@rules_cc//cc/toolchains/actions:cpp_compile_actions",
],
args = [
"-ffunction-sections",
"-fdata-sections",
],
)
_ZEPHYR_SDK_DC233C_TOOLCHAIN_ROOT = get_repo_root("@zephyr_sdk_xtensa_dc233c")
# 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_DC233C_TOOLCHAIN_ROOT + "/lib/gcc/xtensa-dc233c_zephyr-elf/12.2.0/include",
"-isystem",
_ZEPHYR_SDK_DC233C_TOOLCHAIN_ROOT + "/lib/gcc/xtensa-dc233c_zephyr-elf/12.2.0/include-fixed",
],
)
cc_args(
name = "symbol_garbage_collection",
actions = ["@rules_cc//cc/toolchains/actions:link_actions"],
args = ["-Wl,--gc-sections"],
)
cc_args(
name = "print_memory_usage",
actions = ["@rules_cc//cc/toolchains/actions:link_actions"],
args = ["-Wl,--print-memory-usage"],
)
cc_args(
name = "optimizations",
actions = [
"@rules_cc//cc/toolchains/actions:assembly_actions",
"@rules_cc//cc/toolchains/actions:c_compile_actions",
"@rules_cc//cc/toolchains/actions:cpp_compile_actions",
],
args = ["-O"],
)
cc_args(
name = "common_defines",
actions = [
"@rules_cc//cc/toolchains/actions:assembly_actions",
"@rules_cc//cc/toolchains/actions:c_compile_actions",
"@rules_cc//cc/toolchains/actions:cpp_compile_actions",
],
args = [
"-D_LINUX_ERRNO_EXTENSIONS__",
"-D_POSIX_THREAD_SAFE_FUNCTIONS=200809L",
],
)
cc_args(
name = "common",
actions = [
"@rules_cc//cc/toolchains/actions:assembly_actions",
"@rules_cc//cc/toolchains/actions:c_compile_actions",
"@rules_cc//cc/toolchains/actions:cpp_compile_actions",
],
args = [
# We do not use -fno-threadsafe-statics for C++ but instead rely on
# Zephyr's built-in support for C++ thread-safe statics.
"-mlongcalls",
],
)
cc_args(
name = "c99",
actions = [
"@rules_cc//cc/toolchains/actions:assembly_actions",
"@rules_cc//cc/toolchains/actions:c_compile_actions",
],
args = ["-std=c99"],
)
cc_toolchain(
name = "xtensa_gcc_dc233c",
args = [
"//toolchain/args:oz",
"//toolchain/args:debugging",
"//toolchain/args:reduced_size",
"//toolchain/args:no_canonical_prefixes",
"//toolchain/args:common_warnings",
"//toolchain/args:color_diagnostics",
":optimizations",
":data_and_function_sections",
":symbol_garbage_collection",
":print_memory_usage",
":common_defines",
":common",
":c99",
":add_stddef",
],
enabled_features = [
"@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features",
"//toolchain/capability:compiler_is_gcc",
"//toolchain/capability:linker_is_gcc",
],
supports_param_files = 0,
tags = ["manual"],
tool_map = "@zephyr_sdk_xtensa_dc233c//:all_tools",
)
toolchain(
name = "xtensa_gcc_cc_dc233c",
target_compatible_with = [
"@zephyr//constraints:xtensa",
],
toolchain = ":xtensa_gcc_dc233c",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
filegroup(
name = "dc233c_core_files",
srcs = ["@zephyr_sdk_xtensa_dc233c//:xtensa_core_stdlib"],
)