2020-10-31 12:11:10 +09:00
|
|
|
cfg_if::cfg_if! {
|
|
|
|
if #[cfg(windows)] {
|
|
|
|
mod windows;
|
|
|
|
pub use windows::setup;
|
|
|
|
} else if #[cfg(target_os = "macos")] {
|
|
|
|
mod macos;
|
|
|
|
pub use macos::setup;
|
|
|
|
} else {
|
|
|
|
pub fn setup() {
|
|
|
|
setup_napi_feature();
|
2020-09-20 01:28:02 +09:00
|
|
|
}
|
2020-02-18 22:09:17 +09:00
|
|
|
}
|
2020-07-01 21:44:29 +09:00
|
|
|
}
|
|
|
|
|
2020-10-31 12:11:10 +09:00
|
|
|
use std::process::Command;
|
|
|
|
|
2020-10-31 10:29:08 +09:00
|
|
|
pub fn setup_napi_feature() {
|
2020-07-01 21:44:29 +09:00
|
|
|
let napi_version = String::from_utf8(
|
|
|
|
Command::new("node")
|
|
|
|
.args(&["-e", "console.log(process.versions.napi)"])
|
|
|
|
.output()
|
|
|
|
.unwrap()
|
|
|
|
.stdout,
|
|
|
|
)
|
|
|
|
.expect("Get NAPI version failed");
|
|
|
|
|
|
|
|
let napi_version_number = napi_version.trim().parse::<u32>().unwrap();
|
|
|
|
|
2020-07-03 01:31:50 +09:00
|
|
|
if napi_version_number < 2 {
|
2020-07-01 21:44:29 +09:00
|
|
|
panic!("current napi version is too low");
|
|
|
|
}
|
|
|
|
|
2020-07-03 01:31:50 +09:00
|
|
|
if napi_version_number == 2 {
|
2020-07-01 21:44:29 +09:00
|
|
|
println!("cargo:rustc-cfg=napi{}", napi_version_number);
|
2020-02-18 22:09:17 +09:00
|
|
|
} else {
|
2020-07-03 01:31:50 +09:00
|
|
|
for version in 2..(napi_version_number + 1) {
|
2020-07-01 21:44:29 +09:00
|
|
|
println!("cargo:rustc-cfg=napi{}", version);
|
|
|
|
}
|
2020-02-18 22:09:17 +09:00
|
|
|
}
|
|
|
|
}
|