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
[features]
repl = ["rustyline"]
decode_test = ["bindgen"]
comparative_bench = []
decode_test = ["bindgen"]
[dependencies]
bitstream-io = "0.6"
......@@ -22,9 +22,10 @@ enum-iterator-derive = "0.1.1"
backtrace = "0.3"
[build-dependencies]
cc = "1"
cmake = "0.1.29"
pkg-config = "0.3.9"
cmake = "0.1.32"
[target.'cfg(unix)'.build-dependencies]
pkg-config = "0.3.12"
bindgen = { version = "0.37", optional = true }
[dev-dependencies]
......
......@@ -28,12 +28,14 @@ git submodule update --init
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
Input videos must be 8-bit 4:2:0, in y4m format.
......
// build.rs
extern crate cmake;
extern crate cc;
#[cfg(unix)]
extern crate pkg_config;
#[cfg(unix)]
#[cfg(feature = "decode_test")]
extern crate bindgen;
use std::env;
use std::path::Path;
use std::fs;
use std::path::Path;
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 build_path = Path::new(&cargo_dir).join("aom_build/aom");
let debug = if let Some(v) = env::var("PROFILE").ok() {
match v.as_str() {
"bench" | "release" => "0",
_ => "1",
"bench" | "release" => false,
_ => true,
}
} else {
"0"
false
};
let dst = cmake::Config::new(build_path)
.define("CONFIG_DEBUG", debug)
.define("CONFIG_DEBUG", (debug as u8).to_string())
.define("CONFIG_ANALYZER", "0")
.define("ENABLE_DOCS", "0")
.define("CONFIG_UNIT_TESTS", "0")
.define("ENABLE_TESTS", "0")
.no_build_target(cfg!(windows))
.build();
// Dirty hack to force a rebuild whenever the defaults are changed upstream
let _ = fs::remove_file(dst.join("build/CMakeCache.txt"));
env::set_var("PKG_CONFIG_PATH", dst.join("lib/pkgconfig"));
let _libs = pkg_config::Config::new().statik(true).probe("aom").unwrap();
#[cfg(windows)] {
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")] {
use std::io::Write;
#[cfg(feature = "decode_test")] {
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()
.blacklist_type("max_align_t")
.rustfmt_bindings(false)
.header("data/aom.h");
let mut builder = bindgen::builder()
.blacklist_type("max_align_t")
.rustfmt_bindings(false)
.header("data/aom.h");
for header in headers {
builder = builder.clang_arg("-I").clang_arg(header.to_str().unwrap());
}
for header in headers {
builder = builder.clang_arg("-I").clang_arg(header.to_str().unwrap());
}
// Manually fix the comment so rustdoc won't try to pick them
let s = builder
.generate()
.unwrap()
.to_string()
.replace("/**", "/*")
.replace("/*!", "/*");
// Manually fix the comment so rustdoc won't try to pick them
let s = builder
.generate()
.unwrap()
.to_string()
.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());
}
}
{
use std::fs;
fn rerun_dir<P: AsRef<Path>>(dir: P) {
for entry in fs::read_dir(dir).unwrap() {
let entry = entry.unwrap();
let path = entry.path();
println!("cargo:rerun-if-changed={}", path.to_string_lossy());
if path.is_dir() {
rerun_dir(path);
}
fn rerun_dir<P: AsRef<Path>>(dir: P) {
for entry in fs::read_dir(dir).unwrap() {
let entry = entry.unwrap();
let path = entry.path();
println!("cargo:rerun-if-changed={}", path.to_string_lossy());
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