Austin Schuh | 6ea9bfa | 2023-08-06 19:05:10 -0700 | [diff] [blame] | 1 | // Copyright 2023 Google LLC |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 4 | // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 5 | // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your |
| 6 | // option. This file may not be copied, modified, or distributed |
| 7 | // except according to those terms. |
| 8 | |
| 9 | // It would be nice to use the rustversion crate here instead, |
| 10 | // but that doesn't work with inner attributes. |
| 11 | fn main() { |
| 12 | if let Some(ver) = rustc_version() { |
| 13 | if ver.contains("nightly") { |
| 14 | println!("cargo:rustc-cfg=nightly") |
| 15 | } |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | fn rustc_version() -> Option<String> { |
| 20 | let rustc = std::env::var_os("RUSTC")?; |
| 21 | let output = std::process::Command::new(rustc) |
| 22 | .arg("--version") |
| 23 | .output() |
| 24 | .ok()?; |
| 25 | let version = String::from_utf8(output.stdout).ok()?; |
| 26 | Some(version) |
| 27 | } |