mirror of
https://github.com/EasyTier/kcp-sys.git
synced 2025-05-19 10:31:09 +00:00
34 lines
1.1 KiB
Rust
34 lines
1.1 KiB
Rust
use std::env;
|
|
use std::path::{Path, PathBuf};
|
|
|
|
fn main() {
|
|
println!("cargo:rustc-link-lib=kcp");
|
|
let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
|
let fulldir = Path::new(&dir).join("kcp");
|
|
|
|
let mut config = cc::Build::new();
|
|
config.include(fulldir.clone());
|
|
config.file(fulldir.join("ikcp.c"));
|
|
config.opt_level(3);
|
|
config.warnings(false);
|
|
config.compile("libkcp.a");
|
|
println!("cargo:rustc-link-search=native={}", fulldir.display());
|
|
|
|
println!("cargo:rerun-if-changed=kcp/ikcp.h");
|
|
println!("cargo:rerun-if-changed=kcp/ikcp.c");
|
|
println!("cargo:rerun-if-changed=wrapper.h");
|
|
|
|
let bindings = bindgen::Builder::default()
|
|
.header("wrapper.h")
|
|
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
|
.allowlist_function("ikcp_.*")
|
|
.use_core()
|
|
.generate()
|
|
.expect("Unable to generate bindings");
|
|
|
|
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
|
bindings
|
|
.write_to_file(out_path.join("bindings.rs"))
|
|
.expect("Couldn't write bindings!");
|
|
}
|