Skip to content

Commit 6d52c92

Browse files
nashifkeith-packard
authored andcommitted
toolchains: combine host variants
Combine toolchains provided by the host into one variant. This includes both gcc and llvm installationt typically coming from the distribution (on Linux). Both gcc and llvm are now part of the 'host' variant, the default is the gnu compiler, so setting ZEPHYR_TOOLCHAIN_VARIANT=host Will select the gnu compiler. To select llvm or any other compuler provided in this variant, use the follwoing format: ZEPHYR_TOOLCHAIN_VARIANT=<variant>/<compiler> The following will select llvm: ZEPHYR_TOOLCHAIN_VARIANT=host/llvm Although gnu is the default, it can also be selected using the above syntax: ZEPHYR_TOOLCHAIN_VARIANT=host/gcc This commit removes the llvm variant for now, it should be deperecated in another commit to follow. Signed-off-by: Anas Nashif <anas.nashif@intel.com>
1 parent 418e1d7 commit 6d52c92

File tree

17 files changed

+62
-24
lines changed

17 files changed

+62
-24
lines changed

Kconfig.zephyr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ choice COMPILER_OPTIMIZATIONS
491491
prompt "Optimization level"
492492
default NO_OPTIMIZATIONS if COVERAGE
493493
default DEBUG_OPTIMIZATIONS if DEBUG
494-
default SIZE_OPTIMIZATIONS_AGGRESSIVE if "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "llvm"
494+
default SIZE_OPTIMIZATIONS_AGGRESSIVE if "$(TOOLCHAIN_VARIANT_COMPILER)" = "llvm"
495495
default SIZE_OPTIMIZATIONS
496496
help
497497
Note that these flags shall only control the compiler

cmake/modules/FindHostTools.cmake

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ endif()
7373
# Default to the host system's toolchain if we are targeting a host based target
7474
if((${BOARD_DIR} MATCHES "boards\/native") OR ("${ARCH}" STREQUAL "posix")
7575
OR ("${BOARD}" STREQUAL "unit_testing"))
76-
if(NOT "${ZEPHYR_TOOLCHAIN_VARIANT}" STREQUAL "llvm")
76+
if(NOT "${ZEPHYR_TOOLCHAIN_VARIANT}" STREQUAL "host/llvm")
7777
set(ZEPHYR_TOOLCHAIN_VARIANT "host")
7878
endif()
7979
endif()
@@ -102,6 +102,16 @@ endif()
102102
set(TOOLCHAIN_ROOT ${TOOLCHAIN_ROOT} CACHE STRING "Zephyr toolchain root" FORCE)
103103
assert(TOOLCHAIN_ROOT "Zephyr toolchain root path invalid: please set the TOOLCHAIN_ROOT-variable")
104104

105+
106+
# Check if ZEPHYR_TOOLCHAIN_VARIANT follows "<variant_name>/<compiler>" pattern
107+
if("${ZEPHYR_TOOLCHAIN_VARIANT}" MATCHES "^([^/]+)/([^/]+)$")
108+
set(_variant "${CMAKE_MATCH_1}")
109+
set(_compiler "${CMAKE_MATCH_2}")
110+
set(ZEPHYR_TOOLCHAIN_VARIANT "${_variant}")
111+
set(TOOLCHAIN_VARIANT_COMPILER "${_compiler}")
112+
set(TOOLCHAIN_VARIANT_COMPILER ${_compiler} CACHE STRING "compiler used by the toolchain variant" FORCE)
113+
endif()
114+
105115
# Set cached ZEPHYR_TOOLCHAIN_VARIANT.
106116
set(ZEPHYR_TOOLCHAIN_VARIANT ${ZEPHYR_TOOLCHAIN_VARIANT} CACHE STRING "Zephyr toolchain variant")
107117

