/ build.rs
build.rs
 1  fn main() {
 2      let rustc = std::env::var_os("RUSTC").unwrap_or_else(|| "rustc".into());
 3      let output = std::process::Command::new(rustc)
 4          .arg("--version")
 5          .output()
 6          .expect("Failed to run rustc --version");
 7      assert!(output.status.success(), "Failed to get rust version");
 8      let stdout = String::from_utf8(output.stdout).expect("rustc produced non-UTF-8 output");
 9      let version_prefix = "rustc ";
10      if !stdout.starts_with(version_prefix) {
11          panic!("unexpected rustc output: {}", stdout);
12      }
13  
14      let version = &stdout[version_prefix.len()..];
15      let end = version.find(&[' ', '-'] as &[_]).unwrap_or(version.len());
16      let version = &version[..end];
17      let mut version_components = version.split('.');
18      let major = version_components.next().unwrap();
19      assert_eq!(major, "1", "Unexpected Rust version");
20      let minor = version_components
21          .next()
22          .unwrap_or("0")
23          .parse::<u64>()
24          .expect("invalid Rust minor version");
25  
26      for activate_version in &[] {
27          if minor >= *activate_version {
28              println!("cargo:rustc-cfg=rust_v_1_{}", activate_version);
29          }
30      }
31  }
32