Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.

Commit 716cc64

Browse files
Daniel Dulaneymeh
Daniel Dulaney
authored andcommitted
build: upgrade bindgen to 0.51.1
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.
1 parent 4f14151 commit 716cc64

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ libc = "0.2"
1818
num_cpus = "1.0"
1919
cc = "1.0"
2020
pkg-config = "0.3"
21-
bindgen = "0.32"
21+
bindgen = "0.51.1"
2222
regex = "0.2"
2323

2424
[features]

build.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::process::Command;
1212
use std::str;
1313

1414
use regex::Regex;
15-
use bindgen::callbacks::{IntKind, ParseCallbacks};
15+
use bindgen::callbacks::{IntKind, ParseCallbacks, MacroParsingBehavior};
1616

1717
#[derive(Debug)]
1818
struct Library {
@@ -71,6 +71,20 @@ impl ParseCallbacks for IntCallbacks {
7171
None
7272
}
7373
}
74+
75+
// https://github.com/rust-lang/rust-bindgen/issues/687#issuecomment-388277405
76+
fn will_parse_macro(&self, name: &str) -> MacroParsingBehavior {
77+
use MacroParsingBehavior::*;
78+
79+
match name {
80+
"FP_INFINITE" => Ignore,
81+
"FP_NAN" => Ignore,
82+
"FP_NORMAL" => Ignore,
83+
"FP_SUBNORMAL" => Ignore,
84+
"FP_ZERO" => Ignore,
85+
_ => Default,
86+
}
87+
}
7488
}
7589

7690
fn version() -> String {
@@ -902,12 +916,6 @@ fn main() {
902916
let mut builder = bindgen::Builder::default()
903917
.clang_args(clang_includes)
904918
.ctypes_prefix("libc")
905-
// https://github.com/servo/rust-bindgen/issues/687
906-
.blacklist_type("FP_NAN")
907-
.blacklist_type("FP_INFINITE")
908-
.blacklist_type("FP_ZERO")
909-
.blacklist_type("FP_SUBNORMAL")
910-
.blacklist_type("FP_NORMAL")
911919
// https://github.com/servo/rust-bindgen/issues/550
912920
.blacklist_type("max_align_t")
913921
.rustified_enum("*")

0 commit comments

Comments
 (0)