Skip to content

Commit

Permalink
Initial support for building libaom
Browse files Browse the repository at this point in the history
It relies on a git submodule to fetch the sources.

Issue #2.
  • Loading branch information
lu-zero committed Feb 26, 2018
1 parent 82bef68 commit fb155c9
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "aom-sys/data/aom"]
path = aom-sys/data/aom
url = https://aomedia.googlesource.com/aom
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions aom-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
32 changes: 32 additions & 0 deletions aom-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
extern crate bindgen;
extern crate metadeps;

#[cfg(feature="build")]
extern crate cmake;

use std::fs::OpenOptions;
use std::io::Write;

Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions aom-sys/data/aom
Submodule aom added at efec52

0 comments on commit fb155c9

Please sign in to comment.