Skip to content

Commit

Permalink
rust: fix build on nixos
Browse files Browse the repository at this point in the history
Running into these issues: rust-lang/rust-bindgen#687

Signed-off-by: William Casarin <jb55@jb55.com>
  • Loading branch information
jb55 committed Jul 7, 2022
1 parent 1d453b6 commit 5080a33
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@ extern crate bindgen;
use std::env;
use std::path::PathBuf;

fn main() {
#[derive(Debug)]
struct IgnoreMacros(String);

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

fn main() {
// Tell cargo to look for shared libraries in the specified directory
let lib_path = PathBuf::from(env::current_dir().unwrap());
println!("cargo:rustc-link-search={}", lib_path.display());
Expand All @@ -14,6 +26,8 @@ fn main() {
println!("cargo:rustc-link-lib=secp256k1");
println!("cargo:rustc-link-lib=sodium");

let ignored_macros = IgnoreMacros("IPPORT_RESERVED".to_string());

// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
Expand All @@ -25,6 +39,7 @@ fn main() {
.clang_arg("-Ideps/secp256k1/include")
.clang_arg("-Ideps/libsodium/src/libsodium/include")
.header("deps/secp256k1/include/secp256k1.h")
.parse_callbacks(Box::new(ignored_macros))
.trust_clang_mangling(false)
// Finish the builder and generate the bindings.
.generate()
Expand Down

0 comments on commit 5080a33

Please sign in to comment.