From 6ea224f538ca7e40a43564d3d7089293478abaab Mon Sep 17 00:00:00 2001 From: Erwin Jansen Date: Sat, 25 Oct 2025 09:47:54 -0700 Subject: [PATCH 1/2] test(arm-linux): Add failing C atomics compilation test Verify compilation of a C file that uses C11 atomics, which currently fails due to the toolchain incorrectly including C++ headers when compiling a C file. This test documents the existing issue where C files pick up C++ include paths, resulting in build failures. It also adds the new target to the `arm_linux_test` build test exposing the issue. --- examples/bzlmod/BUILD | 5 ++++- examples/bzlmod/arm-linux/BUILD | 11 +++++++---- examples/bzlmod/arm-linux/atomics.c | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 examples/bzlmod/arm-linux/atomics.c diff --git a/examples/bzlmod/BUILD b/examples/bzlmod/BUILD index 9e1996d..08d13f7 100644 --- a/examples/bzlmod/BUILD +++ b/examples/bzlmod/BUILD @@ -6,7 +6,10 @@ load("@bazel_skylib//rules:build_test.bzl", "build_test") build_test( name = "arm_linux_test", - targets = ["//arm-linux:hex"], + targets = [ + "//arm-linux:hex", + "//arm-linux:atomics", + ], ) build_test( diff --git a/examples/bzlmod/arm-linux/BUILD b/examples/bzlmod/arm-linux/BUILD index 128131e..2e054ae 100644 --- a/examples/bzlmod/arm-linux/BUILD +++ b/examples/bzlmod/arm-linux/BUILD @@ -25,10 +25,13 @@ cc_library( "-mthumb", ], includes = ["includes"], - target_compatible_with = [ - "@platforms//cpu:arm", - "@platforms//os:linux", - ], + ) + +cc_library( + name = "atomics", + srcs = ["atomics.c"], + copts = ["-std=c11"], + visibility = ["//visibility:public"], ) cc_binary( diff --git a/examples/bzlmod/arm-linux/atomics.c b/examples/bzlmod/arm-linux/atomics.c new file mode 100644 index 0000000..30ff021 --- /dev/null +++ b/examples/bzlmod/arm-linux/atomics.c @@ -0,0 +1,21 @@ +#include + +// This should pick up the C-variant, not C++ one, +#include + +/** + * Minimal C11 stdatomic.h example without threads. + * + * This example is designed to test the compiler's support for the + * C11 _Atomic type specifier and the functions provided by . + */ +int main(void) { + atomic_int counter = ATOMIC_VAR_INIT(0); + atomic_fetch_add(&counter, 1); + int final_value = atomic_load(&counter); + + printf("Atomic counter initialized to 0, incremented once.\n"); + printf("Final value (read atomically): %d\n", final_value); + + return 0; +} \ No newline at end of file From a9cf01056ac94cbf509de1be36351a4ad3fead24 Mon Sep 17 00:00:00 2001 From: Erwin Jansen Date: Sat, 25 Oct 2025 11:28:48 -0700 Subject: [PATCH 2/2] fix(toolchain): Remove explicit gcc_tool from toolchain definition Remove the hardcoded `gcc_tool = "g++"` argument from the `arm_none_eabi_toolchain` definition. This explicit setting was incorrectly forcing the C compiler to use the C++ frontend (g++) for C files, which led to compilation failures when attempting to use C-specific features like C11 atomics. By removing this argument, Bazel is allowed to correctly infer the appropriate C compiler (`gcc`) for C sources and the C++ compiler (`g++`) for C++ sources, resolving the build issue documented in the previous test commit. Fixes: 83 --- examples/bzlmod/custom/toolchain/BUILD | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/bzlmod/custom/toolchain/BUILD b/examples/bzlmod/custom/toolchain/BUILD index ad3960c..882ca00 100644 --- a/examples/bzlmod/custom/toolchain/BUILD +++ b/examples/bzlmod/custom/toolchain/BUILD @@ -32,7 +32,6 @@ arm_none_eabi_toolchain( "-mfloat-abi=hard", "-mfpu=fpv4-sp-d16", ], - gcc_tool = "g++", linkopts = [ "-mcpu=cortex-m4", "-mthumb",