Skip to content
Merged
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
39 changes: 34 additions & 5 deletions pg-extend/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

extern crate bindgen;

use std::collections::HashSet;
use std::env;
use std::path::PathBuf;

fn main() {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap())
.join("postgres.rs");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("postgres.rs");

if !out_path.exists() {
let pg_include = env::var("PG_INCLUDE_PATH")
Expand All @@ -27,17 +27,33 @@ fn main() {
// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.

let ignored_macros = IgnoreMacros(
vec![
"FP_INFINITE".into(),
"FP_NAN".into(),
"FP_NORMAL".into(),
"FP_SUBNORMAL".into(),
"FP_ZERO".into(),
"IPPORT_RESERVED".into(),
]
.into_iter()
.collect(),
);

let bindings = bindgen::Builder::default()
.clang_arg(format!("-I{}",pg_include))
.clang_arg(format!("-I{}", pg_include))
// The input header we would like to generate
// bindings for.
.header("wrapper.h")
.parse_callbacks(Box::new(ignored_macros))
.rustfmt_bindings(true)
// FIXME: add this back
.layout_tests(false);

// Finish the builder and generate the bindings.
let bindings = bindings.generate()
// Finish the builder and generate the bindings.
let bindings = bindings
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");

Expand All @@ -47,3 +63,16 @@ fn main() {
.expect("Couldn't write bindings!");
}
}

#[derive(Debug)]
struct IgnoreMacros(HashSet<String>);

impl bindgen::callbacks::ParseCallbacks for IgnoreMacros {
fn will_parse_macro(&self, name: &str) -> bindgen::callbacks::MacroParsingBehavior {
if self.0.contains(name) {
bindgen::callbacks::MacroParsingBehavior::Ignore
} else {
bindgen::callbacks::MacroParsingBehavior::Default
}
}
}