Skip to content

Conversation

@cfriedt
Copy link
Member

@cfriedt cfriedt commented Oct 18, 2025

Deprecation of CONFIG_POSIX_API

Deprecate CONFIG_POSIX_API.

Users may choose one of the pre-defined POSIX subprofiles, for simplicity.

Libraries should depend on CONFIG_POSIX_SYSTEM_INTERFACES as well as other POSIX Option Groups, as needed.

Custom Configurations

Of course, instead of, or in addition to, using a pre-defined POSIX subprofile, users can still fully customize their POSIX configuration via Kconfig.

Zephyr's POSIX Kconfig option names correspond 1:1 with official POSIX Option Group names. Simply add a CONFIG_ at the beginning of an Option Group to get the corresponding Kconfig option.

For more information on POSIX Subprofiling Option Groups, please see
https://pubs.opengroup.org/onlinepubs/9799919799/xrat/V4_subprofiles.html

Removal of zephyr/posix/ prefix for standard includes

The majority of the changes in this category (~156 files) are mechanical and are contained in the commit posix: remove zephyr/posix in header prefixes. They are approximately equivalent to running this command (with some adjustments).

FILE_LIST="$(grep "^#include.*zephyr/posix/" $(find * -name '*.c' -o -name '*.h') | awk '{split($0,a,":"); print a[1];}' | sort -u)"
sed -i -e 's|zephyr/posix/||g' $FILE_LIST

Originally from #97152, but included here for simplicity, these changes mean that we no longer need to have include/zephyr/posix in the library search path for C libraries that have (at least partially) conformant POSIX headers. In other words, we use the C library's POSIX headers.

  • Eliminates conflicts between Zephyr's POSIX headers and the libc headers
    • C library headers and types used as-is whenever possible
    • Still possible to "fix up" libc headers, as needed, via #include_next <foo.h>
    • It allows non-POSIX C libraries to also have POSIX support in Zephyr
  • Ensures that POSIX applications and libraries are actually portable at the source level and, in many cases, at the binary level
  • Paves the way for Zephyr's POSIX implementation to become a module

Originally added to mitigate C-library conflicts, the <zephyr/posix/...h> prefix on standard includes has been a thorn in our sides for several years. Since these changes remove the conflicts, opting to use C-library headers (if they exist), we no longer need to namespace those in Zephyr.

Depends on

Note

Compliance issues are false positives

Fixes #97949
Fixes #98661

SUMMARY

Summary:
@nordicjm

@aescolar

@nashif

@jhedberg

@carlescufi

@github-actions
Copy link

github-actions bot commented Oct 19, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
hal_ti zephyrproject-rtos/hal_ti@cc04902 zephyrproject-rtos/hal_ti@33dae8f (master) zephyrproject-rtos/[email protected]
hostap zephyrproject-rtos/hostap@cf05f33 zephyrproject-rtos/hostap@ab7630c zephyrproject-rtos/[email protected]

All manifest checks OK

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@github-actions github-actions bot added manifest manifest-hostap DNM (manifest) This PR should not be merged (controlled by action-manifest) labels Oct 19, 2025
@stephanosio stephanosio assigned cfriedt and unassigned stephanosio Oct 19, 2025
@cfriedt cfriedt force-pushed the deprecate-config-posix-api branch 2 times, most recently from b9dac21 to dc6abc8 Compare October 19, 2025 01:36
@cfriedt
Copy link
Member Author

cfriedt commented Oct 19, 2025

  • rebased

@cfriedt cfriedt force-pushed the deprecate-config-posix-api branch from e68fe2e to 191fb79 Compare November 7, 2025 13:33
@cfriedt
Copy link
Member Author

cfriedt commented Nov 7, 2025

I guess if the shims are only needed when posix is needed, we could just guard this in cmake and do the following, no?

--- a/lib/libc/picolibc/CMakeLists.txt
+++ b/lib/libc/picolibc/CMakeLists.txt
@@ -10,7 +10,9 @@ zephyr_library_sources(
   locks.c
   stdio.c
   )
+if(CONFIG_POSIX_WHATEVER)
 zephyr_include_directories(include)
+endif()
 if(CONFIG_PICOLIBC_USE_MODULE)
   # temporary workaround for https://github.com/picolibc/picolibc/pull/1079
   zephyr_compile_options(-Dpid_t=__pid_t)

It wasn't quite that easy, but this seems to have worked and given me the opportunity to fix something that was missed up until this point as well. Namely, that net/if_arp.h is not a POSIX header file, so that is moved back to include/zephyr/net and a few unnecessary shim headers were removed.

There are additional workarounds needed in order to avoid using shims.

  1. No preprocessor guards exist around the declaration of struct timespec in Picolibc. Removed inclusion of the POSIX header <sys/types.h> from lib/os/printk.c and lib/os/cbprintf_complete.c to remove build errors due to re-declaration due to aforementioned lack of preprocessor guards, and since those files do not rely on POSIX types.
  2. Manually declare inet_pton() as well when Picolibc is used since it is missing the declaration in <arpa/inet.h>.

