forked from xiph/rav1e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
123 lines (102 loc) · 4.03 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// build.rs
extern crate cmake;
#[cfg(unix)]
extern crate pkg_config;
#[cfg(unix)]
#[cfg(feature = "decode_test")]
extern crate bindgen;
#[cfg(target_arch = "x86_64")]
extern crate nasm_rs;
use std::env;
use std::fs;
use std::path::Path;
fn main() {
#[cfg(all(target_arch = "x86_64", not(windows)))] {
use std::fs::File;
use std::io::Write;
let out_dir = env::var("OUT_DIR").unwrap();
{
let dest_path = Path::new(&out_dir).join("config.asm");
let mut config_file = File::create(dest_path).unwrap();
config_file.write(b" %define private_prefix rav1e\n").unwrap();
config_file.write(b" %define ARCH_X86_32 0\n").unwrap();
config_file.write(b" %define ARCH_X86_64 1\n").unwrap();
config_file.write(b" %define PIC 1\n").unwrap();
config_file.write(b" %define STACK_ALIGNMENT 32\n").unwrap();
if cfg!(target_os="macos") {
config_file.write(b" %define PREFIX 1\n").unwrap();
}
}
let mut config_include_arg = String::from("-I");
config_include_arg.push_str(&out_dir);
config_include_arg.push('/');
nasm_rs::compile_library_args("rav1easm", &["src/x86/ipred.asm"], &[&config_include_arg, "-Isrc/"]);
println!("cargo:rustc-link-lib=static=rav1easm");
}
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" => false,
_ => true,
}
} else {
false
};
let dst = cmake::Config::new(build_path)
.define("CONFIG_DEBUG", (debug as u8).to_string())
.define("CONFIG_ANALYZER", "0")
.define("ENABLE_DOCS", "0")
.define("ENABLE_NASM", "1")
.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"));
#[cfg(windows)] {
println!("cargo:rustc-link-search=native={}", dst.join("build").to_str().unwrap());
println!("cargo:rustc-link-search=native={}", dst.join("build/Debug").to_str().unwrap());
println!("cargo:rustc-link-search=native={}", dst.join("build/Release").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;
let out_dir = env::var("OUT_DIR").unwrap();
let headers = _libs.include_paths.clone();
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());
}
// 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 mut file = fs::File::create(dest_path).unwrap();
let _ = file.write(s.as_bytes());
}
}
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");
}