Skip to content

Commit 9130004

Browse files
committed
posix: separate option groups into c library ext and system interfaces
Separate the POSIX implementation into two categories: - Extensions to ISO C - System Interfaces The first category include standalone functions that generally do not require OS support or depend on any other features within the POSIX specification. The Option Groups that comprise this category include - POSIX_C_LIB_EXT: e.g. strnlen(), fnmatch() - POSIX_C_LANG_SUPPORT_R: e.g. gmtime_r(), strtok_r() The second category includes the majority of other POSIX Option Groups that do require OS support. The latter group may also be categorized generally as being NATIVE_LIBC_INCOMPATIBLE, although that might eventually become more granular. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
1 parent e9741b5 commit 9130004

18 files changed

+68
-43
lines changed

lib/posix/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
add_subdirectory(options)
43
add_subdirectory_ifdef(CONFIG_EVENTFD eventfd)
4+
add_subdirectory_ifdef(CONFIG_POSIX_C_LANG_SUPPORT_R c_lang_support_r)
5+
add_subdirectory_ifdef(CONFIG_POSIX_C_LIB_EXT c_lib_ext)
56
add_subdirectory_ifdef(CONFIG_POSIX_SHELL shell)
7+
add_subdirectory_ifdef(CONFIG_POSIX_SYSTEM_INTERFACES options)

lib/posix/Kconfig

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,42 @@
11
# Copyright (c) 2024 Meta
2+
# Copyright (c) 2025 Tenstorrent AI ULC
23
#
34
# SPDX-License-Identifier: Apache-2.0
45

56
menu "POSIX API Support"
67

8+
# POSIX Subprofile Definitions
9+
rsource "Kconfig.profile"
10+
11+
# Toolchain hooks for external implementations
12+
rsource "Kconfig.toolchain"
13+
14+
# POSIX C Library Extensions
15+
# This menu is for POSIX Option Groups that do not require OS support.
16+
menu "POSIX C Library Extensions"
17+
rsource "c_lang_support_r/Kconfig"
18+
rsource "c_lib_ext/Kconfig"
19+
endmenu
20+
21+
# POSIX System Interfaces
22+
menuconfig POSIX_SYSTEM_INTERFACES
23+
bool "POSIX System Interfaces"
24+
depends on !NATIVE_APPLICATION
25+
select NATIVE_LIBC_INCOMPATIBLE
26+
help
27+
Select 'y' here to support POSIX System Interfaces within Zephyr.
28+
29+
Options in this menu are organized by POSIX subprofiling Option Group.
30+
31+
For more information, see
32+
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
33+
34+
35+
if POSIX_SYSTEM_INTERFACES
736
rsource "options/Kconfig"
37+
endif
38+
39+
# POSIX Shell utilities
840
rsource "shell/Kconfig"
941

1042
endmenu

lib/posix/options/Kconfig.profile renamed to lib/posix/Kconfig.profile

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
config POSIX_API
6-
bool "POSIX APIs"
7-
depends on !NATIVE_APPLICATION
8-
select NATIVE_LIBC_INCOMPATIBLE
6+
bool "POSIX API (legacy)"
7+
select POSIX_SYSTEM_INTERFACES
98
select POSIX_BASE_DEFINITIONS # clock_gettime(), pthread_create(), sem_get(), etc
109
select POSIX_AEP_REALTIME_MINIMAL # CLOCK_MONOTONIC, pthread_attr_setstack(), etc
1110
select POSIX_NETWORKING if NETWORKING # inet_ntoa(), socket(), etc
@@ -32,14 +31,13 @@ choice POSIX_AEP_CHOICE
3231
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
3332

3433
config POSIX_AEP_CHOICE_NONE
35-
bool "No pre-defined POSIX subprofile"
34+
bool "No POSIX subprofile"
3635
help
37-
No pre-defined POSIX profile is selected.
36+
No POSIX subprofile is selected.
3837

3938
config POSIX_AEP_CHOICE_BASE
40-
bool "Base definitions (system interfaces)"
41-
depends on !NATIVE_APPLICATION
42-
select NATIVE_LIBC_INCOMPATIBLE
39+
bool "Minimal POSIX System Profile"
40+
depends on POSIX_SYSTEM_INTERFACES
4341
select POSIX_BASE_DEFINITIONS
4442
help
4543
Only enable the base definitions required for all POSIX systems.
@@ -49,8 +47,7 @@ config POSIX_AEP_CHOICE_BASE
4947

5048
config POSIX_AEP_CHOICE_PSE51
5149
bool "Minimal Realtime System Profile (PSE51)"
52-
depends on !NATIVE_APPLICATION
53-
select NATIVE_LIBC_INCOMPATIBLE
50+
depends on POSIX_SYSTEM_INTERFACES
5451
select POSIX_BASE_DEFINITIONS
5552
select POSIX_AEP_REALTIME_MINIMAL
5653
help
@@ -63,8 +60,7 @@ config POSIX_AEP_CHOICE_PSE51
6360

