refactor build.rs to not depend on rustc-cfg
it now uses the CARGO_CFG_TARGET variables provided by Cargo
This commit is contained in:
parent
cc0d8ba2d1
commit
dbcec72ca1
|
@ -4,9 +4,6 @@ build = "build.rs"
|
||||||
name = "compiler_builtins"
|
name = "compiler_builtins"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
rustc-cfg = "0.3.0"
|
|
||||||
|
|
||||||
[build-dependencies.gcc]
|
[build-dependencies.gcc]
|
||||||
optional = true
|
optional = true
|
||||||
version = "0.3.36"
|
version = "0.3.36"
|
||||||
|
|
109
build.rs
109
build.rs
|
@ -1,24 +1,51 @@
|
||||||
#[cfg(feature = "c")]
|
use std::env;
|
||||||
extern crate gcc;
|
|
||||||
extern crate rustc_cfg;
|
|
||||||
|
|
||||||
#[cfg(feature = "c")]
|
fn main() {
|
||||||
use std::collections::BTreeMap;
|
println!("cargo:rerun-if-changed=build.rs");
|
||||||
use std::io::Write;
|
|
||||||
#[cfg(feature = "c")]
|
|
||||||
use std::path::Path;
|
|
||||||
use std::{env, io, process};
|
|
||||||
|
|
||||||
use rustc_cfg::Cfg;
|
let target = env::var("TARGET").unwrap();
|
||||||
|
|
||||||
#[cfg(feature = "c")]
|
// Emscripten's runtime includes all the builtins
|
||||||
struct Sources {
|
if target.contains("emscripten") {
|
||||||
// SYMBOL -> PATH TO SOURCE
|
return;
|
||||||
map: BTreeMap<&'static str, &'static str>,
|
}
|
||||||
|
|
||||||
|
// NOTE we are going to assume that llvm-target, what determines our codegen option, matches the
|
||||||
|
// target triple. This is usually correct for our built-in targets but can break in presence of
|
||||||
|
// custom targets, which can have arbitrary names.
|
||||||
|
let llvm_target = target.split('-').collect::<Vec<_>>();
|
||||||
|
|
||||||
|
// Build missing intrinsics from compiler-rt C source code
|
||||||
|
#[cfg(feature = "c")]
|
||||||
|
c::compile(&llvm_target);
|
||||||
|
|
||||||
|
// To compile intrinsics.rs for thumb targets, where there is no libc
|
||||||
|
if llvm_target[0].starts_with("thumb") {
|
||||||
|
println!("cargo:rustc-cfg=thumb")
|
||||||
|
}
|
||||||
|
|
||||||
|
// compiler-rt `cfg`s away some intrinsics for thumbv6m because that target doesn't have full
|
||||||
|
// THUMBv2 support. We have to cfg our code accordingly.
|
||||||
|
if llvm_target[0] == "thumbv6m" {
|
||||||
|
println!("cargo:rustc-cfg=thumbv6m")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "c")]
|
#[cfg(feature = "c")]
|
||||||
impl Sources {
|
mod c {
|
||||||
|
extern crate gcc;
|
||||||
|
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
use std::env;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
struct Sources {
|
||||||
|
// SYMBOL -> PATH TO SOURCE
|
||||||
|
map: BTreeMap<&'static str, &'static str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sources {
|
||||||
fn new() -> Sources {
|
fn new() -> Sources {
|
||||||
Sources { map: BTreeMap::new() }
|
Sources { map: BTreeMap::new() }
|
||||||
}
|
}
|
||||||
|
@ -49,33 +76,15 @@ impl Sources {
|
||||||
self.map.remove(*symbol).unwrap();
|
self.map.remove(*symbol).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
println!("cargo:rerun-if-changed=build.rs");
|
|
||||||
|
|
||||||
let target = env::var("TARGET").unwrap();
|
|
||||||
|
|
||||||
// Emscripten's runtime includes all the builtins
|
|
||||||
if target.contains("emscripten") {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let Cfg { ref target_arch, ref target_os, ref target_env, ref target_vendor, .. } =
|
/// Compile intrinsics from the compiler-rt C source code
|
||||||
Cfg::new(&target).unwrap_or_else(|e| {
|
pub fn compile(llvm_target: &[&str]){
|
||||||
writeln!(io::stderr(), "{}", e).ok();
|
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
|
||||||
process::exit(1)
|
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
|
||||||
});
|
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
|
||||||
// NOTE we are going to assume that llvm-target, what determines our codegen option, matches the
|
let target_vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap();
|
||||||
// target triple. This is usually correct for our built-in targets but can break in presence of
|
|
||||||
// custom targets, which can have arbitrary names.
|
|
||||||
let llvm_target = target.split('-').collect::<Vec<_>>();
|
|
||||||
|
|
||||||
// Build missing intrinsics from compiler-rt C source code
|
|
||||||
match () {
|
|
||||||
#[cfg(feature = "c")]
|
|
||||||
() => {
|
|
||||||
let target_vendor = target_vendor.as_ref().unwrap();
|
|
||||||
let cfg = &mut gcc::Config::new();
|
let cfg = &mut gcc::Config::new();
|
||||||
|
|
||||||
if target_env == "msvc" {
|
if target_env == "msvc" {
|
||||||
|
@ -404,7 +413,7 @@ fn main() {
|
||||||
Path::new(".")
|
Path::new(".")
|
||||||
};
|
};
|
||||||
|
|
||||||
let src_dir = root.join("compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins");
|
let src_dir = root.join("c/compiler-rt/lib/builtins");
|
||||||
for src in sources.map.values() {
|
for src in sources.map.values() {
|
||||||
let src = src_dir.join(src);
|
let src = src_dir.join(src);
|
||||||
cfg.file(&src);
|
cfg.file(&src);
|
||||||
|
@ -413,24 +422,4 @@ fn main() {
|
||||||
|
|
||||||
cfg.compile("libcompiler-rt.a");
|
cfg.compile("libcompiler-rt.a");
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "c"))]
|
|
||||||
() => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// To filter away some flaky test (see src/float/add.rs for details)
|
|
||||||
if llvm_target[0].starts_with("arm") &&
|
|
||||||
llvm_target.last().unwrap().contains("gnueabi") {
|
|
||||||
println!("cargo:rustc-cfg=arm_linux")
|
|
||||||
}
|
|
||||||
|
|
||||||
// To compile intrinsics.rs for thumb targets, where there is no libc
|
|
||||||
if llvm_target[0].starts_with("thumb") {
|
|
||||||
println!("cargo:rustc-cfg=thumb")
|
|
||||||
}
|
|
||||||
|
|
||||||
// compiler-rt `cfg`s away some intrinsics for thumbv6m because that target doesn't have full
|
|
||||||
// THUMBv2 support. We have to cfg our code accordingly.
|
|
||||||
if llvm_target[0] == "thumbv6m" {
|
|
||||||
println!("cargo:rustc-cfg=thumbv6m")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue