This repository has been archived by the owner on Jan 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.rs
73 lines (61 loc) · 2.22 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
#[cfg(target_os = "macos")]
use std::os::unix::fs::PermissionsExt;
#[cfg(feature = "docs-rs")]
fn main() {}
#[cfg(not(feature = "docs-rs"))]
fn main() {
let output = std::process::Command::new(std::env::var("LLVM_CONFIG").unwrap_or_else(|_| {
std::env::var("DEP_LLVM_CONFIG_PATH").unwrap_or_else(|_| "llvm-config".to_string())
}))
.arg("--libdir")
.output()
.unwrap()
.stdout;
#[cfg(not(target_os = "macos"))]
let shared_lib = "so";
#[cfg(target_os = "macos")]
let shared_lib = "dylib";
let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
let libdir = std::path::PathBuf::from(String::from_utf8(output).unwrap().trim());
// Copy LTO lib
let lto_file_name = format!("libLTO.{}", shared_lib);
let lto = libdir.join(<o_file_name);
let out_file = out_dir.join(<o_file_name);
if !out_file.exists() {
std::fs::copy(<o, &out_file).unwrap();
}
#[cfg(target_os = "macos")]
{
let meta = std::fs::metadata(&out_file).unwrap();
let mut permissions = meta.permissions();
permissions.set_mode(0o755);
std::fs::set_permissions(&out_file, permissions).unwrap();
}
#[cfg(not(target_os = "macos"))]
{
if let Ok(lto_full) = std::fs::read_link(<o) {
let out_file = out_dir.join(lto_full.file_name().unwrap());
if !out_file.exists() {
std::fs::copy(libdir.join(<o_full), out_file).unwrap();
}
}
}
// Copy LLVM lib
let llvm_file_name = format!("libLLVM.{}", shared_lib);
let out_file = out_dir.join(&llvm_file_name);
println!("FILENAME: {}", llvm_file_name);
println!("LIBDIR: {}", libdir.display());
if !out_file.exists() {
std::fs::copy(libdir.join(&llvm_file_name), &out_file).unwrap();
}
#[cfg(target_os = "macos")]
{
let meta = std::fs::metadata(&out_file).unwrap();
let mut permissions = meta.permissions();
permissions.set_mode(0o755);
std::fs::set_permissions(&out_file, permissions).unwrap();
}
println!("cargo:rustc-link-search=native={}", out_dir.display());
println!("cargo:rustc-link-lib=LLVM");
println!("cargo:rustc-link-lib=LTO");
}