Skip to content

Commit

Permalink
build: upgrade bindgen to 0.51.1
Browse files Browse the repository at this point in the history
The preivous bindgen version (0.32.0) fails on Rust 1.39 (see
rust-lang/rust-bindgen#1627), so an upgrade is
needed.

However, the new version also breaks when enum values are also defined as
macros. Previously, this could be handled with blacklist_type, but the
recommended method is by implementing will_parse_macro and returning
Ignore for problematic enum variants. This commit implements that method
and removes the old method.
  • Loading branch information
Daniel Dulaney authored and meh committed Dec 5, 2019
1 parent bb947ef commit 427594e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ffmpeg-sys/Cargo.toml
Expand Up @@ -18,7 +18,7 @@ libc = "0.2"
num_cpus = "1.0"
cc = "1.0"
pkg-config = "0.3"
bindgen = "0.32"
bindgen = "0.51.1"
regex = "0.2"

[features]
Expand Down
22 changes: 15 additions & 7 deletions ffmpeg-sys/build.rs
Expand Up @@ -12,7 +12,7 @@ use std::process::Command;
use std::str;

use regex::Regex;
use bindgen::callbacks::{IntKind, ParseCallbacks};
use bindgen::callbacks::{IntKind, ParseCallbacks, MacroParsingBehavior};

#[derive(Debug)]
struct Library {
Expand Down Expand Up @@ -71,6 +71,20 @@ impl ParseCallbacks for IntCallbacks {
None
}
}

// https://github.com/rust-lang/rust-bindgen/issues/687#issuecomment-388277405
fn will_parse_macro(&self, name: &str) -> MacroParsingBehavior {
use MacroParsingBehavior::*;

match name {
"FP_INFINITE" => Ignore,
"FP_NAN" => Ignore,
"FP_NORMAL" => Ignore,
"FP_SUBNORMAL" => Ignore,
"FP_ZERO" => Ignore,
_ => Default,
}
}
}

fn version() -> String {
Expand Down Expand Up @@ -902,12 +916,6 @@ fn main() {
let mut builder = bindgen::Builder::default()
.clang_args(clang_includes)
.ctypes_prefix("libc")
// https://github.com/servo/rust-bindgen/issues/687
.blacklist_type("FP_NAN")
.blacklist_type("FP_INFINITE")
.blacklist_type("FP_ZERO")
.blacklist_type("FP_SUBNORMAL")
.blacklist_type("FP_NORMAL")
// https://github.com/servo/rust-bindgen/issues/550
.blacklist_type("max_align_t")
.rustified_enum("*")
Expand Down

0 comments on commit 427594e

Please sign in to comment.