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!["GCDAProfiling.c",
14 "InstrProfilingBuffer.c",
15 "InstrProfilingFile.c",
16 "InstrProfilingMerge.c",
17 "InstrProfilingMergeFile.c",
18 "InstrProfilingNameVar.c",
19 "InstrProfilingPlatformDarwin.c",
20 "InstrProfilingPlatformLinux.c",
21 "InstrProfilingPlatformOther.c",
22 "InstrProfilingRuntime.cc",
23 "InstrProfilingUtil.c",
24 "InstrProfilingValue.c",
25 "InstrProfilingWriter.c"];
27 if target.contains("msvc") {
28 // Don't pull in extra libraries on MSVC
30 profile_sources.push("WindowsMMap.c");
31 cfg.define("strdup", Some("_strdup"));
32 cfg.define("open", Some("_open"));
33 cfg.define("fdopen", Some("_fdopen"));
34 cfg.define("getpid", Some("_getpid"));
35 cfg.define("fileno", Some("_fileno"));
37 // Turn off various features of gcc and such, mostly copying
38 // compiler-rt's build system already
39 cfg.flag("-fno-builtin");
40 cfg.flag("-fvisibility=hidden");
41 cfg.flag("-fomit-frame-pointer");
42 cfg.flag("-ffreestanding");
43 cfg.define("VISIBILITY_HIDDEN", None);
44 cfg.define("COMPILER_RT_HAS_UNAME", Some("1"));
47 // Assume that the Unixes we are building this for have fnctl() available
48 if env::var_os("CARGO_CFG_UNIX").is_some() {
49 cfg.define("COMPILER_RT_HAS_FCNTL_LCK", Some("1"));
52 // This should be a pretty good heuristic for when to set
53 // COMPILER_RT_HAS_ATOMICS
54 if env::var_os("CARGO_CFG_TARGET_HAS_ATOMIC").map(|features| {
55 features.to_string_lossy().to_lowercase().contains("cas")
57 cfg.define("COMPILER_RT_HAS_ATOMICS", Some("1"));
60 // The source for `compiler-rt` comes from the `compiler-builtins` crate, so
61 // load our env var set by cargo to find the source code.
62 let root = env::var_os("DEP_COMPILER_RT_COMPILER_RT").unwrap();
63 let root = Path::new(&root);
65 for src in profile_sources {
66 cfg.file(root.join("lib").join("profile").join(src));
70 cfg.compile("profiler-rt");