From 327a82d8a7ae8f13bc0dc4bf1b93caecf7a5d386 Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Tue, 2 Jul 2024 16:05:11 +0800 Subject: [PATCH] lib/libc: picolibc: select its source with Kconfig choice Implement the selection of the picolibc source in a Kconfig choice as they are mutually exclusive. The following table represents the possible choices, where 'X' means that `PICOLIBC_SUPPORTED=n` and is guarded in the parent level as `PICOLIBC=n`, so we do not need to care. Module Toolchain C++ | Choice 0 0 0 | X 0 0 1 | X 0 1 0 | Toolchain only 0 1 1 | Toolchain only 1 0 0 | Module only 1 0 1 | X 1 1 0 | Toolchain/Module 1 1 1 | Toolchain only The current implementation favors `PICOLIBC_USE_TOOLCHAIN` over `PICOLIBC_USE_MODULE` whenever possible, that preference is maintained in this implementation as well - the TOOLCHAIN source will be the default choice when the toolchain supports it or when the C++ is enabled. Otherwise, fallback to MODULE. Signed-off-by: Yong Cong Sin --- lib/libc/picolibc/Kconfig | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/libc/picolibc/Kconfig b/lib/libc/picolibc/Kconfig index 15d513d51475399..be30e6a8f3a606b 100644 --- a/lib/libc/picolibc/Kconfig +++ b/lib/libc/picolibc/Kconfig @@ -3,9 +3,13 @@ if PICOLIBC +choice PICOLIBC_SOURCE + prompt "Source of Picolibc" + default PICOLIBC_USE_TOOLCHAIN if REQUIRES_FULL_LIBCPP || "$(TOOLCHAIN_HAS_PICOLIBC)" = "y" + default PICOLIBC_USE_MODULE + config PICOLIBC_USE_MODULE - bool "Picolibc as module" if "$(TOOLCHAIN_HAS_PICOLIBC)" = "y" - default y if "$(TOOLCHAIN_HAS_PICOLIBC)" != "y" + bool "Picolibc from module" depends on ZEPHYR_PICOLIBC_MODULE depends on !GLIBCXX_LIBCPP help @@ -15,9 +19,14 @@ config PICOLIBC_USE_MODULE # force TLS when using toolchain with TLS support config PICOLIBC_USE_TOOLCHAIN - bool - default y if !PICOLIBC_USE_MODULE + bool "Picolibc from toolchain" + depends on "$(TOOLCHAIN_HAS_PICOLIBC)" = "y" select THREAD_LOCAL_STORAGE if ARCH_HAS_THREAD_LOCAL_STORAGE && TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE + help + Use picolibc included with the toolchain. + This is required when using a full C++ standard library (`REQUIRES_FULL_LIBCPP=y`). + +endchoice # PICOLIBC_SOURCE choice PICOLIBC_IO_LEVEL prompt "Picolibc printf/scanf level"