Joel Galenson | 5448f37 | 2021-04-01 15:10:30 -0700 | [diff] [blame] | 1 | use std::env; |
| 2 | use std::process::Command; |
| 3 | use std::str; |
| 4 | |
| 5 | fn main() { |
| 6 | let compiler = match rustc_minor_version() { |
| 7 | Some(compiler) => compiler, |
| 8 | None => return, |
| 9 | }; |
| 10 | |
| 11 | if compiler < 47 { |
| 12 | println!("cargo:rustc-cfg=self_span_hack"); |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | fn rustc_minor_version() -> Option<u32> { |
| 17 | let rustc = env::var_os("RUSTC")?; |
| 18 | let output = Command::new(rustc).arg("--version").output().ok()?; |
| 19 | let version = str::from_utf8(&output.stdout).ok()?; |
| 20 | let mut pieces = version.split('.'); |
| 21 | if pieces.next() != Some("rustc 1") { |
| 22 | return None; |
| 23 | } |
| 24 | pieces.next()?.parse().ok() |
| 25 | } |