]>
git.proxmox.com Git - rustc.git/blob - library/profiler_builtins/build.rs
1 //! Compiles the profiler part of the `compiler-rt` library.
3 //! See the build.rs for libcompiler_builtins crate for details.
9 let target
= env
::var("TARGET").expect("TARGET was not set");
10 let cfg
= &mut cc
::Build
::new();
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.
14 let mut profile_sources
= vec
![
17 "InstrProfilingBuffer.c",
18 "InstrProfilingFile.c",
19 "InstrProfilingMerge.c",
20 "InstrProfilingMergeFile.c",
21 "InstrProfilingNameVar.c",
22 "InstrProfilingPlatformDarwin.c",
23 "InstrProfilingPlatformFuchsia.c",
24 "InstrProfilingPlatformLinux.c",
25 "InstrProfilingPlatformOther.c",
26 "InstrProfilingPlatformWindows.c",
27 "InstrProfilingUtil.c",
28 "InstrProfilingValue.c",
29 "InstrProfilingWriter.c",
30 // This file was renamed in LLVM 10.
31 "InstrProfilingRuntime.cc",
32 "InstrProfilingRuntime.cpp",
33 // These files were added in LLVM 11.
34 "InstrProfilingInternal.c",
35 "InstrProfilingBiasVar.c",
38 if target
.contains("msvc") {
39 // Don't pull in extra libraries on MSVC
41 profile_sources
.push("WindowsMMap.c");
42 cfg
.define("strdup", Some("_strdup"));
43 cfg
.define("open", Some("_open"));
44 cfg
.define("fdopen", Some("_fdopen"));
45 cfg
.define("getpid", Some("_getpid"));
46 cfg
.define("fileno", Some("_fileno"));
48 // Turn off various features of gcc and such, mostly copying
49 // compiler-rt's build system already
50 cfg
.flag("-fno-builtin");
51 cfg
.flag("-fomit-frame-pointer");
52 cfg
.define("VISIBILITY_HIDDEN", None
);
53 if !target
.contains("windows") {
54 cfg
.flag("-fvisibility=hidden");
55 cfg
.define("COMPILER_RT_HAS_UNAME", Some("1"));
57 profile_sources
.push("WindowsMMap.c");
61 // Assume that the Unixes we are building this for have fnctl() available
62 if env
::var_os("CARGO_CFG_UNIX").is_some() {
63 cfg
.define("COMPILER_RT_HAS_FCNTL_LCK", Some("1"));
66 // This should be a pretty good heuristic for when to set
67 // COMPILER_RT_HAS_ATOMICS
68 if env
::var_os("CARGO_CFG_TARGET_HAS_ATOMIC")
69 .map(|features
| features
.to_string_lossy().to_lowercase().contains("ptr"))
72 cfg
.define("COMPILER_RT_HAS_ATOMICS", Some("1"));
75 // Note that this should exist if we're going to run (otherwise we just
76 // don't build profiler builtins at all).
77 let root
= Path
::new("../../src/llvm-project/compiler-rt");
79 let src_root
= root
.join("lib").join("profile");
80 for src
in profile_sources
{
81 let path
= src_root
.join(src
);
87 cfg
.include(root
.join("include"));
89 cfg
.compile("profiler-rt");