Skip to content

Commit 0372add

Browse files
committed
Use autocfg to probe for i128
1 parent 23d979c commit 0372add

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ full-syntax = ["syn/full"]
2929
name = "num_derive"
3030
proc-macro = true
3131
test = false
32+
33+
[build-dependencies]
34+
autocfg = "0.1.2"

build.rs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,14 @@
1+
extern crate autocfg;
2+
13
use std::env;
2-
use std::io::Write;
3-
use std::process::{Command, Stdio};
44

55
fn main() {
6-
if probe("fn main() { 0i128; }") {
6+
let ac = autocfg::new();
7+
if ac.probe_type("i128") {
78
println!("cargo:rustc-cfg=has_i128");
89
} else if env::var_os("CARGO_FEATURE_I128").is_some() {
910
panic!("i128 support was not detected!");
1011
}
11-
}
12-
13-
/// Test if a code snippet can be compiled
14-
fn probe(code: &str) -> bool {
15-
let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into());
16-
let out_dir = env::var_os("OUT_DIR").expect("environment variable OUT_DIR");
17-
18-
let mut child = Command::new(rustc)
19-
.arg("--out-dir")
20-
.arg(out_dir)
21-
.arg("--emit=obj")
22-
.arg("-")
23-
.stdin(Stdio::piped())
24-
.spawn()
25-
.expect("rustc probe");
26-
27-
child
28-
.stdin
29-
.as_mut()
30-
.expect("rustc stdin")
31-
.write_all(code.as_bytes())
32-
.expect("write rustc stdin");
3312

34-
child.wait().expect("rustc probe").success()
13+
autocfg::rerun_path(file!());
3514
}

0 commit comments

Comments
 (0)