Skip to content

Commit fa9e933

Browse files
cfriedtnashif
authored andcommitted
posix: allow for external implementation of option groups
Make it easier for external C libraries, toolchains, and integrators to override Zephyr's implementation of functions and sybmols on a per-Option-Group basis. This change adds a number of non-user-configurable Kconfig options that block internal Cmake rules from building Zephyr's C sources corresponding to the particular option. This is useful, for example, if a specific C library has a smaller, or faster, or more secure version of some symbols belonging to a a particular option group. Signed-off-by: Chris Friedt <[email protected]>
1 parent b7ed82c commit fa9e933

File tree

3 files changed

+367
-59
lines changed

3 files changed

+367
-59
lines changed

lib/posix/options/CMakeLists.txt

Lines changed: 125 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@ if(CONFIG_POSIX_API)
88
zephyr_include_directories(${ZEPHYR_BASE}/include/zephyr/posix)
99
endif()
1010

11-
if(CONFIG_POSIX_SIGNALS)
12-
set(STRSIGNAL_TABLE_H ${GEN_DIR}/posix/strsignal_table.h)
13-
14-
add_custom_command(
15-
OUTPUT ${STRSIGNAL_TABLE_H}
16-
COMMAND
17-
${PYTHON_EXECUTABLE}
18-
${ZEPHYR_BASE}/scripts/build/gen_strsignal_table.py
19-
-i ${ZEPHYR_BASE}/include/zephyr/posix/signal.h
20-
-o ${STRSIGNAL_TABLE_H}
21-
DEPENDS ${ZEPHYR_BASE}/include/zephyr/posix/signal.h
22-
)
11+
if (NOT CONFIG_TC_PROVIDES_POSIX_SIGNALS)
12+
if(CONFIG_POSIX_SIGNALS)
13+
set(STRSIGNAL_TABLE_H ${GEN_DIR}/posix/strsignal_table.h)
14+
15+
add_custom_command(
16+
OUTPUT ${STRSIGNAL_TABLE_H}
17+
COMMAND
18+
${PYTHON_EXECUTABLE}
19+
${ZEPHYR_BASE}/scripts/build/gen_strsignal_table.py
20+
-i ${ZEPHYR_BASE}/include/zephyr/posix/signal.h
21+
-o ${STRSIGNAL_TABLE_H}
22+
DEPENDS ${ZEPHYR_BASE}/include/zephyr/posix/signal.h
23+
)
24+
endif()
2325
endif()
2426

