-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
45 lines (40 loc) · 1.39 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
extern crate cmake;
/// Determines if the current compilation mode is "debug".
fn is_debug() -> bool {
if let Ok(opt_level) = std::env::var("OPT_LEVEL") {
opt_level != "3"
} else {
println!("cargo:warning=`OPT_LEVEL` environment variable not found");
true
}
}
/// Hints cargo about the rerun rules to apply.
fn send_rerun_rules() {
println!("cargo:rerun-if-changed=bartleby/");
println!("cargo:rerun-if-changed=CMakeLists.txt");
println!("cargo:rerun-if-env-changed=OPT_LEVEL");
println!("cargo:rerun-if-env-changed=LLVM_DIR");
println!("cargo:rerun-if-env-changed=build.rs");
}
fn main() {
send_rerun_rules();
let llvm_dir = std::env::var("LLVM_DIR").expect("`LLVM_DIR`");
let mut cmake_cmd = cmake::Config::new(".");
cmake_cmd
.define(
"CMAKE_BUILD_TYPE",
if is_debug() { "Debug" } else { "Release" },
)
.define("LLVM_DIR", llvm_dir)
.build_arg(format!(
"-j{}",
std::env::var("NUM_JOBS").unwrap_or("1".into())
));
if let Ok(ver) = std::env::var("BARTLEBY_LLVM_VERSION") {
cmake_cmd.define("BARTLEBY_LLVM_VERSION", ver);
}
let dst = cmake_cmd.build();
println!("cargo:rustc-link-search=native={}/lib", dst.display());
println!("cargo:rustc-link-lib=static=Bartleby");
println!("cargo:rustc-link-lib=static=Bartleby-c");
}