Skip to content

Commit 3fc3901

Browse files
committed
Adaptions for clang
1 parent c101f17 commit 3fc3901

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

.github/workflows/trice_lib_reusable.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ jobs:
128128
# and matches the typical embedded toolchain expectation.
129129
export OBJCOPY=arm-none-eabi-objcopy
130130
131+
# Tell clang where the ARM GCC toolchain is located (CI only).
132+
# On ubuntu-latest with gcc-arm-none-eabi from apt, this is /usr.
133+
export CLANG_GCC_TOOLCHAIN=/usr
134+
131135
# 1) GCC all-target builds (TRICE ON/OFF)
132136
if [ "${{ inputs.toolchain_gcc_trice_on }}" = "true" ]; then
133137
./ci_build.sh \

build_environment.sh

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,43 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
142142
export C_INCLUDE_PATH="${arm_inc_dir}"
143143
fi
144144
else
145-
log_warn "Could not auto-detect ARM include directory on Linux (sysroot may be empty for this toolchain). You may need to set C_INCLUDE_PATH manually."
145+
# log_warn "Could not auto-detect ARM include directory on Linux (sysroot may be empty for this toolchain). You may need to set C_INCLUDE_PATH manually."
146+
# now:
147+
148+
# ---------------------------------------------------------------------------
149+
# Clang cross builds need a C library include directory (e.g. Newlib) to find
150+
# headers like stdlib.h. GCC usually finds these internally, but clang does not
151+
# unless we provide a sysroot/toolchain or additional include paths.
152+
#
153+
# On Ubuntu (apt: gcc-arm-none-eabi), Newlib headers are typically here:
154+
# /usr/arm-none-eabi/include
155+
#
156+
# Additionally, GCC has an internal include directory that is useful for both
157+
# gcc and clang setups:
158+
# arm-none-eabi-gcc -print-file-name=include
159+
# ---------------------------------------------------------------------------
160+
newlib_inc="/usr/arm-none-eabi/include"
161+
gcc_inc="$(arm-none-eabi-gcc -print-file-name=include 2>/dev/null || true)"
162+
163+
if [ -d "$newlib_inc" ]; then
164+
if [ -n "${C_INCLUDE_PATH:-}" ]; then
165+
export C_INCLUDE_PATH="${newlib_inc}:${C_INCLUDE_PATH}"
166+
else
167+
export C_INCLUDE_PATH="${newlib_inc}"
168+
fi
169+
else
170+
log_warn "Expected Newlib include directory not found: ${newlib_inc} (clang cross may fail to find stdlib.h)."
171+
fi
172+
173+
if [ -n "$gcc_inc" ] && [ "$gcc_inc" != "include" ] && [ -d "$gcc_inc" ]; then
174+
if [ -n "${C_INCLUDE_PATH:-}" ]; then
175+
export C_INCLUDE_PATH="${gcc_inc}:${C_INCLUDE_PATH}"
176+
else
177+
export C_INCLUDE_PATH="${gcc_inc}"
178+
fi
179+
else
180+
log_warn "GCC internal include directory not found via: arm-none-eabi-gcc -print-file-name=include"
181+
fi
146182
fi
147183

148184
elif [[ "$OSTYPE" == "darwin"* ]]; then

examples/G0B1_inst/clang0.mak

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,12 @@ CLANG_BIN = $(CLANG_CP) -O binary -S
1515
CLANG_ONLY_FLAGS = #
1616
#CLANG_ONLY_FLAGS += -Weverything # # clang only: enable the warning but liberally disable warnings from it that are not useful.
1717
CLANG_ONLY_FLAGS += --target=arm-none-eabi #
18+
19+
# CLANG_ONLY_FLAGS += --gcc-toolchain=/usr
20+
# Optional: allow the environment/CI to provide the GCC toolchain root for clang.
21+
# Example for GitHub Actions Ubuntu: export CLANG_GCC_TOOLCHAIN=/usr
22+
ifneq ($(strip $(CLANG_GCC_TOOLCHAIN)),)
23+
CLANG_ONLY_FLAGS += --gcc-toolchain=$(CLANG_GCC_TOOLCHAIN)
24+
endif
1825
#CLANG_CC_FLAGS += -Wa,-a,-ad,-alms=$(CLANG_BUILD)/$(notdir $(<:.c=.lst))
1926
#CLANG_ONLY_FLAGS += -Wa,--noexecstack

0 commit comments

Comments
 (0)