1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Compiles the profiler part of the `compiler-rt` library.
13 //! See the build.rs for libcompiler_builtins crate for details.
21 let target = env::var("TARGET").expect("TARGET was not set");
22 let cfg = &mut cc::Build::new();
24 let mut profile_sources = vec!["GCDAProfiling.c",
26 "InstrProfilingBuffer.c",
27 "InstrProfilingFile.c",
28 "InstrProfilingMerge.c",
29 "InstrProfilingMergeFile.c",
30 "InstrProfilingPlatformDarwin.c",
31 "InstrProfilingPlatformLinux.c",
32 "InstrProfilingPlatformOther.c",
33 "InstrProfilingRuntime.cc",
34 "InstrProfilingUtil.c",
35 "InstrProfilingValue.c",
36 "InstrProfilingWriter.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"));
46 // Turn off various features of gcc and such, mostly copying
47 // compiler-rt's build system already
48 cfg.flag("-fno-builtin");
49 cfg.flag("-fvisibility=hidden");
50 cfg.flag("-fomit-frame-pointer");
51 cfg.flag("-ffreestanding");
52 cfg.define("VISIBILITY_HIDDEN", None);
55 for src in profile_sources {
56 cfg.file(Path::new("../libcompiler_builtins/compiler-rt/lib/profile").join(src));
59 cfg.compile("libprofiler-rt.a");