Skip to content

Commit

Permalink
Simplify logic in build.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 authored and sunfishcode committed Jul 2, 2020
1 parent 9ed8983 commit b97f773
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,21 @@ fn main() {
Triple::from_str(&target).unwrap_or_else(|_| panic!("Invalid target name: '{}'", target));
let out = File::create(out_dir.join("host.rs")).expect("error creating host.rs");
write_host_rs(out, triple).expect("error writing host.rs");
if using_less_1_40().is_none() {
if using_1_40() {
println!("cargo:rustc-cfg=feature=\"rust_1_40\"");
}
}

fn using_less_1_40() -> Option<()> {
let stdout = match Command::new("rustc").arg("--version").output() {
Ok(output) if output.status.success() => output.stdout,
// Assume we're up-to-date, rustc wasn't found in PATH
_ => return None,
};
let version: i32 = std::str::from_utf8(&stdout).ok()?.split(' ').nth(1)?.parse().ok()?;
if version < 40 {
Some(())
} else {
None
fn using_1_40() -> bool {
match (|| {
let stdout = match Command::new("rustc").arg("--version").output() {
Ok(output) if output.status.success() => output.stdout,
_ => return None,
};
std::str::from_utf8(&stdout).ok()?.split(' ').nth(1)?.parse::<i32>().ok()
})() {
Some(version) => version >= 40,
None => true, // assume we're using an up-to-date compiler
}
}

Expand Down

0 comments on commit b97f773

Please sign in to comment.