|
| 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. |
| 4 | +// |
| 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. |
| 10 | + |
| 11 | +//! Compiles the profiler part of the `compiler-rt` library. |
| 12 | +//! |
| 13 | +//! See the build.rs for libcompiler_builtins crate for details. |
| 14 | +
|
| 15 | +extern crate gcc; |
| 16 | + |
| 17 | +use std::env; |
| 18 | +use std::path::Path; |
| 19 | + |
| 20 | +fn main() { |
| 21 | + let target = env::var("TARGET").expect("TARGET was not set"); |
| 22 | + let cfg = &mut gcc::Config::new(); |
| 23 | + |
| 24 | + let mut profile_sources = vec!["GCDAProfiling.c", |
| 25 | + "InstrProfiling.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"]; |
| 37 | + |
| 38 | + if target.contains("msvc") { |
| 39 | + // Don't pull in extra libraries on MSVC |
| 40 | + cfg.flag("/Zl"); |
| 41 | + profile_sources.push("WindowsMMap.c"); |
| 42 | + cfg.define("strdup", Some("_strdup")); |
| 43 | + cfg.define("open", Some("_open")); |
| 44 | + cfg.define("fdopen", Some("_fdopen")); |
| 45 | + } else { |
| 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); |
| 53 | + } |
| 54 | + |
| 55 | + for src in profile_sources { |
| 56 | + cfg.file(Path::new("../compiler-rt/lib/profile").join(src)); |
| 57 | + } |
| 58 | + |
| 59 | + cfg.compile("libprofiler-rt.a"); |
| 60 | +} |
0 commit comments