Merge #113
113: Use autocfg to probe for i128 r=cuviper a=cuviper Co-authored-by: Josh Stone <cuviper@gmail.com>
This commit is contained in:
commit
852ec9380f
|
@ -22,3 +22,6 @@ features = ["std"]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
std = []
|
std = []
|
||||||
i128 = []
|
i128 = []
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
autocfg = "0.1.2"
|
||||||
|
|
33
build.rs
33
build.rs
|
@ -1,35 +1,14 @@
|
||||||
|
extern crate autocfg;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::io::Write;
|
|
||||||
use std::process::{Command, Stdio};
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
if probe("fn main() { 0i128; }") {
|
let ac = autocfg::new();
|
||||||
|
if ac.probe_type("i128") {
|
||||||
println!("cargo:rustc-cfg=has_i128");
|
println!("cargo:rustc-cfg=has_i128");
|
||||||
} else if env::var_os("CARGO_FEATURE_I128").is_some() {
|
} else if env::var_os("CARGO_FEATURE_I128").is_some() {
|
||||||
panic!("i128 support was not detected!");
|
panic!("i128 support was not detected!");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
autocfg::rerun_path(file!());
|
||||||
/// 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()
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue