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