From 8122b9053cbb00abb68e49e9819222939b20b77b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 1 Nov 2024 12:06:38 -0700 Subject: [PATCH 1/2] lib/cpp: Add support for building libstdc++ as a module Provide a mechanism to build libstdc++ as a module, instead of requiring that it be included in the toolchain. Signed-off-by: Keith Packard --- MAINTAINERS.yml | 9 +++++++++ lib/cpp/Kconfig | 19 +++++++++++++++++++ lib/libc/Kconfig | 2 +- lib/libc/picolibc/Kconfig | 4 +--- modules/Kconfig | 1 + modules/Kconfig.libstdc++ | 5 +++++ west.yml | 7 +++++++ 7 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 modules/Kconfig.libstdc++ diff --git a/MAINTAINERS.yml b/MAINTAINERS.yml index c77180172d2d..6efd14cea0f7 100644 --- a/MAINTAINERS.yml +++ b/MAINTAINERS.yml @@ -5304,6 +5304,15 @@ West: labels: - "area: Audio" +"West project: libstdcxx": + status: maintained + maintainers: + - Keith Packard + files: + - modules/Kconfig.libstdc++ + labels: + - "area: C++" + "West project: littlefs": status: odd fixes files: diff --git a/lib/cpp/Kconfig b/lib/cpp/Kconfig index da309ee3fbcd..9ab89e668556 100644 --- a/lib/cpp/Kconfig +++ b/lib/cpp/Kconfig @@ -118,6 +118,25 @@ config GLIBCXX_LIBCPP Build with GNU C++ Standard Library (libstdc++) provided by the GNU Compiler Collection (GCC)-based toolchain. +choice GLIBCXX_LIBCPP_SOURCE + prompt "Source of libstdc++" + depends on GLIBCXX_LIBCPP + default GLIBCXX_LIBCPP_USE_TOOLCHAIN + +config GLIBCXX_LIBCPP_USE_MODULE + bool "libstdc++ from module" + depends on ZEPHYR_LIBSTDCXX_MODULE + help + Use libstdc++ module instead of libstdc++ included with toolchain. + +config GLIBCXX_LIBCPP_USE_TOOLCHAIN + bool "libstdc++ from toolchain" + depends on NEWLIB_LIBC || PICOLIBC_USE_TOOLCHAIN + help + Use libstdc++ included with toolchain. + +endchoice + config LIBCXX_LIBCPP bool "LLVM C++ Standard Library" depends on !NATIVE_APPLICATION diff --git a/lib/libc/Kconfig b/lib/libc/Kconfig index 5d981e4719b0..88f45a9a1780 100644 --- a/lib/libc/Kconfig +++ b/lib/libc/Kconfig @@ -45,7 +45,7 @@ config NEWLIB_LIBC_SUPPORTED config PICOLIBC_SUPPORTED bool depends on !NATIVE_APPLICATION - depends on ("$(TOOLCHAIN_HAS_PICOLIBC)" = "y") || (ZEPHYR_PICOLIBC_MODULE && !REQUIRES_FULL_LIBCPP) + depends on ("$(TOOLCHAIN_HAS_PICOLIBC)" = "y") || ZEPHYR_PICOLIBC_MODULE default y select FULL_LIBC_SUPPORTED help diff --git a/lib/libc/picolibc/Kconfig b/lib/libc/picolibc/Kconfig index be30e6a8f3a6..f48a69f8aa56 100644 --- a/lib/libc/picolibc/Kconfig +++ b/lib/libc/picolibc/Kconfig @@ -5,13 +5,12 @@ if PICOLIBC choice PICOLIBC_SOURCE prompt "Source of Picolibc" - default PICOLIBC_USE_TOOLCHAIN if REQUIRES_FULL_LIBCPP || "$(TOOLCHAIN_HAS_PICOLIBC)" = "y" + default PICOLIBC_USE_TOOLCHAIN if "$(TOOLCHAIN_HAS_PICOLIBC)" = "y" default PICOLIBC_USE_MODULE config PICOLIBC_USE_MODULE bool "Picolibc from module" depends on ZEPHYR_PICOLIBC_MODULE - depends on !GLIBCXX_LIBCPP help Use picolibc module instead of picolibc included with toolchain. This is enabled by default for toolchains other than the Zephyr @@ -24,7 +23,6 @@ config PICOLIBC_USE_TOOLCHAIN 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 diff --git a/modules/Kconfig b/modules/Kconfig index 7d32d1ff818e..e2b7f1da7051 100644 --- a/modules/Kconfig +++ b/modules/Kconfig @@ -49,6 +49,7 @@ source "modules/zcbor/Kconfig" source "modules/Kconfig.mcuboot" source "modules/Kconfig.intel" source "modules/hostap/Kconfig" +source "modules/Kconfig.libstdc++" comment "Unavailable modules, please install those via the project manifest." diff --git a/modules/Kconfig.libstdc++ b/modules/Kconfig.libstdc++ new file mode 100644 index 000000000000..581b1691c754 --- /dev/null +++ b/modules/Kconfig.libstdc++ @@ -0,0 +1,5 @@ +# Copyright 2024 Google LLC +# SPDX-License-Identifier: Apache-2.0 + +config ZEPHYR_LIBSTDCXX_MODULE + bool diff --git a/west.yml b/west.yml index 1489b3a57f6d..f7ae609beb45 100644 --- a/west.yml +++ b/west.yml @@ -23,6 +23,8 @@ manifest: url-base: https://github.com/zephyrproject-rtos - name: babblesim url-base: https://github.com/BabbleSim + - name: keithp + url-base: https://github.com/keith-packard group-filter: [-babblesim, -optional] @@ -293,6 +295,11 @@ manifest: path: modules/hal/libmetal groups: - hal + - name: libstdcxx + remote: keithp + repo-path: libstdcxx-module + revision: 9ac70a1eec3bec2bc158eb4b384cdc97631cdd77 + path: modules/lib/libstdcxx - name: littlefs path: modules/fs/littlefs groups: From 4675791386c04f5a68707d5c478ddb50c7ac4ff0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 1 Nov 2024 14:13:00 -0700 Subject: [PATCH 2/2] tests/cpp: Test the modular build of libstdc++ Add a test case verifying that libstdc++ can be used with picolibc with newlib. Signed-off-by: Keith Packard --- tests/lib/cpp/libcxx/testcase.yaml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/lib/cpp/libcxx/testcase.yaml b/tests/lib/cpp/libcxx/testcase.yaml index 566a0d689d3c..c4a33a724bbf 100644 --- a/tests/lib/cpp/libcxx/testcase.yaml +++ b/tests/lib/cpp/libcxx/testcase.yaml @@ -11,6 +11,19 @@ tests: - CONFIG_CPP_EXCEPTIONS=y integration_platforms: - mps2/an385 + cpp.libcxx.glibcxx.newlib.module: + filter: TOOLCHAIN_HAS_NEWLIB == 1 + toolchain_exclude: xcc + min_flash: 54 + min_ram: 24 + tags: cpp + extra_configs: + - CONFIG_NEWLIB_LIBC=y + - CONFIG_GLIBCXX_LIBCPP=y + - CONFIG_GLIBCXX_LIBCPP_USE_MODULE=y + - CONFIG_CPP_EXCEPTIONS=y + integration_platforms: + - mps2/an385 cpp.libcxx.glibcxx.newlib_nano: filter: TOOLCHAIN_HAS_NEWLIB == 1 and CONFIG_HAS_NEWLIB_LIBC_NANO toolchain_exclude: xcc @@ -34,6 +47,18 @@ tests: - CONFIG_CPP_EXCEPTIONS=y integration_platforms: - mps2/an385 + cpp.libcxx.glibcxx.picolibc.module: + toolchain_exclude: xcc + platform_exclude: native_sim + tags: cpp + timeout: 60 + extra_configs: + - CONFIG_PICOLIBC=y + - CONFIG_GLIBCXX_LIBCPP=y + - CONFIG_GLIBCXX_LIBCPP_USE_MODULE=y + - CONFIG_CPP_EXCEPTIONS=n + integration_platforms: + - mps2/an385 cpp.libcxx.arcmwdtlib: toolchain_allow: arcmwdt min_flash: 54