forked from rust-lang/rust-bindgen
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.rs
94 lines (84 loc) · 2.85 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#![feature(path_ext)]
use std::env;
use std::fs::PathExt;
use std::path::Path;
const LINUX_CLANG_DIRS: &'static [&'static str] = &["/usr/lib", "/usr/lib/llvm", "/usr/lib64/llvm"];
const MAC_CLANG_DIR: &'static str = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib";
fn main() {
let use_static_lib = env::var_os("LIBCLANG_STATIC").is_some() || cfg!(feature = "static");
let possible_clang_dirs = if let Ok(dir) = env::var("LIBCLANG_PATH") {
vec![dir]
} else if cfg!(any(target_os = "linux", target_os = "freebsd")) {
LINUX_CLANG_DIRS.iter().map(ToString::to_string).collect()
} else if cfg!(target_os = "macos") {
vec![MAC_CLANG_DIR.to_string()]
} else {
panic!("Platform not supported");
};
let clang_lib = format!("{}clang{}", env::consts::DLL_PREFIX, env::consts::DLL_SUFFIX);
let maybe_clang_dir = possible_clang_dirs.iter().filter_map(|candidate_dir| {
let clang_dir = Path::new(candidate_dir);
let clang_path = clang_dir.join(clang_lib.clone());
if clang_path.exists() {
Some(clang_dir)
} else {
None
}
}).next();
macro_rules! qw {
($($i:ident)*) => (vec!($(stringify!($i)),*));
}
if let Some(clang_dir) = maybe_clang_dir {
if use_static_lib {
let libs = qw![
LLVMAnalysis
LLVMBitReader
LLVMCore
LLVMLTO
LLVMLinker
LLVMMC
LLVMMCParser
LLVMObjCARCOpts
LLVMObject
LLVMOption
LLVMScalarOpts
LLVMSupport
LLVMTarget
LLVMTransformUtils
LLVMVectorize
LLVMipa
LLVMipo
clang
clangARCMigrate
clangAST
clangASTMatchers
clangAnalysis
clangBasic
clangDriver
clangEdit
clangFormat
clangFrontend
clangIndex
clangLex
clangParse
clangRewrite
clangRewriteFrontend
clangSema
clangSerialization
clangStaticAnalyzerCheckers
clangStaticAnalyzerCore
clangStaticAnalyzerFrontend
clangTooling
];
print!("cargo:rustc-flags=");
for lib in libs {
print!("-l static={} ", lib);
}
println!("-L {} -l ncursesw -l z -l stdc++", clang_dir.to_str().unwrap());
} else{
println!("cargo:rustc-flags=-l clang -L {}", clang_dir.to_str().unwrap());
}
} else {
panic!("Unable to find {}", clang_lib);
}
}