-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathbuild.rs
47 lines (41 loc) · 1.4 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
extern crate cc;
extern crate pkg_config;
use std::path::PathBuf;
use std::{env, fs};
fn main() {
let mut cfg = cc::Build::new();
let target = env::var("TARGET").unwrap();
cfg.warnings(false);
if target.contains("windows") {
cfg.define("_WIN32", None);
cfg.define("BZ_EXPORT", None);
} else if !cfg!(feature = "static") {
// pkg-config doesn't guarantee static link
if pkg_config::Config::new()
.cargo_metadata(true)
.probe("bzip2")
.is_ok()
{
return;
}
}
let dst = PathBuf::from(env::var_os("OUT_DIR").unwrap());
cfg.include("bzip2-1.0.8")
.define("_FILE_OFFSET_BITS", Some("64"))
.define("BZ_NO_STDIO", None)
.file("bzip2-1.0.8/blocksort.c")
.file("bzip2-1.0.8/huffman.c")
.file("bzip2-1.0.8/crctable.c")
.file("bzip2-1.0.8/randtable.c")
.file("bzip2-1.0.8/compress.c")
.file("bzip2-1.0.8/decompress.c")
.file("bzip2-1.0.8/bzlib.c")
.out_dir(dst.join("lib"))
.compile("libbz2.a");
let src = env::current_dir().unwrap().join("bzip2-1.0.8");
let include = dst.join("include");
fs::create_dir_all(&include).unwrap();
fs::copy(src.join("bzlib.h"), dst.join("include/bzlib.h")).unwrap();
println!("cargo:root={}", dst.display());
println!("cargo:include={}", dst.join("include").display());
}