Skip to content

Commit 9e888ab

Browse files
committed
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 <[email protected]>
1 parent 7e232b0 commit 9e888ab

File tree

7 files changed

+43
-5
lines changed

7 files changed

+43
-5
lines changed

MAINTAINERS.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4933,6 +4933,15 @@ West:
49334933
labels:
49344934
- "area: Audio"
49354935

4936+
"West project: libstdcxx":
4937+
status: maintained
4938+
maintainers:
4939+
- Keith Packard
4940+
files:
4941+
- modules/Kconfig.libstdc++
4942+
labels:
4943+
- "area: C++"
4944+
49364945
"West project: littlefs":
49374946
status: odd fixes
49384947
files:

lib/cpp/Kconfig

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,29 @@ config MINIMAL_LIBCPP
9191
config GLIBCXX_LIBCPP
9292
bool "GNU C++ Standard Library"
9393
depends on !NATIVE_APPLICATION
94-
depends on NEWLIB_LIBC || PICOLIBC
9594
select FULL_LIBCPP_SUPPORTED
9695
help
9796
Build with GNU C++ Standard Library (libstdc++) provided by the GNU
9897
Compiler Collection (GCC)-based toolchain.
9998

99+
choice GLIBCXX_LIBCPP_SOURCE
100+
prompt "Source of libstdc++"
101+
default GLIBCXX_LIBCPP_USE_TOOLCHAIN
102+
103+
config GLIBCXX_LIBCPP_USE_MODULE
104+
bool "libstdc++ from module"
105+
depends on ZEPHYR_LIBSTDCXX_MODULE
106+
help
107+
Use libstdc++ module instead of libstdc++ included with toolchain.
108+
109+
config GLIBCXX_LIBCPP_USE_TOOLCHAIN
110+
bool "libstdc++ from toolchain"
111+
depends on NEWLIB_LIBC || PICOLIBC_USE_TOOLCHAIN
112+
help
113+
Use libstdc++ module instead of libstdc++ included with toolchain.
114+
115+
endchoice
116+
100117
config LIBCXX_LIBCPP
101118
bool "LLVM C++ Standard Library"
102119
depends on !NATIVE_APPLICATION

lib/libc/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ config NEWLIB_LIBC_SUPPORTED
4545
config PICOLIBC_SUPPORTED
4646
bool
4747
depends on !NATIVE_APPLICATION
48-
depends on ("$(TOOLCHAIN_HAS_PICOLIBC)" = "y") || (ZEPHYR_PICOLIBC_MODULE && !REQUIRES_FULL_LIBCPP)
48+
depends on ("$(TOOLCHAIN_HAS_PICOLIBC)" = "y") || ZEPHYR_PICOLIBC_MODULE
4949
default y
5050
select FULL_LIBC_SUPPORTED
5151
help
@@ -87,6 +87,7 @@ config PICOLIBC
8787
select NEED_LIBC_MEM_PARTITION
8888
select TC_PROVIDES_POSIX_C_LANG_SUPPORT_R
8989
imply COMMON_LIBC_MALLOC
90+
select COMMON_LIBC_MALLOC if REQUIRES_FULL_LIBCPP
9091
depends on PICOLIBC_SUPPORTED
9192
help
9293
Build with picolibc library. The picolibc library is built as

lib/libc/picolibc/Kconfig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ if PICOLIBC
55

66
choice PICOLIBC_SOURCE
77
prompt "Source of Picolibc"
8-
default PICOLIBC_USE_TOOLCHAIN if REQUIRES_FULL_LIBCPP || "$(TOOLCHAIN_HAS_PICOLIBC)" = "y"
8+
default PICOLIBC_USE_TOOLCHAIN if "$(TOOLCHAIN_HAS_PICOLIBC)" = "y"
99
default PICOLIBC_USE_MODULE
1010

1111
config PICOLIBC_USE_MODULE
1212
bool "Picolibc from module"
1313
depends on ZEPHYR_PICOLIBC_MODULE
14-
depends on !GLIBCXX_LIBCPP
1514
help
1615
Use picolibc module instead of picolibc included with toolchain.
1716
This is enabled by default for toolchains other than the Zephyr
@@ -24,7 +23,6 @@ config PICOLIBC_USE_TOOLCHAIN
2423
select THREAD_LOCAL_STORAGE if ARCH_HAS_THREAD_LOCAL_STORAGE && TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE
2524
help
2625
Use picolibc included with the toolchain.
27-
This is required when using a full C++ standard library (`REQUIRES_FULL_LIBCPP=y`).
2826

2927
endchoice # PICOLIBC_SOURCE
3028

modules/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ source "modules/zcbor/Kconfig"
4444
source "modules/Kconfig.mcuboot"
4545
source "modules/Kconfig.intel"
4646
source "modules/hostap/Kconfig"
47+
source "modules/Kconfig.libstdc++"
4748

4849
comment "Unavailable modules, please install those via the project manifest."
4950

modules/Kconfig.libstdc++

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright 2024 Google LLC
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config ZEPHYR_LIBSTDCXX_MODULE
5+
bool

west.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ manifest:
2323
url-base: https://github.com/zephyrproject-rtos
2424
- name: babblesim
2525
url-base: https://github.com/BabbleSim
26+
- name: keithp
27+
url-base: https://github.com/keith-packard
2628

2729
group-filter: [-babblesim, -optional]
2830

@@ -268,6 +270,11 @@ manifest:
268270
- name: liblc3
269271
revision: 1a5938ebaca4f13fe79ce074f5dee079783aa29f
270272
path: modules/lib/liblc3
273+
- name: libstdcxx
274+
remote: keithp
275+
repo-path: libstdcxx-module
276+
revision: 8b94ca21ebc054259d8229c47e96b40e44a42baa
277+
path: modules/lib/libstdcxx
271278
- name: littlefs
272279
path: modules/fs/littlefs
273280
groups:

0 commit comments

Comments
 (0)