Skip to content

Commit

Permalink
Explicitly test stray include paths from the host.
Browse files Browse the repository at this point in the history
This in particular affects `__has_include` new in C++17, which is also
how the test internally works. Tested files are chosen so that there is
no chance that other OSes have matching header files by accident.
  • Loading branch information
lifthrasiir committed Jun 17, 2023
1 parent 84436d6 commit 998830e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
toolchain: [1.63.0, stable, nightly]
# Ideally we should also test against 0.9.0, but it is too unusable to test from CI
zig: [0.10.1, master]
exclude:
# Only test MSRV with zig stable version
Expand Down
39 changes: 36 additions & 3 deletions tests/bindgen-exhaustive/src/sysdep.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
#if defined __has_include
#if __has_include(<linux/netfilter.h>)
#define HAS_LINUX_HEADER
#endif
#if __has_include(<winsock2.h>)
#define HAS_WINDOWS_HEADER
#endif
#if __has_include(<mach/mach_time.h>)
#define HAS_MACOS_HEADER
#endif
#endif

#ifdef __linux__
struct zigbuild_is_linux { int x; };
struct zigbuild_is_linux { int x; };
#if defined __has_include && !defined HAS_LINUX_HEADER
#error "linux targets are expected to have <linux/netfilter.h>"
#endif
#else
#if defined __has_include && defined HAS_LINUX_HEADER
#error "non-linux targets mistakenly have <linux/netfilter.h>, probably from host includes"
#endif
#endif

#ifdef _WIN32
struct zigbuild_is_win32 { int x; };
struct zigbuild_is_win32 { int x; };
#if defined __has_include && !defined HAS_WINDOWS_HEADER
#error "windows targets are expected to have <winsock2.h>"
#endif
#else
#if defined __has_include && defined HAS_WINDOWS_HEADER
#error "non-windows targets mistakenly have <winsock2.h>, probably from host includes"
#endif
#endif

#if defined __APPLE__ && defined __MACH__
struct zigbuild_is_macos { int x; };
struct zigbuild_is_macos { int x; };
#if defined __has_include && !defined HAS_MACOS_HEADER
#error "macos targets are expected to have <mach/mach_time.h>"
#endif
#else
#if defined __has_include && defined HAS_MACOS_HEADER
#error "non-macos targets mistakenly have <mach/mach_time.h>, probably from host includes"
#endif
#endif

0 comments on commit 998830e

Please sign in to comment.