cmake/modules/kconfig.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ set(COMMON_KCONFIG_ENV_SETTINGS
168168
KCONFIG_BINARY_DIR=${KCONFIG_BINARY_DIR}
169169
APPLICATION_SOURCE_DIR=${APPLICATION_SOURCE_DIR}
170170
ZEPHYR_TOOLCHAIN_VARIANT=${ZEPHYR_TOOLCHAIN_VARIANT}
171+
TOOLCHAIN_VARIANT_COMPILER=${TOOLCHAIN_VARIANT_COMPILER}
171172
TOOLCHAIN_KCONFIG_DIR=${TOOLCHAIN_KCONFIG_DIR}
172173
TOOLCHAIN_HAS_NEWLIB=${_local_TOOLCHAIN_HAS_NEWLIB}
173174
TOOLCHAIN_HAS_PICOLIBC=${_local_TOOLCHAIN_HAS_PICOLIBC}

cmake/toolchain/host/generic.cmake

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
set(COMPILER host-gcc)
4-
set(LINKER ld)
5-
set(BINTOOLS host-gnu)
3+
if(TOOLCHAIN_VARIANT_COMPILER STREQUAL "gnu" OR
4+
NOT DEFINED TOOLCHAIN_VARIANT_COMPILER)
65

7-
set(TOOLCHAIN_HAS_NEWLIB OFF CACHE BOOL "True if toolchain supports newlib")
8-
set(TOOLCHAIN_HAS_GLIBCXX ON CACHE BOOL "True if toolchain supports libstdc++")
6+
if (NOT DEFINED TOOLCHAIN_VARIANT_COMPILER)
7+
set(TOOLCHAIN_VARIANT_COMPILER "gnu" CACHE STRING "compiler used by the toolchain variant" FORCE)
8+
endif()
99

10-
message(STATUS "Found toolchain: host (gcc/ld)")
10+
include(${ZEPHYR_BASE}/cmake/toolchain/host/gnu/generic.cmake)
11+
12+
set(TOOLCHAIN_KCONFIG_DIR ${ZEPHYR_BASE}/cmake/toolchain/host/gnu)
13+
set(TOOLCHAIN_HAS_NEWLIB OFF CACHE BOOL "True if toolchain supports newlib")
14+
set(TOOLCHAIN_HAS_GLIBCXX ON CACHE BOOL "True if toolchain supports libstdc++")
15+
elseif(TOOLCHAIN_VARIANT_COMPILER STREQUAL "llvm")
16+
17+
include(${ZEPHYR_BASE}/cmake/toolchain/host/llvm/generic.cmake)
18+
set(TOOLCHAIN_KCONFIG_DIR ${ZEPHYR_BASE}/cmake/toolchain/host/llvm)
19+
endif()

cmake/toolchain/host/Kconfig renamed to cmake/toolchain/host/gnu/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2024 Basalte bv
1+
# Copyright The Zephyr Project Contributors
22
# SPDX-License-Identifier: Apache-2.0
33

44
config TOOLCHAIN_HOST_SUPPORTS_GNU_EXTENSIONS
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
set(TOOLCHAIN_VARIANT_COMPILER gcc CACHE STRING "Variant compiler being used")
3+
set(COMPILER host-gcc)
4+
set(LINKER ld)
5+
set(BINTOOLS host-gnu)
6+
7+
set(TOOLCHAIN_HAS_NEWLIB OFF CACHE BOOL "True if toolchain supports newlib")
8+
9+
message(STATUS "Found toolchain: host (gcc/ld)")

cmake/toolchain/host/gnu/target.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# SPDX-License-Identifier: Apache-2.0

cmake/toolchain/llvm/Kconfig renamed to cmake/toolchain/host/llvm/Kconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Copyright (c) 2023 Intel Corporation
1+
# Copyright The Zephyr Project Contributors
2+
# Copyright (c) 2024 Basalte bv
23
# SPDX-License-Identifier: Apache-2.0
3-
4+
#
45
choice LLVM_LINKER
56
prompt "LLVM Linker"
6-
depends on "${ZEPHYR_TOOLCHAIN_VARIANT}" = "llvm"
77
default LLVM_USE_LD
88

99
config LLVM_USE_LD

0 commit comments

Comments
 (0)