Skip to content

Commit

Permalink
Ensure bindgen gets all the cppflags it needs (on macOS, anyway) (#…
Browse files Browse the repository at this point in the history
…1247)

We should consider doing this on other targets too (I think technically
we would be fine to always do this), but I'd rather not make a big
change like that on the targets people use for production DBs, at least
not without more testing (and possibly a escape hatch to opt out).

This is for #470 and fixes it on macOS, but since the bug was reported
on FreeBSD too, I'm not sure we should close it until it's done more
broadly.
  • Loading branch information
thomcc committed Aug 10, 2023
1 parent c1ff12b commit d1c253f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pgrx-pg-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,14 +885,18 @@ fn extra_bindgen_clang_args(pg_config: &PgConfig) -> eyre::Result<Vec<String>> {
// `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();
// Find the `-isysroot` flags -- The rest are `-I` flags that don't seem
// to be needed inside the code (and feel likely to cause bindgen to
// emit bindings for unrelated libraries)
// 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.
for pair in flags.windows(2) {
if pair[0] == "-isysroot" {
if std::path::Path::new(&pair[1]).exists() {
out.extend(pair.into_iter().cloned());
} else {
if !std::path::Path::new(&pair[1]).exists() {
// The SDK path doesn't exist. Emit a warning, which they'll
// see if the build ends up failing (it may not fail in all
// cases, so we don't panic here).
Expand Down

0 comments on commit d1c253f

Please sign in to comment.