build.rs 588 B

1234567891011121314151617
  1. use std::process::{Command, Stdio};
  2. use std::io::Write;
  3. fn main() {
  4. let mut child = Command::new(option_env!("RUSTC").unwrap_or("rustc"))
  5. .args(&["-", "--crate-type", "lib", "-Z", "no-trans"])
  6. .stdin(Stdio::piped())
  7. .stdout(Stdio::null())
  8. .stderr(Stdio::null())
  9. .spawn()
  10. .unwrap();
  11. child.stdin.as_mut().unwrap().write_all(b"use std::net::IpAddr;").unwrap();
  12. if child.wait().unwrap().success() {
  13. // We can use `IpAddr` as it is `#[stable]` in this version of Rust.
  14. println!("cargo:rustc-cfg=has_ipaddr")
  15. }
  16. }