]> git.proxmox.com Git - rustc.git/blame - library/profiler_builtins/build.rs
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / library / profiler_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 11
3dfed10e
XL
12 // FIXME: `rerun-if-changed` directives are not currently emitted and the build script
13 // will not rerun on changes in these source files or headers included into them.
dfeec247
XL
14 let mut profile_sources = vec![
15 "GCDAProfiling.c",
16 "InstrProfiling.c",
17 "InstrProfilingBuffer.c",
18 "InstrProfilingFile.c",
19 "InstrProfilingMerge.c",
20 "InstrProfilingMergeFile.c",
21 "InstrProfilingNameVar.c",
22 "InstrProfilingPlatformDarwin.c",
1b1a35ee 23 "InstrProfilingPlatformFuchsia.c",
dfeec247
XL
24 "InstrProfilingPlatformLinux.c",
25 "InstrProfilingPlatformOther.c",
26 "InstrProfilingPlatformWindows.c",
27 "InstrProfilingUtil.c",
28 "InstrProfilingValue.c",
6a06907d 29 "InstrProfilingVersionVar.c",
dfeec247 30 "InstrProfilingWriter.c",
f035d41b
XL
31 // This file was renamed in LLVM 10.
32 "InstrProfilingRuntime.cc",
33 "InstrProfilingRuntime.cpp",
34 // These files were added in LLVM 11.
35 "InstrProfilingInternal.c",
36 "InstrProfilingBiasVar.c",
dfeec247 37 ];
041b39d2
XL
38
39 if target.contains("msvc") {
40 // Don't pull in extra libraries on MSVC
41 cfg.flag("/Zl");
42 profile_sources.push("WindowsMMap.c");
43 cfg.define("strdup", Some("_strdup"));
44 cfg.define("open", Some("_open"));
45 cfg.define("fdopen", Some("_fdopen"));
0531ce1d
XL
46 cfg.define("getpid", Some("_getpid"));
47 cfg.define("fileno", Some("_fileno"));
041b39d2
XL
48 } else {
49 // Turn off various features of gcc and such, mostly copying
50 // compiler-rt's build system already
51 cfg.flag("-fno-builtin");
041b39d2 52 cfg.flag("-fomit-frame-pointer");
041b39d2 53 cfg.define("VISIBILITY_HIDDEN", None);
dc9dc135 54 if !target.contains("windows") {
1b1a35ee 55 cfg.flag("-fvisibility=hidden");
dc9dc135
XL
56 cfg.define("COMPILER_RT_HAS_UNAME", Some("1"));
57 } else {
58 profile_sources.push("WindowsMMap.c");
59 }
041b39d2
XL
60 }
61
48663c56
XL
62 // Assume that the Unixes we are building this for have fnctl() available
63 if env::var_os("CARGO_CFG_UNIX").is_some() {
64 cfg.define("COMPILER_RT_HAS_FCNTL_LCK", Some("1"));
65 }
66
67 // This should be a pretty good heuristic for when to set
68 // COMPILER_RT_HAS_ATOMICS
dfeec247 69 if env::var_os("CARGO_CFG_TARGET_HAS_ATOMIC")
3dfed10e 70 .map(|features| features.to_string_lossy().to_lowercase().contains("ptr"))
dfeec247
XL
71 .unwrap_or(false)
72 {
48663c56
XL
73 cfg.define("COMPILER_RT_HAS_ATOMICS", Some("1"));
74 }
75
ba9703b0
XL
76 // Note that this should exist if we're going to run (otherwise we just
77 // don't build profiler builtins at all).
3dfed10e 78 let root = Path::new("../../src/llvm-project/compiler-rt");
0731742a 79
dfeec247 80 let src_root = root.join("lib").join("profile");
041b39d2 81 for src in profile_sources {
f035d41b
XL
82 let path = src_root.join(src);
83 if path.exists() {
84 cfg.file(path);
85 }
041b39d2
XL
86 }
87
dfeec247 88 cfg.include(root.join("include"));
0731742a 89 cfg.warnings(false);
ff7c6d11 90 cfg.compile("profiler-rt");
041b39d2 91}