-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.rs
73 lines (64 loc) · 2.23 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
extern crate pkg_config;
extern crate submodules;
extern crate cmake;
use std::io::{BufRead, BufReader};
use std::fs::File;
use std::env;
fn parse_cubeb_cache(cache: String) -> String {
let file = File::open(cache.clone()).unwrap_or_else(|e| {
panic!("Failed to open {}: {}", cache, e);
});
let mut reader = BufReader::new(file);
let mut line = String::new();
let mut flags = String::new();
while reader.read_line(&mut line).unwrap() > 0 {
{
if line.contains("USE_ALSA:INTERNAL=1") {
flags.push_str("cargo:rustc-link-lib=asound\n");
}
else if line.contains("USE_AUDIOUNIT:INTERNAL=1") {
flags.push_str("cargo:rustc-link-lib=framework=AudioUnit\n");
}
else if line.contains("USE_JACK:INTERNAL=1") {
flags.push_str("cargo:rustc-link-lib=jack\n");
}
else if line.contains("USE_OPENSL:INTERNAL=1") {
flags.push_str("cargo:rustc-link-lib=OpenSLES\n");
}
else if line.contains("USE_PULSE:INTERNAL=1") {
flags.push_str("cargo:rustc-link-lib=pulse\n");
}
else if line.contains("USE_SNDIO:INTERNAL=1") {
flags.push_str("cargo:rustc-link-lib=sndio\n");
}
else if line.contains("USE_WINMM:INTERNAL=1") {
flags.push_str("cargo:rustc-link-lib=winmm\n");
}
}
line.clear();
};
flags
}
fn main()
{
let build_cubeb = env::var("CARGO_FEATURE_BUILD_CUBEB").is_ok();
let target = env::var("TARGET").unwrap();
let host = env::var("HOST").unwrap();
if !build_cubeb {
if target != host {
panic!("For cross-builds use the 'build-cubeb' feature.");
} else if !pkg_config::Config::new().find("cubeb").is_ok() {
panic!("Missing libcubeb. Install it manually or build cult with \
'--features build-cubeb'.");
}
/* if using a pre-existing libcubeb, just link against it dynamically */
println!("cargo:rustc-link-lib=dylib=cubeb");
return
}
submodules::update().init().recursive().run();
let dst = cmake::build("cubeb");
println!("cargo:rustc-link-search=native={}", dst.display());
println!("cargo:rustc-link-lib=static=cubeb");
println!("cargo:rustc-flags=-l dylib=stdc++");
print!("{}", parse_cubeb_cache(format!("{}/build/CMakeCache.txt", dst.display())));
}