Skip to content

Commit

Permalink
lib/libc: picolibc: select its source with Kconfig choice
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ycsin committed Jul 5, 2024
1 parent 2191a08 commit 327a82d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/libc/picolibc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down

0 comments on commit 327a82d

Please sign in to comment.