Skip to content

Commit 00bb121

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 <[email protected]>
1 parent bca9424 commit 00bb121

File tree

19 files changed

+75
-40
lines changed

19 files changed

+75
-40
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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +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+
select NATIVE_LIBC_INCOMPATIBLE
25+
help
26+
Select 'y' here to support POSIX System Interfaces within Zephyr.
27+
28+
Options in this menu are organized by POSIX subprofiling Option Group.
29+
30+
For more information, see
31+
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
32+
33+
34+
if POSIX_SYSTEM_INTERFACES
735
rsource "options/Kconfig"
36+
37+
# POSIX Shell utilities
838
rsource "shell/Kconfig"
39+
endif
940

1041
endmenu
1142

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
config POSIX_SYSTEM_HEADERS
5+
config POSIX_SYSTEM_INTERFACES
66
bool
77
select NATIVE_LIBC_INCOMPATIBLE
88
help
99
Make POSIX headers available to the system without the "zephyr/posix" prefix.
1010

1111
config POSIX_API
1212
bool "POSIX APIs"
13-
select NATIVE_LIBC_INCOMPATIBLE
14-
select POSIX_SYSTEM_HEADERS
13+
select POSIX_SYSTEM_INTERFACES
1514
select POSIX_BASE_DEFINITIONS # clock_gettime(), pthread_create(), sem_get(), etc
1615
select POSIX_AEP_REALTIME_MINIMAL # CLOCK_MONOTONIC, pthread_attr_setstack(), etc
1716
select POSIX_NETWORKING if NETWORKING # inet_ntoa(), socket(), etc
@@ -38,13 +37,13 @@ choice POSIX_AEP_CHOICE
3837
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
3938

4039
config POSIX_AEP_CHOICE_NONE
41-
bool "No pre-defined POSIX subprofile"
40+
bool "No POSIX subprofile"
4241
help
43-
No pre-defined POSIX profile is selected.
42+
No POSIX subprofile is selected.
4443

4544
config POSIX_AEP_CHOICE_BASE
46-
bool "Base definitions (system interfaces)"
47-
select NATIVE_LIBC_INCOMPATIBLE
45+
bool "Minimal POSIX System Profile"
46+
select POSIX_SYSTEM_INTERFACES
4847
select POSIX_BASE_DEFINITIONS
4948
help
5049
Only enable the base definitions required for all POSIX systems.
@@ -54,7 +53,7 @@ config POSIX_AEP_CHOICE_BASE
5453

5554
config POSIX_AEP_CHOICE_PSE51
5655
bool "Minimal Realtime System Profile (PSE51)"
57-
select NATIVE_LIBC_INCOMPATIBLE
56+
select POSIX_SYSTEM_INTERFACES
5857
select POSIX_BASE_DEFINITIONS
5958
select POSIX_AEP_REALTIME_MINIMAL
6059
help
@@ -67,7 +66,7 @@ config POSIX_AEP_CHOICE_PSE51
6766

6867
config POSIX_AEP_CHOICE_PSE52
6968
bool "Realtime Controller System Profile (PSE52)"
70-
select NATIVE_LIBC_INCOMPATIBLE
69+
select POSIX_SYSTEM_INTERFACES
7170
select POSIX_BASE_DEFINITIONS
7271
select POSIX_AEP_REALTIME_MINIMAL
7372
select POSIX_AEP_REALTIME_CONTROLLER
@@ -81,7 +80,7 @@ config POSIX_AEP_CHOICE_PSE52
8180

8281
config POSIX_AEP_CHOICE_PSE53
8382
bool "Dedicated Realtime System Profile (PSE53)"
84-
select NATIVE_LIBC_INCOMPATIBLE
83+
select POSIX_SYSTEM_INTERFACES
8584
select POSIX_BASE_DEFINITIONS
8685
select POSIX_AEP_REALTIME_MINIMAL
8786
select POSIX_AEP_REALTIME_CONTROLLER
@@ -98,10 +97,11 @@ config POSIX_AEP_CHOICE_PSE53
9897

9998
endchoice # POSIX_AEP_CHOICE
10099

101-
# Base Definitions (System Interfaces)
100+
if POSIX_SYSTEM_INTERFACES
101+
102+
# Mandatory POSIX System Interfaces (base profile)
102103
config POSIX_BASE_DEFINITIONS
103104
bool
104-
select POSIX_SYSTEM_HEADERS
105105
select POSIX_ASYNCHRONOUS_IO
106106
select POSIX_BARRIERS
107107
select POSIX_CLOCK_SELECTION
@@ -187,3 +187,5 @@ config POSIX_AEP_REALTIME_DEDICATED
187187

188188
For more information, please see
189189
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
190+
191+
endif # POSIX_SYSTEM_INTERFACE
File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright The Zephyr Project Contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
set(POSIX_VERSION 200809L)
5+
6+
if (CONFIG_POSIX_C_LANG_SUPPORT_R)
7+
zephyr_compile_definitions(-D_POSIX_THREAD_SAFE_FUNCTIONS=${POSIX_VERSION})
8+
endif()
File renamed without changes.

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.

0 commit comments

Comments
 (0)