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 let mut profile_sources = vec![
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 "InstrProfilingRuntime.cc",
25 "InstrProfilingUtil.c",
26 "InstrProfilingValue.c",
27 "InstrProfilingWriter.c",
30 if target.contains("msvc") {
31 // Don't pull in extra libraries on MSVC
33 profile_sources.push("WindowsMMap.c");
34 cfg.define("strdup", Some("_strdup"));
35 cfg.define("open", Some("_open"));
36 cfg.define("fdopen", Some("_fdopen"));
37 cfg.define("getpid", Some("_getpid"));
38 cfg.define("fileno", Some("_fileno"));
40 // Turn off various features of gcc and such, mostly copying
41 // compiler-rt's build system already
42 cfg.flag("-fno-builtin");
43 cfg.flag("-fvisibility=hidden");
44 cfg.flag("-fomit-frame-pointer");
45 cfg.flag("-ffreestanding");
46 cfg.define("VISIBILITY_HIDDEN", None);
47 if !target.contains("windows") {
48 cfg.define("COMPILER_RT_HAS_UNAME", Some("1"));
50 profile_sources.push("WindowsMMap.c");
54 // Assume that the Unixes we are building this for have fnctl() available
55 if env::var_os("CARGO_CFG_UNIX").is_some() {
56 cfg.define("COMPILER_RT_HAS_FCNTL_LCK", Some("1"));
59 // This should be a pretty good heuristic for when to set
60 // COMPILER_RT_HAS_ATOMICS
61 if env::var_os("CARGO_CFG_TARGET_HAS_ATOMIC")
62 .map(|features| features.to_string_lossy().to_lowercase().contains("cas"))
65 cfg.define("COMPILER_RT_HAS_ATOMICS", Some("1"));
68 let root = env::var_os("RUST_COMPILER_RT_ROOT").unwrap();
69 let root = Path::new(&root);
71 for src in profile_sources {
72 cfg.file(root.join("lib").join("profile").join(src));
76 cfg.compile("profiler-rt");