This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
zhangyang-libzt/pkg/crate/libzt/build.rs

37 lines
1.2 KiB
Rust
Raw Normal View History

2021-05-24 21:29:57 -07:00
extern crate bindgen;
2021-05-30 19:51:26 -07:00
use cmake::Config;
use std::env;
use std::path::PathBuf;
2021-05-24 21:29:57 -07:00
fn main() {
2021-05-30 19:51:26 -07:00
Config::new("src/native").build_target("zt-static").define("ZTS_ENABLE_RUST", "1").out_dir("target").build();
println!("cargo:rustc-link-search=target/build/lib");
println!("cargo:rustc-link-lib=static=zt");
// See here for reasoning: https://flames-of-code.netlify.app/blog/rust-and-cmake-cplusplus/
let target = env::var("TARGET").unwrap();
if target.contains("apple") {
println!("cargo:rustc-link-lib=dylib=c++");
} else if target.contains("linux") {
println!("cargo:rustc-link-lib=dylib=stdc++");
} else {
unimplemented!();
}
2021-05-24 21:29:57 -07:00
2021-05-30 19:51:26 -07:00
//println!("cargo:rustc-env=LLVM_CONFIG_PATH=/usr/local/opt/llvm/bin/llvm-config");
2021-05-24 21:29:57 -07:00
let bindings = bindgen::Builder::default()
2021-05-30 19:51:26 -07:00
.header("src/native/include/ZeroTierSockets.h")
2021-05-24 21:29:57 -07:00
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings");
2021-05-30 19:51:26 -07:00
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
2021-05-24 21:29:57 -07:00
bindings
2021-05-30 19:51:26 -07:00
.write_to_file(out_path.join("libzt.rs"))
2021-05-24 21:29:57 -07:00
.expect("Couldn't write bindings!");
}