]> git.lizzy.rs Git - rust.git/blob - src/libprofiler_builtins/build.rs
Rollup merge of #58096 - h-michael:linkchecker-2018, r=Centril
[rust.git] / src / libprofiler_builtins / build.rs
1 //! Compiles the profiler part of the `compiler-rt` library.
2 //!
3 //! See the build.rs for libcompiler_builtins crate for details.
4
5 extern crate cc;
6
7 use std::env;
8 use std::path::Path;
9
10 fn main() {
11     let target = env::var("TARGET").expect("TARGET was not set");
12     let cfg = &mut cc::Build::new();
13
14     let mut profile_sources = vec!["GCDAProfiling.c",
15                                    "InstrProfiling.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"];
28
29     if target.contains("msvc") {
30         // Don't pull in extra libraries on MSVC
31         cfg.flag("/Zl");
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"));
38     } else {
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"));
47     }
48
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);
53
54     for src in profile_sources {
55         cfg.file(root.join("lib").join("profile").join(src));
56     }
57
58     cfg.warnings(false);
59     cfg.compile("profiler-rt");
60 }