2024-05-28 19:38:43 +02:00
|
|
|
//! Build script generating the header for the `servicepoint` C library.
|
|
|
|
//!
|
|
|
|
//! When the environment variable `SERVICEPOINT_HEADER_OUT` is set, the header is copied there from
|
|
|
|
//! the out directory. This can be used to use the build script as a command line tool from other
|
|
|
|
//! build tools.
|
|
|
|
|
2024-05-26 11:40:52 +02:00
|
|
|
use std::{env, fs::copy};
|
2024-05-25 11:16:37 +02:00
|
|
|
|
|
|
|
use cbindgen::{generate_with_config, Config};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
2024-05-26 11:40:52 +02:00
|
|
|
println!("cargo::rerun-if-changed={crate_dir}");
|
|
|
|
|
|
|
|
let config =
|
|
|
|
Config::from_file(crate_dir.clone() + "/cbindgen.toml").unwrap();
|
2024-05-25 11:16:37 +02:00
|
|
|
|
2024-05-26 11:40:52 +02:00
|
|
|
let output_dir = env::var("OUT_DIR").unwrap();
|
|
|
|
let header_file = output_dir.clone() + "/servicepoint.h";
|
|
|
|
|
2024-05-26 13:15:11 +02:00
|
|
|
generate_with_config(crate_dir, config)
|
2024-05-26 11:40:52 +02:00
|
|
|
.unwrap()
|
|
|
|
.write_to_file(&header_file);
|
|
|
|
println!("cargo:include={output_dir}");
|
|
|
|
|
|
|
|
println!("cargo::rerun-if-env-changed=SERVICEPOINT_HEADER_OUT");
|
|
|
|
if let Ok(header_out) = env::var("SERVICEPOINT_HEADER_OUT") {
|
|
|
|
let header_copy = header_out + "/servicepoint.h";
|
|
|
|
println!("cargo:warning=Copying header to {header_copy}");
|
|
|
|
copy(header_file, &header_copy).unwrap();
|
|
|
|
println!("cargo::rerun-if-changed={header_copy}");
|
|
|
|
}
|
2024-05-25 11:16:37 +02:00
|
|
|
}
|