6461
config POSIX_AEP_CHOICE_PSE52
6562
bool "Realtime Controller System Profile (PSE52)"
66-
depends on !NATIVE_APPLICATION
67-
select NATIVE_LIBC_INCOMPATIBLE
63+
depends on POSIX_SYSTEM_INTERFACES
6864
select POSIX_BASE_DEFINITIONS
6965
select POSIX_AEP_REALTIME_MINIMAL
7066
select POSIX_AEP_REALTIME_CONTROLLER
@@ -78,8 +74,7 @@ config POSIX_AEP_CHOICE_PSE52
7874

7975
config POSIX_AEP_CHOICE_PSE53
8076
bool "Dedicated Realtime System Profile (PSE53)"
81-
depends on !NATIVE_APPLICATION
82-
select NATIVE_LIBC_INCOMPATIBLE
77+
depends on POSIX_SYSTEM_INTERFACES
8378
select POSIX_BASE_DEFINITIONS
8479
select POSIX_AEP_REALTIME_MINIMAL
8580
select POSIX_AEP_REALTIME_CONTROLLER
@@ -96,7 +91,9 @@ config POSIX_AEP_CHOICE_PSE53
9691

9792
endchoice # POSIX_AEP_CHOICE
9893

99-
# Base Definitions (System Interfaces)
94+
if POSIX_SYSTEM_INTERFACES
95+
96+
# Mandatory POSIX System Interfaces (base profile)
10097
config POSIX_BASE_DEFINITIONS
10198
bool
10299
select POSIX_ASYNCHRONOUS_IO
@@ -184,3 +181,5 @@ config POSIX_AEP_REALTIME_DEDICATED
184181

185182
For more information, please see
186183
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
184+
185+
endif # POSIX_SYSTEM_INTERFACE
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# intentionally empty

lib/posix/c_lib_ext/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
zephyr_include_directories(getopt)
4+
5+
if (CONFIG_TC_PROVIDES_POSIX_C_LIB_EXT)
6+
return()
7+
endif()
8+
9+
zephyr_library()
10+
zephyr_library_sources(
11+
fnmatch.c
12+
getentropy.c
13+
getopt/getopt.c
14+
getopt/getopt_common.c
15+
)
16+
17+
zephyr_library_sources_ifdef(CONFIG_GETOPT_LONG getopt/getopt_long.c)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

lib/posix/options/CMakeLists.txt

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ endif()
2626

2727
if(CONFIG_POSIX_API OR CONFIG_POSIX_THREADS OR CONFIG_POSIX_TIMERS OR
2828
CONFIG_POSIX_MESSAGE_PASSING OR CONFIG_POSIX_FILE_SYSTEM OR
29-
CONFIG_POSIX_C_LIB_EXT OR CONFIG_POSIX_SINGLE_PROCESS)
29+
CONFIG_POSIX_SINGLE_PROCESS)
3030
# This is a temporary workaround so that Newlib declares the appropriate
3131
# types for us. POSIX features to be formalized as part of #51211
3232
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:-D_POSIX_THREADS>)
@@ -43,15 +43,6 @@ if (NOT CONFIG_TC_PROVIDES_POSIX_BARRIERS)
4343
zephyr_library_sources_ifdef(CONFIG_POSIX_BARRIERS barrier.c)
4444
endif()
4545

46-
if (NOT CONFIG_TC_PROVIDES_POSIX_C_LIB_EXT)
47-
zephyr_library_sources_ifdef(CONFIG_POSIX_C_LIB_EXT
48-
fnmatch.c
49-
getentropy.c
50-
getopt/getopt.c
51-
getopt/getopt_common.c
52-
)
53-
endif()
54-
5546
if (NOT CONFIG_TC_PROVIDES_POSIX_DEVICE_IO)
5647
zephyr_library_sources_ifdef(CONFIG_POSIX_DEVICE_IO
5748
# perror should be moved to the common libc
@@ -156,13 +147,6 @@ if (NOT CONFIG_TC_PROVIDES_XSI_SYSTEM_LOGGING)
156147
zephyr_library_sources_ifdef(CONFIG_XSI_SYSTEM_LOGGING syslog.c)
157148
endif()
158149

159-
zephyr_library_sources_ifdef(CONFIG_GETOPT_LONG
160-
getopt/getopt_long.c
161-
)
162-
zephyr_include_directories_ifdef(CONFIG_POSIX_C_LIB_EXT
163-
getopt/
164-
)
165-
166150
zephyr_library_include_directories(
167151
${ZEPHYR_BASE}/kernel/include
168152
${ARCH_DIR}/${ARCH}/include

lib/posix/options/Kconfig

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7-
menu "POSIX Options"
8-
9-
rsource "Kconfig.profile"
10-
117
rsource "Kconfig.aio"
128
rsource "Kconfig.barrier"
13-
rsource "Kconfig.c_lang_r"
14-
rsource "Kconfig.c_lib_ext"
159
rsource "Kconfig.device_io"
1610
rsource "Kconfig.fd_mgmt"
1711
rsource "Kconfig.file_system_r"
@@ -41,7 +35,3 @@ rsource "Kconfig.xsi_threads_ext"
4135
endmenu # "X/Open system interfaces"
4236

4337
rsource "Kconfig.compat"
44-
45-
rsource "Kconfig.toolchain"
46-
47-
endmenu # "POSIX Options"

0 commit comments

Comments
 (0)