-
Notifications
You must be signed in to change notification settings - Fork 12.9k
/
build.rs
83 lines (73 loc) · 2.77 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
//! Compiles the profiler part of the `compiler-rt` library.
//!
//! See the build.rs for libcompiler_builtins crate for details.
use std::env;
use std::path::Path;
fn main() {
let target = env::var("TARGET").expect("TARGET was not set");
let cfg = &mut cc::Build::new();
let mut profile_sources = vec![
"GCDAProfiling.c",
"InstrProfiling.c",
"InstrProfilingBuffer.c",
"InstrProfilingFile.c",
"InstrProfilingMerge.c",
"InstrProfilingMergeFile.c",
"InstrProfilingNameVar.c",
"InstrProfilingPlatformDarwin.c",
"InstrProfilingPlatformLinux.c",
"InstrProfilingPlatformOther.c",
"InstrProfilingPlatformWindows.c",
"InstrProfilingUtil.c",
"InstrProfilingValue.c",
"InstrProfilingWriter.c",
];
if target.contains("msvc") {
// Don't pull in extra libraries on MSVC
cfg.flag("/Zl");
profile_sources.push("WindowsMMap.c");
cfg.define("strdup", Some("_strdup"));
cfg.define("open", Some("_open"));
cfg.define("fdopen", Some("_fdopen"));
cfg.define("getpid", Some("_getpid"));
cfg.define("fileno", Some("_fileno"));
} else {
// Turn off various features of gcc and such, mostly copying
// compiler-rt's build system already
cfg.flag("-fno-builtin");
cfg.flag("-fvisibility=hidden");
cfg.flag("-fomit-frame-pointer");
cfg.flag("-ffreestanding");
cfg.define("VISIBILITY_HIDDEN", None);
if !target.contains("windows") {
cfg.define("COMPILER_RT_HAS_UNAME", Some("1"));
} else {
profile_sources.push("WindowsMMap.c");
}
}
// Assume that the Unixes we are building this for have fnctl() available
if env::var_os("CARGO_CFG_UNIX").is_some() {
cfg.define("COMPILER_RT_HAS_FCNTL_LCK", Some("1"));
}
// This should be a pretty good heuristic for when to set
// COMPILER_RT_HAS_ATOMICS
if env::var_os("CARGO_CFG_TARGET_HAS_ATOMIC")
.map(|features| features.to_string_lossy().to_lowercase().contains("cas"))
.unwrap_or(false)
{
cfg.define("COMPILER_RT_HAS_ATOMICS", Some("1"));
}
let root = env::var_os("RUST_COMPILER_RT_ROOT").unwrap();
let root = Path::new(&root);
let src_root = root.join("lib").join("profile");
for src in profile_sources {
cfg.file(src_root.join(src));
}
// The file was renamed in LLVM 10.
let old_runtime_path = src_root.join("InstrProfilingRuntime.cc");
let new_runtime_path = src_root.join("InstrProfilingRuntime.cpp");
cfg.file(if old_runtime_path.exists() { old_runtime_path } else { new_runtime_path });
cfg.include(root.join("include"));
cfg.warnings(false);
cfg.compile("profiler-rt");
}