2527
if(CONFIG_POSIX_API OR CONFIG_POSIX_THREADS OR CONFIG_POSIX_TIMERS OR
@@ -33,60 +35,124 @@ endif()
3335

3436
zephyr_library()
3537
zephyr_library_sources_ifdef(CONFIG_EVENTFD eventfd.c)
36-
zephyr_library_sources_ifdef(CONFIG_POSIX_ASYNCHRONOUS_IO aio.c)
37-
zephyr_library_sources_ifdef(CONFIG_POSIX_BARRIERS barrier.c)
38-
zephyr_library_sources_ifdef(CONFIG_POSIX_C_LIB_EXT
39-
fnmatch.c
40-
getentropy.c
41-
getopt/getopt.c
42-
getopt/getopt_common.c
43-
)
44-
zephyr_library_sources_ifdef(CONFIG_POSIX_DEVICE_IO
45-
# perror should be moved to the common libc
46-
perror.c
47-
device_io.c
48-
)
49-
zephyr_library_sources_ifdef(CONFIG_POSIX_FD_MGMT
50-
fd_mgmt.c
51-
)
52-
zephyr_library_sources_ifdef(CONFIG_POSIX_FILE_SYSTEM fs.c)
38+
39+
if (NOT CONFIG_TC_PROVIDES_POSIX_ASYNCHRONOUS_IO)
40+
zephyr_library_sources_ifdef(CONFIG_POSIX_ASYNCHRONOUS_IO aio.c)
41+
endif()
42+
43+
if (NOT CONFIG_TC_PROVIDES_POSIX_BARRIERS)
44+
zephyr_library_sources_ifdef(CONFIG_POSIX_BARRIERS barrier.c)
45+
endif()
46+
47+
if (NOT CONFIG_TC_PROVIDES_POSIX_C_LIB_EXT)
48+
zephyr_library_sources_ifdef(CONFIG_POSIX_C_LIB_EXT
49+
fnmatch.c
50+
getentropy.c
51+
getopt/getopt.c
52+
getopt/getopt_common.c
53+
)
54+
endif()
55+
56+
if (NOT CONFIG_TC_PROVIDES_POSIX_DEVICE_IO)
57+
zephyr_library_sources_ifdef(CONFIG_POSIX_DEVICE_IO
58+
# perror should be moved to the common libc
59+
perror.c
60+
device_io.c
61+
)
62+
endif()
63+
64+
if (NOT CONFIG_TC_PROVIDES_POSIX_FD_MGMT)
65+
zephyr_library_sources_ifdef(CONFIG_POSIX_FD_MGMT
66+
fd_mgmt.c
67+
)
68+
endif()
69+
70+
if (NOT CONFIG_TC_PROVIDES_POSIX_FILE_SYSTEM)
71+
zephyr_library_sources_ifdef(CONFIG_POSIX_FILE_SYSTEM fs.c)
72+
endif()
73+
5374
zephyr_library_sources_ifdef(CONFIG_POSIX_FSYNC fsync.c)
5475
zephyr_library_sources_ifdef(CONFIG_POSIX_MEMLOCK mlockall.c)
5576
zephyr_library_sources_ifdef(CONFIG_POSIX_MEMLOCK_RANGE mlock.c)
77+
78+
if (NOT CONFIG_TC_PROVIDES_POSIX_MEMORY_PROTECTION)
5679
zephyr_library_sources_ifdef(CONFIG_POSIX_MEMORY_PROTECTION mprotect.c)
57-
zephyr_library_sources_ifdef(CONFIG_POSIX_MAPPED_FILES mmap.c)
80+
endif()
81+
82+
if (NOT CONFIG_TC_PROVIDES_POSIX_MAPPED_FILES)
83+
zephyr_library_sources_ifdef(CONFIG_POSIX_MAPPED_FILES mmap.c)
84+
endif()
85+
5886
zephyr_library_sources_ifdef(CONFIG_POSIX_MESSAGE_PASSING mqueue.c)
59-
zephyr_library_sources_ifdef(CONFIG_POSIX_MULTI_PROCESS
60-
sleep.c
61-
multi_process.c
62-
)
63-
zephyr_library_sources_ifdef(CONFIG_POSIX_NETWORKING net.c)
64-
zephyr_library_sources_ifdef(CONFIG_POSIX_SHARED_MEMORY_OBJECTS shm.c)
65-
zephyr_library_sources_ifdef(CONFIG_POSIX_SIGNALS signal.c ${STRSIGNAL_TABLE_H})
66-
zephyr_library_sources_ifdef(CONFIG_POSIX_SINGLE_PROCESS
67-
confstr.c
68-
env.c
69-
sysconf.c
70-
uname.c
71-
)
72-
zephyr_library_sources_ifdef(CONFIG_POSIX_SPIN_LOCKS spinlock.c)
73-
zephyr_library_sources_ifdef(CONFIG_POSIX_SYSLOG syslog.c)
74-
zephyr_library_sources_ifdef(CONFIG_POSIX_TIMERS
75-
clock.c
76-
timer.c
77-
timespec_to_timeout.c
78-
)
87+
88+
if (NOT CONFIG_TC_PROVIDES_POSIX_MULTI_PROCESS)
89+
zephyr_library_sources_ifdef(CONFIG_POSIX_MULTI_PROCESS
90+
sleep.c
91+
multi_process.c
92+
)
93+
endif()
94+
95+
if (NOT CONFIG_TC_PROVIDES_POSIX_NETWORKING)
96+
zephyr_library_sources_ifdef(CONFIG_POSIX_NETWORKING net.c)
97+
endif()
98+
99+
if (NOT CONFIG_TC_PROVIDES_POSIX_SHARED_MEMORY_OBJECTS)
100+
zephyr_library_sources_ifdef(CONFIG_POSIX_SHARED_MEMORY_OBJECTS shm.c)
101+
endif()
102+
103+
if (NOT CONFIG_TC_PROVIDES_POSIX_SIGNALS)
104+
zephyr_library_sources_ifdef(CONFIG_POSIX_SIGNALS signal.c ${STRSIGNAL_TABLE_H})
105+
endif()
106+
107+
if (NOT CONFIG_TC_PROVIDES_POSIX_SINGLE_PROCESS)
108+
zephyr_library_sources_ifdef(CONFIG_POSIX_SINGLE_PROCESS
109+
confstr.c
110+
env.c
111+
sysconf.c
112+
uname.c
113+
)
114+
endif()
115+
116+
if (NOT CONFIG_TC_PROVIDES_POSIX_SPIN_LOCKS)
117+
zephyr_library_sources_ifdef(CONFIG_POSIX_SPIN_LOCKS spinlock.c)
118+
endif()
119+
120+
if (NOT CONFIG_TC_PROVIDES_POSIX_TIMERS)
121+
zephyr_library_sources_ifdef(CONFIG_POSIX_TIMERS
122+
clock.c
123+
timer.c
124+
timespec_to_timeout.c
125+
)
126+
endif()
127+
79128
zephyr_library_sources_ifdef(CONFIG_POSIX_PRIORITY_SCHEDULING sched.c)
80-
zephyr_library_sources_ifdef(CONFIG_POSIX_READER_WRITER_LOCKS rwlock.c)
81-
zephyr_library_sources_ifdef(CONFIG_POSIX_SEMAPHORES semaphore.c)
82-
zephyr_library_sources_ifdef(CONFIG_POSIX_THREADS
83-
cond.c
84-
key.c
85-
mutex.c
86-
pthread.c
87-
)
129+
130+
if (NOT CONFIG_TC_PROVIDES_POSIX_READER_WRITER_LOCKS)
131+
# Note: the Option is _POSIX_READER_WRITER_LOCKS, while the Option Group is POSIX_RW_LOCKS.
132+
# We have opted to use POSIX_READER_WRITER_LOCKS here to match the Option name.
133+
zephyr_library_sources_ifdef(CONFIG_POSIX_READER_WRITER_LOCKS rwlock.c)
134+
endif()
135+
136+
if (NOT CONFIG_TC_PROVIDES_POSIX_SEMAPHORES)
137+
zephyr_library_sources_ifdef(CONFIG_POSIX_SEMAPHORES semaphore.c)
138+
endif()
139+
140+
if (NOT CONFIG_TC_PROVIDES_POSIX_THREADS)
141+
# Note: the Option is _POSIX_THREADS, while the Option Group is POSIX_THREADS_BASE.
142+
# We have opted to use POSIX_THREADS here to match the Option name.
143+
zephyr_library_sources_ifdef(CONFIG_POSIX_THREADS
144+
cond.c
145+
key.c
146+
mutex.c
147+
pthread.c
148+
)
149+
endif()
150+
88151
zephyr_library_sources_ifdef(CONFIG_XOPEN_STREAMS stropts.c)
89-
zephyr_library_sources_ifdef(CONFIG_XSI_SYSTEM_LOGGING syslog.c)
152+
153+
if (NOT CONFIG_TC_PROVIDES_XSI_SYSTEM_LOGGING)
154+
zephyr_library_sources_ifdef(CONFIG_XSI_SYSTEM_LOGGING syslog.c)
155+
endif()
90156

91157
zephyr_library_sources_ifdef(CONFIG_GETOPT_LONG
92158
getopt/getopt_long.c

lib/posix/options/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ rsource "Kconfig.compat"
3333

3434
rsource "Kconfig.deprecated"
3535

36+
rsource "Kconfig.toolchain"
37+
3638
endmenu # "POSIX Options"

0 commit comments

Comments
 (0)