This should be sufficient to satisfy one of Alberto's pending comments mentioned here. I will not be shuffling headers around to some unrelated folder at this time, and I do not see the need to do so in the future. However, headers required as workarounds for issues in Picolibc can be removed as Picolibc is improved over time.

Changes are here
https://github.com/zephyrproject-rtos/zephyr/compare/e68fe2eeae59d9d24f2c80c704e66da204c5afba..191fb795b609b57a9022f2226a07524c1c6e0738

@cfriedt cfriedt requested review from jhedberg and ycsin November 7, 2025 14:58
@cfriedt
Copy link
Member Author

cfriedt commented Nov 7, 2025

@nashif @jhedberg @ycsin @jukkar - just a re-ping here since the PR was updated. All tests are still passing.

@cfriedt
Copy link
Member Author

cfriedt commented Nov 7, 2025

Hey @carlescufi

The CMakeLists.txt suggestion worked with some extra effort.

I completely agree with you, but then my question would be why not first fix the issues with the networking subsystem that you mention (I can work with @jukkar and @rlubos to make this happen) which to me seems a prerequisite to being able to clean up the POSIX subsystem

It's not really a prerequisite, as demonstrated by the last month of successful CI runs. As long as there are non-broken headers for the network stack to use, everything is fine, and it works identically.

What's nicely demonstrated here, is that it's quite straight-forward to make the problem of refactoring the network stack a separable one, due to the well-established interface. I.e. as long as the interface is consistent and functionality is the same, the implementation may be modified.

Since reworking the network stack has been demonstrated to be a separable problem, there is no need to defer this change to pay off that technical debt.

Copy link
Member

@aescolar aescolar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is better.
But note we'd want to do the same for the other libCs too, not just picolibc.

Note that placing these new headers in a separate folders and only including them in a more fine grained way than CONFIG_POSIX_BASE_DEFINITIONS OR CONFIG_EVENTFD would help limiting side-effects as described in #99075.

ycsin
ycsin previously approved these changes Nov 10, 2025
CONFIG_XOPEN_STREAMS does not follow the pattern of other XSI Option
Groups, where the Option Group name is not the same as the feature
test macro that indicates it is supported by the implementation.

Deprecate CONFIG_XOPEN_STREAMS and rename it to CONFIG_XSI_STREAMS.

For more information, please see
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/\
V1_chap02.html#tag_02_01_05_09

Signed-off-by: Chris Friedt <[email protected]>
Deprecate the CONFIG_XOPEN_STREAMS Kconfig option in favour of
CONFIG_XSI_STREAMS, which matches the naming conventions of other XSI
Kconfig options and the actual Option Group name in the specification.

Please use CONFIG_XSI_STREAMS instead.

Signed-off-by: Chris Friedt <[email protected]>
This change mitigates some code sonar issues (from SonarQube).

1. explicit 'U' after 0xffffffff

> A cast shall not remove any const or volatile qualification from the
> type of a pointer or reference c:S859

2. check return value from call to pthread_barrierattr_getpshared()

> Unused assignments should be removed c:S1854

Signed-off-by: Chris Friedt <[email protected]>
This mitigates a sonarqube warning

"Value stored to 'cvalue' is never read"

> Unused assignments should be removed c:S1854

https://sonarcloud.io/project/issues?pullRequest=97152&\
open=AZnAZi4C7BgzESPFIGwf&id=zephyrproject-rtos_zephyr

Signed-off-by: Chris Friedt <[email protected]>
This change mitigates a sonarqube warning about uninitialized variables.

"1st function call argument is an uninitialized value"

> Variables should be initialized before use c:S836

https://sonarcloud.io/project/issues?pullRequest=97152&\
open=AZnAZi0m7BgzESPFIGwe&id=zephyrproject-rtos_zephyr

Signed-off-by: Chris Friedt <[email protected]>
There is no need to pull in a POSIX header file into these files,
so remove it.

Signed-off-by: Chris Friedt <[email protected]>
If C libraries provide conformant POSIX headers, then use the headers
provided by the C library.

Otherwise, C library maintainers may add `include/zephyr/posix` to their
standard search path.

This change removes the requirement to have `<zephyr/posix/...>` prefixing
all standard POSIX includes in Zephyr.

The main reason that it was required was due to conflicts between C
library time.h, signal.h and the fact that Zephyr posix headers were being
somewhat ad-hoc mixed with libc posix headers.

Now, any (even partially) POSIX-conformant C libraries are expected to
provide their own types, constants, and headers, and Zephyr's
implementation uses those definitions.

