Unverified Commit c0638c83 authored by Raphael Zumer's avatar Raphael Zumer Committed by GitHub

Support build on Windows (#420)

* Document pkg-config dependency

* Document dependencies on Windows

* Support build on Windows
parent 4003c39d
...@@ -8,8 +8,8 @@ autobenches = false ...@@ -8,8 +8,8 @@ autobenches = false
[features] [features]
repl = ["rustyline"] repl = ["rustyline"]
decode_test = ["bindgen"]
comparative_bench = [] comparative_bench = []
decode_test = ["bindgen"]
[dependencies] [dependencies]
bitstream-io = "0.6" bitstream-io = "0.6"
...@@ -22,9 +22,10 @@ enum-iterator-derive = "0.1.1" ...@@ -22,9 +22,10 @@ enum-iterator-derive = "0.1.1"
backtrace = "0.3" backtrace = "0.3"
[build-dependencies] [build-dependencies]
cc = "1" cmake = "0.1.32"
cmake = "0.1.29"
pkg-config = "0.3.9" [target.'cfg(unix)'.build-dependencies]
pkg-config = "0.3.12"
bindgen = { version = "0.37", optional = true } bindgen = { version = "0.37", optional = true }
[dev-dependencies] [dev-dependencies]
......
...@@ -28,12 +28,14 @@ git submodule update --init ...@@ -28,12 +28,14 @@ git submodule update --init
This is also required every time you switch branches or pull a submodule change. This is also required every time you switch branches or pull a submodule change.
In order to build the codec, you need perl, yasm and cmake. To install this on Ubuntu or Linux Mint, run: In order to build and link to the codec on UNIX, you need Perl, Yasm, CMake, and pkg-config. To install this on Ubuntu or Linux Mint, run:
``` ```
sudo apt install perl yasm cmake sudo apt install perl yasm cmake pkg-config
``` ```
On Windows, pkg-config is not required. A Perl distribution such as Strawberry Perl, CMake, and a Yasm binary in your system PATH are required.
# Compressing video # Compressing video
Input videos must be 8-bit 4:2:0, in y4m format. Input videos must be 8-bit 4:2:0, in y4m format.
......
// build.rs // build.rs
extern crate cmake; extern crate cmake;
extern crate cc; #[cfg(unix)]
extern crate pkg_config; extern crate pkg_config;
#[cfg(unix)]
#[cfg(feature = "decode_test")] #[cfg(feature = "decode_test")]
extern crate bindgen; extern crate bindgen;
use std::env; use std::env;
use std::path::Path;
use std::fs; use std::fs;
use std::path::Path;
fn main() { fn main() {
if cfg!(windows) && cfg!(feature = "decode_test") {
panic!("Unsupported feature on this platform!");
}
let cargo_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); let cargo_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let build_path = Path::new(&cargo_dir).join("aom_build/aom"); let build_path = Path::new(&cargo_dir).join("aom_build/aom");
let debug = if let Some(v) = env::var("PROFILE").ok() { let debug = if let Some(v) = env::var("PROFILE").ok() {
match v.as_str() { match v.as_str() {
"bench" | "release" => "0", "bench" | "release" => false,
_ => "1", _ => true,
} }
} else { } else {
"0" false
}; };
let dst = cmake::Config::new(build_path) let dst = cmake::Config::new(build_path)
.define("CONFIG_DEBUG", debug) .define("CONFIG_DEBUG", (debug as u8).to_string())
.define("CONFIG_ANALYZER", "0") .define("CONFIG_ANALYZER", "0")
.define("ENABLE_DOCS", "0") .define("ENABLE_DOCS", "0")
.define("CONFIG_UNIT_TESTS", "0") .define("ENABLE_TESTS", "0")
.no_build_target(cfg!(windows))
.build(); .build();
// Dirty hack to force a rebuild whenever the defaults are changed upstream // Dirty hack to force a rebuild whenever the defaults are changed upstream
let _ = fs::remove_file(dst.join("build/CMakeCache.txt")); let _ = fs::remove_file(dst.join("build/CMakeCache.txt"));
env::set_var("PKG_CONFIG_PATH", dst.join("lib/pkgconfig")); #[cfg(windows)] {
let _libs = pkg_config::Config::new().statik(true).probe("aom").unwrap(); let bin_dir = if debug {
"Debug"
} else {
"Release"
};
println!("cargo:rustc-link-search=native={}", dst.join("build").join(bin_dir).to_str().unwrap());
println!("cargo:rustc-link-lib=static=aom");
}
#[cfg(unix)] {
env::set_var("PKG_CONFIG_PATH", dst.join("lib/pkgconfig"));
let _libs = pkg_config::Config::new().statik(true).probe("aom").unwrap();
#[cfg(feature = "decode_test")] { #[cfg(feature = "decode_test")] {
use std::io::Write; use std::io::Write;
let out_dir = env::var("OUT_DIR").unwrap(); let out_dir = env::var("OUT_DIR").unwrap();
let headers = _libs.include_paths.clone(); let headers = _libs.include_paths.clone();
let mut builder = bindgen::builder() let mut builder = bindgen::builder()
.blacklist_type("max_align_t") .blacklist_type("max_align_t")
.rustfmt_bindings(false) .rustfmt_bindings(false)
.header("data/aom.h"); .header("data/aom.h");
for header in headers { for header in headers {
builder = builder.clang_arg("-I").clang_arg(header.to_str().unwrap()); builder = builder.clang_arg("-I").clang_arg(header.to_str().unwrap());
} }
// Manually fix the comment so rustdoc won't try to pick them // Manually fix the comment so rustdoc won't try to pick them
let s = builder let s = builder
.generate() .generate()
.unwrap() .unwrap()
.to_string() .to_string()
.replace("/**", "/*") .replace("/**", "/*")
.replace("/*!", "/*"); .replace("/*!", "/*");
let dest_path = Path::new(&out_dir).join("aom.rs"); let dest_path = Path::new(&out_dir).join("aom.rs");
let mut file = fs::File::create(dest_path).unwrap(); let mut file = fs::File::create(dest_path).unwrap();
let _ = file.write(s.as_bytes()); let _ = file.write(s.as_bytes());
}
} }
{ fn rerun_dir<P: AsRef<Path>>(dir: P) {
use std::fs; for entry in fs::read_dir(dir).unwrap() {
fn rerun_dir<P: AsRef<Path>>(dir: P) { let entry = entry.unwrap();
for entry in fs::read_dir(dir).unwrap() { let path = entry.path();
let entry = entry.unwrap(); println!("cargo:rerun-if-changed={}", path.to_string_lossy());
let path = entry.path();
println!("cargo:rerun-if-changed={}", path.to_string_lossy()); if path.is_dir() {
rerun_dir(path);
if path.is_dir() {
rerun_dir(path);
}
} }
} }
rerun_dir("aom_build");
} }
rerun_dir("aom_build");
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment