Skip to content

Only require the target spec if the c-feature is enabled #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = "compiler_builtins"
version = "0.1.0"

[build-dependencies]
rustc-cfg = "0.3.0"
rustc-cfg = { version = "0.3.0", optional = true }

[build-dependencies.gcc]
optional = true
Expand All @@ -19,7 +19,7 @@ compiler-rt = { path = "compiler-rt" }

[features]
# Build the missing intrinsics from compiler-rt C source code
c = ["gcc"]
c = ["gcc", "rustc-cfg"]
# Mark this crate as the #![compiler_builtins] crate
compiler-builtins = []
default = ["compiler-builtins"]
Expand Down
24 changes: 13 additions & 11 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#[cfg(feature = "c")]
extern crate gcc;
#[cfg(feature = "c")]
extern crate rustc_cfg;

#[cfg(feature = "c")]
use std::collections::BTreeMap;
#[cfg(feature = "c")]
use std::io::Write;
#[cfg(feature = "c")]
use std::path::Path;
use std::{env, io, process};
use std::env;

#[cfg(feature = "c")]
use std::{io, process};

#[cfg(feature = "c")]
use rustc_cfg::Cfg;

#[cfg(feature = "c")]
Expand Down Expand Up @@ -61,20 +67,19 @@ fn main() {
return;
}

let Cfg { ref target_arch, ref target_os, ref target_env, ref target_vendor, .. } =
Cfg::new(&target).unwrap_or_else(|e| {
writeln!(io::stderr(), "{}", e).ok();
process::exit(1)
});
// 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
match () {
#[cfg(feature = "c")]
() => {
{
let Cfg { ref target_arch, ref target_os, ref target_env, ref target_vendor, .. } =
Cfg::new(&target).unwrap_or_else(|e| {
writeln!(io::stderr(), "{}", e).ok();
process::exit(1)
});
let target_vendor = target_vendor.as_ref().unwrap();
let cfg = &mut gcc::Config::new();

Expand Down Expand Up @@ -413,9 +418,6 @@ fn main() {

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") &&
Expand Down
2 changes: 1 addition & 1 deletion src/bin/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// compiling a C implementation and forget to implement that intrinsic in Rust, this file will fail
// to link due to the missing intrinsic (symbol).

#![allow(unused_features)]
#![allow(unused_features, private_no_mangle_fns)]
#![cfg_attr(thumb, no_main)]
#![deny(dead_code)]
#![feature(asm)]
Expand Down