diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f2310ed --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "aom-sys/data/aom"] + path = aom-sys/data/aom + url = https://aomedia.googlesource.com/aom diff --git a/Cargo.toml b/Cargo.toml index 0aebf2a..dd74a4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ keywords = ["libaom","av1"] [features] default = ["codec-trait"] codec-trait = ["av-codec"] +build = ["aom-sys/build"] [dependencies] aom-sys = { version = "0.1.0", path = "aom-sys" } diff --git a/README.md b/README.md index a43638d..a7ddf7b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,9 @@ It is a simple [binding][1] and safe abstraction over [libaom][2]. ## Building -The bindings are generated using the headers and libraries that ought to be present in the system. +By default the bindings are generated using the headers and libraries that ought to be present in the system. + +The `build` feature is available to automatically fetch and build [libaom][2]. ## TODO - [x] Simple bindings diff --git a/aom-sys/Cargo.toml b/aom-sys/Cargo.toml index 5b882c6..d0ff258 100644 --- a/aom-sys/Cargo.toml +++ b/aom-sys/Cargo.toml @@ -8,9 +8,13 @@ repository = "https://github.com/rust-av/aom-rs" build = "build.rs" +[features] +build = ["cmake"] + [build-dependencies] bindgen = "0.30" metadeps = "1.1" +cmake = { version = "0.1.29", optional = true } [package.metadata.pkg-config] aom = "0.1.0" diff --git a/aom-sys/build.rs b/aom-sys/build.rs index 61ee744..3cd4086 100644 --- a/aom-sys/build.rs +++ b/aom-sys/build.rs @@ -1,6 +1,9 @@ extern crate bindgen; extern crate metadeps; +#[cfg(feature="build")] +extern crate cmake; + use std::fs::OpenOptions; use std::io::Write; @@ -30,7 +33,36 @@ fn common_builder() -> bindgen::Builder { .raw_line("#![allow(non_upper_case_globals)]") } + +#[cfg(feature="build")] +fn build_sources() { + use cmake::Config; + use std::env; + use std::path::Path; + use std::process::Command; + + let build_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + + Command::new("git") + .args(&["submodule", "update", "--recommend-shallow", "--init"]) + .spawn() + .expect("Update failed"); + + let build_path = Path::new(&build_dir).join("data/aom"); + + let cfg = Config::new(build_path).build(); + + env::set_var("PKG_CONFIG_PATH", cfg.join("lib/pkgconfig")); +} + +#[cfg(not(feature="build"))] +fn build_sources() {} + fn main() { + if cfg!(feature="build") { + build_sources() + } + let libs = metadeps::probe().unwrap(); let headers = libs.get("aom").unwrap().include_paths.clone(); // let buildver = libs.get("vpx").unwrap().version.split(".").nth(1).unwrap(); diff --git a/aom-sys/data/aom b/aom-sys/data/aom new file mode 160000 index 0000000..efec52a --- /dev/null +++ b/aom-sys/data/aom @@ -0,0 +1 @@ +Subproject commit efec52a713b48e058d8df6a579de51309d0a2ee5