From 55370eb24fcd42f860fd5e02cf6d19d7a7990a40 Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Thu, 12 Oct 2023 12:50:00 -0700 Subject: [PATCH] Make sure bindgen gets the cppflags even if we aren't using macOS --- pgrx-pg-sys/build.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pgrx-pg-sys/build.rs b/pgrx-pg-sys/build.rs index b8a9e5eae4..290cea728d 100644 --- a/pgrx-pg-sys/build.rs +++ b/pgrx-pg-sys/build.rs @@ -885,24 +885,24 @@ fn build_shim_for_version( fn extra_bindgen_clang_args(pg_config: &PgConfig) -> eyre::Result> { let mut out = vec![]; + let flags = shlex::split(&flags.to_string_lossy()).unwrap_or_default(); + // Just give clang the full flag set, since presumably that's what we're + // getting when we build the C shim anyway. + out.extend(flags.iter().cloned()); if env_tracked("CARGO_CFG_TARGET_OS").as_deref() == Some("macos") { - // On macOS, find the `-isysroot` arg out of the c preprocessor flags, - // to handle the case where bindgen uses a libclang isn't provided by - // the system. - let flags = pg_config.cppflags()?; - // In practice this will always be valid UTF-8 because of how the - // `pgrx-pg-config` crate is implemented, but even if it were not, the - // problem won't be with flags we are interested in. - let flags = shlex::split(&flags.to_string_lossy()).unwrap_or_default(); - // Just give clang the full flag set, since presumably that's what we're - // getting when we build the C shim anyway. - out.extend(flags.iter().cloned()); - // Find the `-isysroot` flags so we can warn about them, so something // reasonable shows up if/when the build fails. // - // Eventually we should probably wrangle the sysroot for `cargo pgrx - // init`-installed PGs a bit more aggressively, but for now, whatever. + // TODO(thom): Could probably fix some brew/xcode issues here in the + // Find the `-isysroot` flags so we can warn about them, so something + // reasonable shows up if/when the build fails. + // + // - Handle homebrew packages initially linked against as keg-only, but + // which have had their version bumped. + for pair in flags.windows(2) { + if pair[0] == "-isysroot" { + if !std::path::Path::new(&pair[1]).exists() { + // The SDK path doesn't exist. Emit a warning, which they'll for pair in flags.windows(2) { if pair[0] == "-isysroot" { if !std::path::Path::new(&pair[1]).exists() {