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

Updated bindgen to be able to build this with rust version 1.39 #79

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ keywords = ["audio", "video"]
libc = "0.2"

[build-dependencies]
num_cpus = "1.0"
num_cpus = "1.11"
cc = "1.0"
pkg-config = "0.3"
bindgen = "0.32"
bindgen = "0.51.0"
regex = "0.2"

[features]
Expand Down
59 changes: 38 additions & 21 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,14 @@ fn search() -> PathBuf {
}

fn fetch() -> io::Result<()> {
let status = try!(
Command::new("git")
let status = Command::new("git")
.current_dir(&output())
.arg("clone")
.arg("-b")
.arg(format!("release/{}", version()))
.arg("https://github.com/FFmpeg/FFmpeg")
.arg(format!("ffmpeg-{}", version()))
.status()
);
.status()?;

if status.success() {
Ok(())
Expand Down Expand Up @@ -267,24 +265,20 @@ fn build() -> io::Result<()> {
}

// run make
if !try!(
Command::new("make")
if Command::new("make")
.arg("-j")
.arg(num_cpus::get().to_string())
.current_dir(&source())
.status()
).success()
.status()?.success()
{
return Err(io::Error::new(io::ErrorKind::Other, "make failed"));
}

// run make install
if !try!(
Command::new("make")
if Command::new("make")
.current_dir(&source())
.arg("install")
.status()
).success()
.status()?.success()
{
return Err(io::Error::new(io::ErrorKind::Other, "make install failed"));
}
Expand Down Expand Up @@ -896,24 +890,34 @@ fn main() {
.iter()
.map(|include| format!("-I{}", include.to_string_lossy()));

// https://github.com/servo/rust-bindgen/issues/687
let ignored_macros = IgnoreMacros(
vec![
"FP_INFINITE".into(),
"FP_NAN".into(),
"FP_NORMAL".into(),
"FP_SUBNORMAL".into(),
"FP_ZERO".into(),
"IPPORT_RESERVED".into(),
// https://github.com/servo/rust-bindgen/issues/550
"max_align_t".into(),
]
.into_iter()
.collect(),
);

// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
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("*")
.prepend_enum_name(false)
.derive_eq(true)
.parse_callbacks(Box::new(IntCallbacks));
.parse_callbacks(Box::new(IntCallbacks))
.parse_callbacks(Box::new(ignored_macros))
;

// The input headers we would like to generate
// bindings for.
Expand Down Expand Up @@ -1022,3 +1026,16 @@ fn main() {
.write_to_file(output().join("bindings.rs"))
.expect("Couldn't write bindings!");
}

#[derive(Debug)]
struct IgnoreMacros(std::collections::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
}
}
}
4 changes: 2 additions & 2 deletions src/avutil/rational.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use AVRational;
use libc::{c_double, c_int, int64_t};
use libc::{c_double, c_int};

#[inline(always)]
pub unsafe fn av_make_q(num: c_int, den: c_int) -> AVRational {
Expand All @@ -8,7 +8,7 @@ pub unsafe fn av_make_q(num: c_int, den: c_int) -> AVRational {

#[inline(always)]
pub unsafe fn av_cmp_q(a: AVRational, b: AVRational) -> c_int {
let tmp: int64_t = i64::from(a.num) * i64::from(b.den) - i64::from(b.num) * i64::from(a.den);
let tmp: i64 = i64::from(a.num) * i64::from(b.den) - i64::from(b.num) * i64::from(a.den);

if tmp != 0 {
(((tmp ^ i64::from(a.den) ^ i64::from(b.den)) >> 63) | 1) as c_int
Expand Down
4 changes: 2 additions & 2 deletions src/avutil/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use libc::{c_int, int64_t};
use libc::{c_int};
use {AVRational, AV_TIME_BASE};

pub const AV_NOPTS_VALUE: int64_t = 0x8000000000000000u64 as int64_t;
pub const AV_NOPTS_VALUE: i64 = 0x8000000000000000u64 as i64;
pub const AV_TIME_BASE_Q: AVRational = AVRational {
num: 1,
den: AV_TIME_BASE as c_int,
Expand Down