2020-10-08 00:38:59 +00:00
|
|
|
use std::env;
|
|
|
|
use std::path::Path;
|
2020-11-11 20:00:20 +00:00
|
|
|
use std::process::Command;
|
2020-10-08 00:38:59 +00:00
|
|
|
|
2019-10-20 18:51:12 +00:00
|
|
|
fn main() {
|
|
|
|
cc::Build::new()
|
2020-03-11 23:49:18 +00:00
|
|
|
.file("src/cxx.cc")
|
2020-05-08 18:23:46 +00:00
|
|
|
.cpp(true)
|
2020-05-08 20:06:04 +00:00
|
|
|
.cpp_link_stdlib(None) // linked via link-cplusplus crate
|
2020-08-29 00:25:29 +00:00
|
|
|
.flag_if_supported(cxxbridge_flags::STD)
|
2021-01-02 23:54:24 +00:00
|
|
|
.warnings_into_errors(cfg!(deny_warnings))
|
2020-11-17 07:43:37 +00:00
|
|
|
.compile("cxxbridge1");
|
2020-11-11 20:00:20 +00:00
|
|
|
|
2020-03-11 23:49:18 +00:00
|
|
|
println!("cargo:rerun-if-changed=src/cxx.cc");
|
|
|
|
println!("cargo:rerun-if-changed=include/cxx.h");
|
2020-08-31 04:03:38 +00:00
|
|
|
println!("cargo:rustc-cfg=built_with_cargo");
|
2020-11-11 20:00:20 +00:00
|
|
|
|
2020-10-08 00:38:59 +00:00
|
|
|
if let Some(manifest_dir) = env::var_os("CARGO_MANIFEST_DIR") {
|
|
|
|
let cxx_h = Path::new(&manifest_dir).join("include").join("cxx.h");
|
|
|
|
println!("cargo:HEADER={}", cxx_h.to_string_lossy());
|
|
|
|
}
|
2020-11-11 20:00:20 +00:00
|
|
|
|
|
|
|
if let Some(rustc) = rustc_version() {
|
2023-01-07 20:37:15 +00:00
|
|
|
if rustc.minor < 60 {
|
|
|
|
println!("cargo:warning=The cxx crate requires a rustc version 1.60.0 or newer.");
|
2020-11-11 20:00:20 +00:00
|
|
|
println!(
|
|
|
|
"cargo:warning=You appear to be building with: {}",
|
|
|
|
rustc.version,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct RustVersion {
|
|
|
|
version: String,
|
|
|
|
minor: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn rustc_version() -> Option<RustVersion> {
|
|
|
|
let rustc = env::var_os("RUSTC")?;
|
|
|
|
let output = Command::new(rustc).arg("--version").output().ok()?;
|
|
|
|
let version = String::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(RustVersion { version, minor })
|
2019-10-20 18:51:12 +00:00
|
|
|
}
|