Skip to content

Do not include sysctl.h on Linux. #660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Do not include sysctl.h on Linux.
This PR ensures `<sys/sysctl.h>` is not included on Linux, where it generates compile-time diagnostics on distros/versions where it's still present. The diagnostic looks something like:

```
[5/5][100%][7.920s] Linking Swift shared library lib/libTesting.so
<module-includes>:3:10: note: in file included from <module-includes>:3:
1 | #include "./Defines.h"
2 | #include "./Discovery.h"
3 | #include "./Includes.h"
  |          `- note: in file included from <module-includes>:3:
4 | #include "./Stubs.h"
5 | #include "./TestSupport.h"

/home/build-user/swift-testing/Sources/_TestingInternals/include/./Includes.h:61:10: note: in file included from /home/build-user/swift-testing/Sources/_TestingInternals/include/./Includes.h:61:
 59 |
 60 | #if __has_include(<sys/sysctl.h>)
 61 | #include <sys/sysctl.h>
    |          `- note: in file included from /home/build-user/swift-testing/Sources/_TestingInternals/include/./Includes.h:61:
 62 | #endif
 63 |
```

Since we don't use `sysctl()` on Linux (and it's been outright removed from the OS!), let's fix the diagnostic.
  • Loading branch information
grynspan committed Sep 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 06fa07b4b43ba76eadc9d9dd85317e6703e76235
2 changes: 1 addition & 1 deletion Sources/_TestingInternals/include/Includes.h
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@
#include <sys/stat.h>
#endif

#if __has_include(<sys/sysctl.h>)
#if __has_include(<sys/sysctl.h>) && !defined(__linux__)
#include <sys/sysctl.h>
#endif