Skip to content

Commit

Permalink
Use autocfg to probe for i128
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed May 10, 2019
1 parent 2f20761 commit 8e4bb14
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ version = "1.0"
default = ["std"]
i128 = ["num-integer/i128", "num-traits/i128"]
std = ["num-integer/std", "num-traits/std"]

[build-dependencies]
autocfg = "0.1.2"
31 changes: 5 additions & 26 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,14 @@
extern crate autocfg;

use std::env;
use std::io::Write;
use std::process::{Command, Stdio};

fn main() {
if probe("fn main() { 0i128; }") {
let ac = autocfg::new();
if ac.probe_type("i128") {
println!("cargo:rustc-cfg=has_i128");
} else if env::var_os("CARGO_FEATURE_I128").is_some() {
panic!("i128 support was not detected!");
}
}

/// Test if a code snippet can be compiled
fn probe(code: &str) -> bool {
let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into());
let out_dir = env::var_os("OUT_DIR").expect("environment variable OUT_DIR");

let mut child = Command::new(rustc)
.arg("--out-dir")
.arg(out_dir)
.arg("--emit=obj")
.arg("-")
.stdin(Stdio::piped())
.spawn()
.expect("rustc probe");

child
.stdin
.as_mut()
.expect("rustc stdin")
.write_all(code.as_bytes())
.expect("write rustc stdin");

child.wait().expect("rustc probe").success()
autocfg::rerun_path(file!());
}

0 comments on commit 8e4bb14

Please sign in to comment.