diff --git a/CMakeLists.txt b/CMakeLists.txt index 0788c10a5ebf3..be99801239562 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -695,7 +695,7 @@ add_custom_command( # Make sure Picolibc is built before the rest of the system; there's no explicit # reference to any of the files as they're all picked up by various compiler # settings -if(CONFIG_PICOLIBC_USE_MODULE) +if(CONFIG_PICOLIBC AND CONFIG_PICOLIBC_MODULE) set(picolibc_dependency PicolibcBuild) endif() diff --git a/cmake/compiler/gcc/compiler_flags.cmake b/cmake/compiler/gcc/compiler_flags.cmake index 2dbb1e3e08eae..f59f7c65b5435 100644 --- a/cmake/compiler/gcc/compiler_flags.cmake +++ b/cmake/compiler/gcc/compiler_flags.cmake @@ -104,6 +104,7 @@ set_compiler_property(PROPERTY warning_error_coding_guideline set_compiler_property(PROPERTY cstd -std=) if (NOT CONFIG_NEWLIB_LIBC AND + NOT (CONFIG_PICOLIBC AND NOT CONFIG_PICOLIBC_MODULE) AND NOT COMPILER STREQUAL "xcc" AND NOT CONFIG_HAS_ESPRESSIF_HAL AND NOT CONFIG_NATIVE_APPLICATION) diff --git a/cmake/toolchain/zephyr/generic.cmake b/cmake/toolchain/zephyr/generic.cmake index f59d18c56fcd9..8f3f8252c80f9 100644 --- a/cmake/toolchain/zephyr/generic.cmake +++ b/cmake/toolchain/zephyr/generic.cmake @@ -4,4 +4,8 @@ include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/generic.cmake) set(TOOLCHAIN_KCONFIG_DIR ${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr) +if(SDK_VERSION VERSION_GREATER_EQUAL 0.16) + set(TOOLCHAIN_HAS_PICOLIBC ON CACHE BOOL "True if toolchain supports picolibc") +endif() + message(STATUS "Found toolchain: zephyr ${SDK_VERSION} (${ZEPHYR_SDK_INSTALL_DIR})") diff --git a/lib/libc/Kconfig b/lib/libc/Kconfig index 697a6ee99439d..6a53a65eb2ce5 100644 --- a/lib/libc/Kconfig +++ b/lib/libc/Kconfig @@ -19,6 +19,8 @@ config PICOLIBC_SUPPORTED bool depends on ARC || ARM || ARM64 || MIPS || RISCV depends on "$(ZEPHYR_TOOLCHAIN_VARIANT)" != "arcmwdt" + # Picolibc with C++ support in Zephyr SDK is handled by Zephyr SDK's own Kconfig. + depends on !(CPLUSPLUS && "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "zephyr") default y help Selected when the target has support for picolibc. @@ -42,6 +44,7 @@ config PICOLIBC select THREAD_LOCAL_STORAGE if ARCH_HAS_THREAD_LOCAL_STORAGE && TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE select LIBC_ERRNO if THREAD_LOCAL_STORAGE depends on !NATIVE_APPLICATION + depends on PICOLIBC_SUPPORTED help Build with picolibc library. The picolibc library is built as a module if PICOLIBC_MODULE is set, otherwise picolibc is diff --git a/lib/libc/picolibc/CMakeLists.txt b/lib/libc/picolibc/CMakeLists.txt index bfbe4bca8c332..02a487a68fdb5 100644 --- a/lib/libc/picolibc/CMakeLists.txt +++ b/lib/libc/picolibc/CMakeLists.txt @@ -7,7 +7,7 @@ zephyr_library_sources(libc-hooks.c) # used by the network stack zephyr_compile_definitions(__LINUX_ERRNO_EXTENSIONS__) -if(NOT CONFIG_PICOLIBC_USE_MODULE) +if(CONFIG_PICOLIBC AND NOT CONFIG_PICOLIBC_MODULE) # Use picolibc provided with the toolchain diff --git a/lib/libc/picolibc/Kconfig b/lib/libc/picolibc/Kconfig index 492a02a87f03c..94cfec08e4b34 100644 --- a/lib/libc/picolibc/Kconfig +++ b/lib/libc/picolibc/Kconfig @@ -4,9 +4,10 @@ if PICOLIBC config PICOLIBC_USE_MODULE - bool "Use picolibc module" + bool "Picolibc as module" default y - select PICOLIBC_MODULE + depends on ZEPHYR_PICOLIBC_MODULE + depends on !CPLUSPLUS help Use picolibc module instead of picolibc included with toolchain @@ -148,6 +149,6 @@ config PICOLIBC_GLOBAL_ERRNO which can be used to avoid TLS variable usage by the library if necessary. -endif # PICOLIBC_USE_MODULE +endif # PICOLIBC_MODULE endif # PICOLIBC diff --git a/samples/subsys/cpp/cpp_synchronization/sample.yaml b/samples/subsys/cpp/cpp_synchronization/sample.yaml index e3e9669a1ad09..621224a7b5589 100644 --- a/samples/subsys/cpp/cpp_synchronization/sample.yaml +++ b/samples/subsys/cpp/cpp_synchronization/sample.yaml @@ -13,3 +13,18 @@ tests: - "Create semaphore (.*)" - "main: Hello World!" - "coop_thread_entry: Hello World!" + sample.cpp.synchronization.picolibc: + filter: (TOOLCHAIN_HAS_PICOLIBC == 1) and CONFIG_PICOLIBC_SUPPORTED + extra_configs: + - CONFIG_PICOLIBC=y + tags: cpp + toolchain_exclude: issm xcc + integration_platforms: + - qemu_x86 + harness: console + harness_config: + type: multi_line + regex: + - "Create semaphore (.*)" + - "main: Hello World!" + - "coop_thread_entry: Hello World!" diff --git a/tests/subsys/cpp/cxx/testcase.yaml b/tests/subsys/cpp/cxx/testcase.yaml index 378bdaef530f0..079152b8940d6 100644 --- a/tests/subsys/cpp/cxx/testcase.yaml +++ b/tests/subsys/cpp/cxx/testcase.yaml @@ -22,6 +22,6 @@ tests: - CONFIG_NEWLIB_LIBC_NANO=y cpp.main.picolibc: tags: picolibc - filter: CONFIG_PICOLIBC_SUPPORTED + filter: (TOOLCHAIN_HAS_PICOLIBC == 1) and CONFIG_PICOLIBC_SUPPORTED extra_configs: - CONFIG_PICOLIBC=y diff --git a/tests/subsys/cpp/libcxx/testcase.yaml b/tests/subsys/cpp/libcxx/testcase.yaml index 3a8f23b18da45..98f9007c9a673 100644 --- a/tests/subsys/cpp/libcxx/testcase.yaml +++ b/tests/subsys/cpp/libcxx/testcase.yaml @@ -21,6 +21,15 @@ tests: - CONFIG_NEWLIB_LIBC_NANO=y integration_platforms: - mps2_an385 + cpp.libcxx.picolibc: + filter: (TOOLCHAIN_HAS_PICOLIBC == 1) and CONFIG_PICOLIBC_SUPPORTED + toolchain_exclude: xcc + tags: cpp + timeout: 60 + extra_configs: + - CONFIG_PICOLIBC=y + integration_platforms: + - mps2_an385 cpp.libcxx.arcmwdtlib: toolchain_allow: arcmwdt min_flash: 54