forked from benfred/remoteprocess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
41 lines (38 loc) · 2.13 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
use std::env;
fn main() {
// We only support native unwinding on some platforms
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
match target_arch.as_str() {
"x86_64" | "arm" => {}
_ => return,
};
let target = env::var("TARGET").unwrap();
match env::var("CARGO_CFG_TARGET_OS").unwrap().as_ref() {
"linux" => {
// statically link libunwind if compiling for musl, dynamically link otherwise
if env::var("CARGO_FEATURE_UNWIND").is_ok() {
println!("cargo:rustc-cfg=use_libunwind");
if env::var("CARGO_CFG_TARGET_ENV").unwrap() == "musl"
&& env::var("CARGO_CFG_TARGET_VENDOR").unwrap() != "alpine"
{
println!("cargo:rustc-link-search=native=/usr/local/lib");
let out_dir = env::var("OUT_DIR").unwrap();
std::fs::copy(format!("/usr/local/musl/{}/lib/libunwind.a", target), format!("{}/libunwind-remoteprocess.a", out_dir)).unwrap();
std::fs::copy(format!("/usr/local/musl/{}/lib/libunwind-ptrace.a", target), format!("{}/libunwind-ptrace.a", out_dir)).unwrap();
std::fs::copy(format!("/usr/local/musl/{}/lib/libunwind-{}.a", target, target_arch), format!("{}/libunwind-{}.a", out_dir, target_arch)).unwrap();
std::fs::copy(format!("/usr/local/musl/{}/lib/libz.a", target), format!("{}/libz.a", out_dir)).unwrap();
println!("cargo:rustc-link-search=native={}", out_dir);
println!("cargo:rustc-link-lib=static=unwind-remoteprocess");
println!("cargo:rustc-link-lib=static=unwind-ptrace");
println!("cargo:rustc-link-lib=static=unwind-{}", target_arch);
println!("cargo:rustc-link-lib=static=z");
} else {
println!("cargo:rustc-link-lib=dylib=unwind");
println!("cargo:rustc-link-lib=dylib=unwind-ptrace");
println!("cargo:rustc-link-lib=dylib=unwind-{}", target_arch);
}
}
}
_ => {}
}
}