If any definitions are missing, we define them on a per-libc basis. This
can also be done out-of-tree, which allows for implementors to take
advantage of the `CONFIG_TC_PROVIDES_POSIX..` options.

This is likely the last major commit required before we deprecate the
`CONFIG_POSIX_API` Kconfig option in favour of POSIX subprofiling \o/

Signed-off-by: Chris Friedt <[email protected]>
Include standard headers for POSIX types and functions instead of making
implicit declarations.

Signed-off-by: Chris Friedt <[email protected]>
Remove the duplicate Kconfig option `CONFIG_POSIX_SYSTEM_INTERFACES` in
`lib/posix/Kconfig.profile` that shadows the option in
`lib/posix/Kconfig`.

Signed-off-by: Chris Friedt <[email protected]>
This change deprecates the Kconfig option `CONFIG_POSIX_API`.

It is slated for removal in Zephyr v4.5.0.

Signed-off-by: Chris Friedt <[email protected]>
Add release notes about the deprecation of CONFIG_POSIX_API.

User should instead use one of the pre-defined POSIX subprofiles

CONFIG_POSIX_AEP_CHOICE_BASE
CONFIG_POSIX_AEP_CHOICE_PSE51
CONFIG_POSIX_AEP_CHOICE_PSE52
CONFIG_POSIX_AEP_CHOICE_PSE53

and libraries should depend on CONFIG_POSIX_SYSTEM_INTERFACES as well as
other POSIX Option Groups, as needed.

For more information, please see

https://pubs.opengroup.org/onlinepubs/9799919799/xrat/V4_subprofiles.html

Signed-off-by: Chris Friedt <[email protected]>
The specification requires that unistd.h (or a file that is included via
unistd.h) declare version macros and symbolic constants.

Feature test macros declarations are also removed from
`lib/posix/options/CMakeLists.txt`.

Closes zephyrproject-rtos#97949

Signed-off-by: Chris Friedt <[email protected]>
@cfriedt
Copy link
Member Author

cfriedt commented Nov 10, 2025

But note we'd want to do the same for the other libCs too, not just picolibc.

Disagree. The only reason that including the path was made conditional was because it was your preference, which, in my opinion, is not sufficient technical justification.

I called it a workaround for the workaround, because the original workaround was to correct inconsistencies in C libraries, but then the workaround for the workaround was for you, since you seem to prefer broken headers, which introduces more inconsistence and tech debt.

For a technical justification, we have to consider why the path is included in the first place. It's included to provide a way to supply POSIX headers when Picolibc (and other C libraries) does not (either partially or fully) provide the header or required definitions (i.e. to have a consistent compilation environment).

Of course, this is only necessary when POSIX is configured, due to work done over the last few years.

I should take a step back - that's only true until some source file includes a POSIX header without configuring POSIX, which is historically extremely likely in the Zephyr project. So having shim files available unconditionally would be more consistent, just like they are unconditionally available from the C library (even if only partially complete as provided by the C library).

Now, inconsistence aside, assuming that it is possible to fix the C library over time to be more conformant, then shim headers can be removed over time as well (as well as the path to include shim headers).

If that assumption does not hold, which is the case for (at least Zephyr's SDK) newlib, minimal libc, IAR, ARCMWDT, most commercial toolchains, etc), then shim headers, and the include paths, should remain as long as they are required.

Note that placing these new headers in a separate folders and only including them in a more fine grained way than CONFIG_POSIX_BASE_DEFINITIONS OR CONFIG_EVENTFD would help limiting side-effects as described in #99075.

What side effects? There are none described in #99075.

If "side effects" mean having functional code, that is, by definition, not a side effect, but an intentional and direct effect.

The conditions for including the shim header path are by no means meant to be permanent. Personally, I would have not added them at all due to aforementioned concerns with inconsistence, had it not been for @nashif's suggestion, and @carlescufi's follow-up, squarely meant to satisfy you.

So from that perspective, you seem to want the rest of the Zephyr community to suffer with additional technical debt beyond the release cycle due to your preference.

So no, "we" do not want to do the same for the other libCs, and I still question the value in making the shim header path conditional for Picolibc as well.

@sonarqubecloud
Copy link

@aescolar
Copy link
Member

aescolar commented Nov 11, 2025

I created #99075 to facilitate discussing the more fundamental issues. As there seems to be a disagreement about how the POSIX_API should relate to the C library, its integration, and how optional or not it should be.

@nashif nashif moved this from Todo to In Progress in TSC Attention Needed Nov 12, 2025
@jhedberg jhedberg modified the milestones: v4.3.0, v4.4.0 Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug The issue is a bug, or the PR is fixing a bug Compliance: False Positive DNM This PR should not be merged (Do Not Merge) manifest manifest-hal_ti manifest-hostap priority: high High impact/importance bug TSC Topics that need TSC discussion

Projects

Status: In Progress