From ad2673327a52668440a068f31662bde266832fc0 Mon Sep 17 00:00:00 2001 From: Daniel Dulaney Date: Sat, 30 Nov 2019 01:07:33 -0500 Subject: [PATCH] build: upgrade bindgen to 0.51.1 The preivous bindgen version (0.32.0) fails on Rust 1.39 (see https://github.com/rust-lang/rust-bindgen/pull/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. --- Cargo.toml | 2 +- build.rs | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 819cd796..b8cead7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ libc = "0.2" num_cpus = "1.0" cc = "1.0" pkg-config = "0.3" -bindgen = "0.51" +bindgen = "0.51.1" regex = "0.2" [features] diff --git a/build.rs b/build.rs index bee2303f..cadf7d14 100644 --- a/build.rs +++ b/build.rs @@ -102,13 +102,17 @@ impl ParseCallbacks for IntCallbacks { } } - // https://github.com/servo/rust-bindgen/issues/687 - // Original fix is broken with bindgen 0.51 and linux 5.2 + // https://github.com/rust-lang/rust-bindgen/issues/687#issuecomment-388277405 fn will_parse_macro(&self, name: &str) -> MacroParsingBehavior { - if name.starts_with("FP_") { - MacroParsingBehavior::Ignore - } else { - MacroParsingBehavior::Default + use MacroParsingBehavior::*; + + match name { + "FP_INFINITE" => Ignore, + "FP_NAN" => Ignore, + "FP_NORMAL" => Ignore, + "FP_SUBNORMAL" => Ignore, + "FP_ZERO" => Ignore, + _ => Default, } } } @@ -935,12 +939,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("*")