2021-03-29 17:22:14 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
mod linux {
|
|
|
|
use std::{env, path::PathBuf};
|
|
|
|
|
|
|
|
pub fn build_bindings() {
|
2021-11-21 06:33:03 +00:00
|
|
|
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
2021-03-29 17:22:14 +00:00
|
|
|
|
2021-11-21 06:33:03 +00:00
|
|
|
#[cfg(feature = "buildtime_bindgen")]
|
|
|
|
{
|
2021-11-21 06:49:41 +00:00
|
|
|
let bindings = bindgen::Builder::default()
|
2021-11-21 06:33:03 +00:00
|
|
|
.rust_target(bindgen::RustTarget::Stable_1_40)
|
|
|
|
.derive_default(true)
|
|
|
|
.header("c/wireguard.h")
|
|
|
|
.impl_debug(true)
|
|
|
|
.allowlist_function("wg_.*")
|
|
|
|
.bitfield_enum("wg_peer_flags")
|
|
|
|
.bitfield_enum("wg_device_flags");
|
2021-03-29 17:22:14 +00:00
|
|
|
|
2021-11-21 06:33:03 +00:00
|
|
|
let bindings = bindings.generate().expect("Unable to generate bindings");
|
|
|
|
bindings
|
|
|
|
.write_to_file(out_path.join("bindings.rs"))
|
|
|
|
.expect("Couldn't write bindings!");
|
|
|
|
}
|
|
|
|
#[cfg(not(feature = "buildtime_bindgen"))]
|
|
|
|
{
|
|
|
|
std::fs::copy("bindgen-bindings/bindings.rs", out_path.join("bindings.rs"))
|
|
|
|
.expect("Could not copy bindings to output directory");
|
|
|
|
}
|
2021-03-29 17:22:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn build_library() {
|
|
|
|
cc::Build::new()
|
|
|
|
.file("c/wireguard.c")
|
|
|
|
.warnings(true)
|
|
|
|
.extra_warnings(true)
|
|
|
|
.warnings_into_errors(true)
|
|
|
|
.flag_if_supported("-Wno-unused-parameter")
|
|
|
|
.compile("wireguard");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
fn main() {
|
|
|
|
linux::build_bindings();
|
|
|
|
linux::build_library();
|
2021-11-25 15:44:44 +00:00
|
|
|
|
|
|
|
println!("cargo:rerun-if-changed=c/wireguard.c");
|
|
|
|
println!("cargo:rerun-if-changed=c/wireguard.h");
|
2021-03-29 17:22:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "linux"))]
|
|
|
|
fn main() {}
|