Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure bindgen gets the cppflags even if we aren't using macOS #1336

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions pgrx-pg-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,24 +885,20 @@ fn build_shim_for_version(

fn extra_bindgen_clang_args(pg_config: &PgConfig) -> eyre::Result<Vec<String>> {
let mut out = vec![];
let flags = shlex::split(&pg_config.cppflags()?.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() {
Expand Down
Loading