From 53df2d880b2d6d22c1ae396f753f10b9153cf13c Mon Sep 17 00:00:00 2001 From: Dimitris Papaioannou Date: Thu, 27 Aug 2026 21:54:18 +0300 Subject: [PATCH] Pass system header paths to fallback parser If a macro needed to be parsed using the fallback parser but the macro used items included in a builtin header, the parsing would fail since the location of the header would be unknown. --- .../expectations/tests/macro-fallback-include-builtin.rs | 2 ++ .../tests/headers/macro-fallback-include-builtin.h | 7 +++++++ bindgen/lib.rs | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 bindgen-tests/tests/expectations/tests/macro-fallback-include-builtin.rs create mode 100644 bindgen-tests/tests/headers/macro-fallback-include-builtin.h diff --git a/bindgen-tests/tests/expectations/tests/macro-fallback-include-builtin.rs b/bindgen-tests/tests/expectations/tests/macro-fallback-include-builtin.rs new file mode 100644 index 0000000000..b4fbcde929 --- /dev/null +++ b/bindgen-tests/tests/expectations/tests/macro-fallback-include-builtin.rs @@ -0,0 +1,2 @@ +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub const TEST: u32 = 42; diff --git a/bindgen-tests/tests/headers/macro-fallback-include-builtin.h b/bindgen-tests/tests/headers/macro-fallback-include-builtin.h new file mode 100644 index 0000000000..dbb47a4b39 --- /dev/null +++ b/bindgen-tests/tests/headers/macro-fallback-include-builtin.h @@ -0,0 +1,7 @@ +// bindgen-flags: --clang-macro-fallback --allowlist-item TEST +// Ensures that the fallback path for macros doesn't silently +// fail because of builtin headers not being found. + +#include + +#define TEST ((size_t)42) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 88e07a41ef..f5b7326e3e 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -871,7 +871,10 @@ impl Bindings { for path in search_paths { if let Ok(path) = path.into_os_string().into_string() { options.clang_args.push("-isystem".into()); - options.clang_args.push(path.into_boxed_str()); + options.clang_args.push(path.clone().into_boxed_str()); + + options.fallback_clang_args.push("-isystem".into()); + options.fallback_clang_args.push(path.into_boxed_str()); } } }