1 //! Compiles the profiler part of the `compiler-rt` library.
3 //! See the build.rs for libcompiler_builtins crate for details.
11 let target = env::var("TARGET").expect("TARGET was not set");
12 let cfg = &mut cc::Build::new();
14 let mut profile_sources = vec!["GCDAProfiling.c",
16 "InstrProfilingBuffer.c",
17 "InstrProfilingFile.c",
18 "InstrProfilingMerge.c",
19 "InstrProfilingMergeFile.c",
20 "InstrProfilingNameVar.c",
21 "InstrProfilingPlatformDarwin.c",
22 "InstrProfilingPlatformLinux.c",
23 "InstrProfilingPlatformOther.c",
24 "InstrProfilingRuntime.cc",
25 "InstrProfilingUtil.c",
26 "InstrProfilingValue.c",
27 "InstrProfilingWriter.c"];
29 if target.contains("msvc") {
30 // Don't pull in extra libraries on MSVC
32 profile_sources.push("WindowsMMap.c");
33 cfg.define("strdup", Some("_strdup"));
34 cfg.define("open", Some("_open"));
35 cfg.define("fdopen", Some("_fdopen"));
36 cfg.define("getpid", Some("_getpid"));
37 cfg.define("fileno", Some("_fileno"));
39 // Turn off various features of gcc and such, mostly copying
40 // compiler-rt's build system already
41 cfg.flag("-fno-builtin");
42 cfg.flag("-fvisibility=hidden");
43 cfg.flag("-fomit-frame-pointer");
44 cfg.flag("-ffreestanding");
45 cfg.define("VISIBILITY_HIDDEN", None);
46 cfg.define("COMPILER_RT_HAS_UNAME", Some("1"));
49 // The source for `compiler-rt` comes from the `compiler-builtins` crate, so
50 // load our env var set by cargo to find the source code.
51 let root = env::var_os("DEP_COMPILER_RT_COMPILER_RT").unwrap();
52 let root = Path::new(&root);
54 for src in profile_sources {
55 cfg.file(root.join("lib").join("profile").join(src));
59 cfg.compile("profiler-rt");