This repository has been archived by the owner on Oct 6, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gate literal fromstr support on new enough compiler
- Loading branch information
Showing
2 changed files
with
54 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::env; | ||
use std::process::Command; | ||
use std::str; | ||
|
||
fn main() { | ||
println!("cargo:rerun-if-changed=build.rs"); | ||
|
||
let version = match rustc_version() { | ||
Some(version) => version, | ||
None => return, | ||
}; | ||
|
||
if version.minor < 54 { | ||
// https://github.com/rust-lang/rust/pull/84717 | ||
println!("cargo:rustc-cfg=no_literal_fromstr"); | ||
} | ||
} | ||
|
||
struct RustcVersion { | ||
minor: u32, | ||
} | ||
|
||
fn rustc_version() -> Option<RustcVersion> { | ||
let rustc = env::var_os("RUSTC")?; | ||
let output = Command::new(rustc).arg("--version").output().ok()?; | ||
let version = str::from_utf8(&output.stdout).ok()?; | ||
let mut pieces = version.split('.'); | ||
if pieces.next() != Some("rustc 1") { | ||
return None; | ||
} | ||
let minor = pieces.next()?.parse().ok()?; | ||
Some(RustcVersion { minor }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters