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 68daa8f commit dce74cc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
toolchain: [1.64.0, stable, nightly]
zig: [0.10.1, master]
zig: [0.9.0, 0.10.1, master]
exclude:
# Only test MSRV with zig stable version
- toolchain: 1.64.0
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 dce74cc

Please sign in to comment.