Skip to content

Commit

Permalink
cmake: Add LLVM toolchain support
Browse files Browse the repository at this point in the history
This commit adds the support file for the `zephyr-llvm` toolchain
variant.

Signed-off-by: Stephanos Ioannidis <[email protected]>
  • Loading branch information
stephanosio committed Oct 25, 2024
1 parent dd9a89b commit 1358e13
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cmake/zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ config TOOLCHAIN_ZEPHYR_0_17
def_bool y
# FIXME: Newlib-nano is disabled for Xtensa targets due to the memset
# bug causing crashes (see the GitHub issue #660).
select HAS_NEWLIB_LIBC_NANO if !XTENSA
select HAS_NEWLIB_LIBC_NANO if !XTENSA \
&& "$(ZEPHYR_TOOLCHAIN_VARIANT)" != "zephyr-llvm"

config TOOLCHAIN_ZEPHYR_SUPPORTS_THREAD_LOCAL_STORAGE
def_bool y
Expand All @@ -16,6 +17,7 @@ config TOOLCHAIN_ZEPHYR_SUPPORTS_GNU_EXTENSIONS

config PICOLIBC_SUPPORTED
def_bool y
depends on "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "zephyr-gnu"
depends on "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "zephyr-gnu" \
|| "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "zephyr-llvm"
help
Zephyr SDK >=0.16 always supports Picolibc for C and C++ development.
4 changes: 4 additions & 0 deletions cmake/zephyr/llvm/clang_compiler_rt.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) 2023 The ChromiumOS Authors
# SPDX-License-Identifier: Apache-2.0

--rtlib=compiler-rt
11 changes: 11 additions & 0 deletions cmake/zephyr/llvm/generic.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# SPDX-License-Identifier: Apache-2.0

set(LLVM_TOOLCHAIN_PATH ${ZEPHYR_SDK_INSTALL_DIR}/llvm)

set(TOOLCHAIN_HOME ${ZEPHYR_SDK_INSTALL_DIR}/llvm/bin)

set(COMPILER clang)
set(LINKER lld)
set(BINTOOLS llvm)

set(TOOLCHAIN_HAS_PICOLIBC ON CACHE BOOL "True if toolchain supports picolibc")
38 changes: 38 additions & 0 deletions cmake/zephyr/llvm/target.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# SPDX-License-Identifier: Apache-2.0

if("${ARCH}" STREQUAL "arm")
if(DEFINED CONFIG_ARMV8_M_MAINLINE)
# ARMv8-M mainline is ARMv7-M with additional features from ARMv8-M.
set(triple armv8m.main-none-eabi)
elseif(DEFINED CONFIG_ARMV8_M_BASELINE)
# ARMv8-M baseline is ARMv6-M with additional features from ARMv8-M.
set(triple armv8m.base-none-eabi)
elseif(DEFINED CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
# ARMV7_M_ARMV8_M_MAINLINE means that ARMv7-M or backward compatible ARMv8-M
# processor is used.
set(triple armv7m-none-eabi)
elseif(DEFINED CONFIG_ARMV6_M_ARMV8_M_BASELINE)
# ARMV6_M_ARMV8_M_BASELINE means that ARMv6-M or ARMv8-M supporting the
# Baseline implementation processor is used.
set(triple armv6m-none-eabi)
else()
# Default ARM target supported by all processors.
set(triple arm-none-eabi)
endif()
elseif("${ARCH}" STREQUAL "arm64")
set(triple aarch64-none-elf)
# TODO: Add RISC-V target support.
endif()

if(DEFINED triple)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_ASM_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER_TARGET ${triple})

unset(triple)
endif()

list(APPEND TOOLCHAIN_C_FLAGS --config
${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/llvm/clang_compiler_rt.cfg)
list(APPEND TOOLCHAIN_LD_FLAGS --config
${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/llvm/clang_compiler_rt.cfg)

0 comments on commit 1358e13

Please sign in to comment.