2017-02-13 03:57:50 -06:00
|
|
|
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
//! Compiles the profiler part of the `compiler-rt` library.
|
|
|
|
//!
|
|
|
|
//! See the build.rs for libcompiler_builtins crate for details.
|
|
|
|
|
2017-09-22 23:34:27 -05:00
|
|
|
extern crate cc;
|
2017-02-13 03:57:50 -06:00
|
|
|
|
|
|
|
use std::env;
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let target = env::var("TARGET").expect("TARGET was not set");
|
2017-09-22 23:34:27 -05:00
|
|
|
let cfg = &mut cc::Build::new();
|
2017-02-13 03:57:50 -06:00
|
|
|
|
2017-06-12 17:08:08 -05:00
|
|
|
let mut profile_sources = vec!["GCDAProfiling.c",
|
|
|
|
"InstrProfiling.c",
|
|
|
|
"InstrProfilingBuffer.c",
|
|
|
|
"InstrProfilingFile.c",
|
|
|
|
"InstrProfilingMerge.c",
|
|
|
|
"InstrProfilingMergeFile.c",
|
|
|
|
"InstrProfilingPlatformDarwin.c",
|
|
|
|
"InstrProfilingPlatformLinux.c",
|
|
|
|
"InstrProfilingPlatformOther.c",
|
|
|
|
"InstrProfilingRuntime.cc",
|
|
|
|
"InstrProfilingUtil.c",
|
|
|
|
"InstrProfilingValue.c",
|
|
|
|
"InstrProfilingWriter.c"];
|
|
|
|
|
2017-02-13 03:57:50 -06:00
|
|
|
if target.contains("msvc") {
|
|
|
|
// Don't pull in extra libraries on MSVC
|
|
|
|
cfg.flag("/Zl");
|
2017-06-12 17:08:08 -05:00
|
|
|
profile_sources.push("WindowsMMap.c");
|
2017-06-12 17:08:57 -05:00
|
|
|
cfg.define("strdup", Some("_strdup"));
|
|
|
|
cfg.define("open", Some("_open"));
|
|
|
|
cfg.define("fdopen", Some("_fdopen"));
|
2017-02-13 03:57:50 -06:00
|
|
|
} else {
|
|
|
|
// Turn off various features of gcc and such, mostly copying
|
|
|
|
// compiler-rt's build system already
|
|
|
|
cfg.flag("-fno-builtin");
|
|
|
|
cfg.flag("-fvisibility=hidden");
|
|
|
|
cfg.flag("-fomit-frame-pointer");
|
|
|
|
cfg.flag("-ffreestanding");
|
|
|
|
cfg.define("VISIBILITY_HIDDEN", None);
|
|
|
|
}
|
|
|
|
|
|
|
|
for src in profile_sources {
|
2017-06-22 15:14:00 -05:00
|
|
|
cfg.file(Path::new("../libcompiler_builtins/compiler-rt/lib/profile").join(src));
|
2017-02-13 03:57:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
cfg.compile("libprofiler-rt.a");
|
|
|
|
}
|