Skip to content

Conversation

@cfriedt
Copy link
Member

@cfriedt cfriedt commented Jul 13, 2024

A corner case involving C++, posix, networking, and native_sim was causing problems.

Even though C and C++ builds should include zephyr/posix/.. in the default search path with CONFIG_POSIX_API=y, for some reason, the native compiler pulls in /usr/include first anyway.

The stat.h header pulled in <sys/types.h> (which is normally fine) but due to the native build, it was pulling in /usr/include/sys/types.h, from the host toolchain.

Explicitly include <zephyr/posix/posix_types.h> instead of <sys/types.h> from stat.h, and continue using the workarounds for native builds (explicitly including zephyr/posix/arpa/net.h etc from net/sockets.h, etc).

The workaround must be left in the tree until the deprecated option CONFIG_NET_SOCKETS_POSIX_NAMES is removed, at which point Zephyr's POSIX API will be a consumer of the network subsystem, eliminating one of the few remaining dependency cycles in Zephyr.

Fixes #75319

@cfriedt cfriedt requested review from jukkar, rlubos and ycsin July 13, 2024 21:03
cfriedt added 2 commits July 13, 2024 17:08
A corner case involving C++, posix, networking, and native_sim
was causing problems.

Even though C and C++ builds should include zephyr/posix/.. in
the default search path with `CONFIG_POSIX_API=y`, for some
reason, the native compiler pulls in /usr/include first anyway.

The stat.h header pulled in <sys/types.h> (which is normally
fine) but due to the native build, it was pulling in
/usr/include/sys/types.h, from the host toolchain.

Explicitly include <zephyr/posix/posix_types.h> instead of
<sys/types.h> from stat.h, and continue using the workarounds
for native builds (explicitly including zephyr/posix/arpa/net.h
from net/sockets.h .

Signed-off-by: Chris Friedt <[email protected]>
@cfriedt cfriedt force-pushed the issues/75319/fix-cpp-posix-net-native-sim-build branch from 4c4cddd to d6fe2fc Compare July 13, 2024 21:08
A number of types such as uid_t, gitd_t, etc, were defined in
sys/stat.h to workaround compatibility issues many years ago.

Since posix_types.h is slated to become equivalent to
sys/types.h in terms of standard headers, move these types
to where they belong.

For more information, please see

https://pubs.opengroup.org/onlinepubs/9699919799/\
 basedefs/sys_types.h.html

Signed-off-by: Chris Friedt <[email protected]>
@cfriedt cfriedt force-pushed the issues/75319/fix-cpp-posix-net-native-sim-build branch from 3258021 to 8467129 Compare July 14, 2024 01:34
cfriedt added 2 commits July 14, 2024 06:24
Simplify the conditions for pthread type declaration

Signed-off-by: Chris Friedt <[email protected]>
Prior to the fixes in the previous commits, combining a build
for native_sim with

CONFIG_CPP=y
CONFIG_POSIX_API=y
CONFIG_STD_CPP20=y
CONFIG_REQUIRES_FULL_LIBCPP=y

would fail.

It succeeds now.

This change adds a testcase to monitor that scenario in CI.

Note: this was partially necessary because the deprecation of
CONFIG_NET_SOCKETS_POSIX_NAMES is not yet complete, so there
is a dependency cycle, and also because <sys/types.h> was
pulling in the host <sys/types.h> instead of Zephyr's or one
of the embedded OSes we support.

Signed-off-by: Chris Friedt <[email protected]>
@cfriedt cfriedt force-pushed the issues/75319/fix-cpp-posix-net-native-sim-build branch from 8467129 to 9914838 Compare July 14, 2024 10:25
@cfriedt cfriedt marked this pull request as ready for review July 14, 2024 20:40
@cfriedt cfriedt added the bug The issue is a bug, or the PR is fixing a bug label Jul 14, 2024
Copy link
Member

@ycsin ycsin left a comment

Choose a reason for hiding this comment

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

Thanks

@cfriedt cfriedt added this to the v3.7.0 milestone Jul 15, 2024
@nashif nashif added the backport v3.7-branch Request backport to the v3.7-branch label Jul 16, 2024
@cfriedt cfriedt modified the milestones: v3.7.0, v3.7.1 Jul 16, 2024
@0x6e
Copy link
Contributor

0x6e commented Jul 20, 2024

Thank you, I can confirm that #75319 is fixed when this PR is checked out.

@cfriedt cfriedt deleted the issues/75319/fix-cpp-posix-net-native-sim-build branch July 27, 2024 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Networking area: POSIX POSIX API Library backport v3.7-branch Request backport to the v3.7-branch bug The issue is a bug, or the PR is fixing a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fatal error: sys/_timespec.h: No such file or directory with v3.7.0-rc2

7 participants