]>
Commit | Line | Data |
---|---|---|
041b39d2 XL |
1 | //! Compiles the profiler part of the `compiler-rt` library. |
2 | //! | |
3 | //! See the build.rs for libcompiler_builtins crate for details. | |
4 | ||
041b39d2 XL |
5 | use std::env; |
6 | use std::path::Path; | |
7 | ||
8 | fn main() { | |
9 | let target = env::var("TARGET").expect("TARGET was not set"); | |
ea8adc8c | 10 | let cfg = &mut cc::Build::new(); |
041b39d2 | 11 | |
dfeec247 XL |
12 | let mut profile_sources = vec![ |
13 | "GCDAProfiling.c", | |
14 | "InstrProfiling.c", | |
15 | "InstrProfilingBuffer.c", | |
16 | "InstrProfilingFile.c", | |
17 | "InstrProfilingMerge.c", | |
18 | "InstrProfilingMergeFile.c", | |
19 | "InstrProfilingNameVar.c", | |
20 | "InstrProfilingPlatformDarwin.c", | |
21 | "InstrProfilingPlatformLinux.c", | |
22 | "InstrProfilingPlatformOther.c", | |
23 | "InstrProfilingPlatformWindows.c", | |
24 | "InstrProfilingUtil.c", | |
25 | "InstrProfilingValue.c", | |
26 | "InstrProfilingWriter.c", | |
27 | ]; | |
041b39d2 XL |
28 | |
29 | if target.contains("msvc") { | |
30 | // Don't pull in extra libraries on MSVC | |
31 | cfg.flag("/Zl"); | |
32 | profile_sources.push("WindowsMMap.c"); | |
33 | cfg.define("strdup", Some("_strdup")); | |
34 | cfg.define("open", Some("_open")); | |
35 | cfg.define("fdopen", Some("_fdopen")); | |
0531ce1d XL |
36 | cfg.define("getpid", Some("_getpid")); |
37 | cfg.define("fileno", Some("_fileno")); | |
041b39d2 XL |
38 | } else { |
39 | // Turn off various features of gcc and such, mostly copying | |
40 | // compiler-rt's build system already | |
41 | cfg.flag("-fno-builtin"); | |
42 | cfg.flag("-fvisibility=hidden"); | |
43 | cfg.flag("-fomit-frame-pointer"); | |
44 | cfg.flag("-ffreestanding"); | |
45 | cfg.define("VISIBILITY_HIDDEN", None); | |
dc9dc135 XL |
46 | if !target.contains("windows") { |
47 | cfg.define("COMPILER_RT_HAS_UNAME", Some("1")); | |
48 | } else { | |
49 | profile_sources.push("WindowsMMap.c"); | |
50 | } | |
041b39d2 XL |
51 | } |
52 | ||
48663c56 XL |
53 | // Assume that the Unixes we are building this for have fnctl() available |
54 | if env::var_os("CARGO_CFG_UNIX").is_some() { | |
55 | cfg.define("COMPILER_RT_HAS_FCNTL_LCK", Some("1")); | |
56 | } | |
57 | ||
58 | // This should be a pretty good heuristic for when to set | |
59 | // COMPILER_RT_HAS_ATOMICS | |
dfeec247 XL |
60 | if env::var_os("CARGO_CFG_TARGET_HAS_ATOMIC") |
61 | .map(|features| features.to_string_lossy().to_lowercase().contains("cas")) | |
62 | .unwrap_or(false) | |
63 | { | |
48663c56 XL |
64 | cfg.define("COMPILER_RT_HAS_ATOMICS", Some("1")); |
65 | } | |
66 | ||
dc9dc135 | 67 | let root = env::var_os("RUST_COMPILER_RT_ROOT").unwrap(); |
0731742a XL |
68 | let root = Path::new(&root); |
69 | ||
dfeec247 | 70 | let src_root = root.join("lib").join("profile"); |
041b39d2 | 71 | for src in profile_sources { |
dfeec247 | 72 | cfg.file(src_root.join(src)); |
041b39d2 XL |
73 | } |
74 | ||
dfeec247 XL |
75 | // The file was renamed in LLVM 10. |
76 | let old_runtime_path = src_root.join("InstrProfilingRuntime.cc"); | |
77 | let new_runtime_path = src_root.join("InstrProfilingRuntime.cpp"); | |
78 | cfg.file(if old_runtime_path.exists() { old_runtime_path } else { new_runtime_path }); | |
79 | ||
80 | cfg.include(root.join("include")); | |
0731742a | 81 | cfg.warnings(false); |
ff7c6d11 | 82 | cfg.compile("profiler-rt"); |
041b39d2 | 83 | } |