2024-05-28 19:38:43 +02:00
|
|
|
//! Build script generating the C# code needed to call methods from the `servicepoint` C library.
|
|
|
|
|
2024-10-16 21:59:35 +02:00
|
|
|
use std::{fs, path::Path};
|
|
|
|
|
|
|
|
use convert_case::{Case, Casing};
|
2024-09-07 13:34:13 +02:00
|
|
|
|
2024-05-25 11:16:37 +02:00
|
|
|
fn main() {
|
2024-05-30 21:55:55 +02:00
|
|
|
println!("cargo::rerun-if-changed=../servicepoint_binding_c/src");
|
|
|
|
println!("cargo::rerun-if-changed=build.rs");
|
2024-09-07 13:34:13 +02:00
|
|
|
|
2024-10-16 21:59:35 +02:00
|
|
|
let mut paths = fs::read_dir("../servicepoint_binding_c/src")
|
|
|
|
.unwrap()
|
2024-10-16 20:02:35 +02:00
|
|
|
.map(|x| x.unwrap().path())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
paths.sort();
|
|
|
|
|
2024-10-16 21:59:35 +02:00
|
|
|
for path in &paths {
|
2024-09-07 13:34:13 +02:00
|
|
|
println!("cargo:rerun-if-changed={}", path.display());
|
2024-10-16 22:46:34 +02:00
|
|
|
let file: &str = Path::new(path).file_stem().unwrap().to_str().unwrap();
|
2024-10-19 14:21:50 +02:00
|
|
|
if file == "lib" {
|
2024-10-16 22:46:34 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-10-19 14:21:50 +02:00
|
|
|
let class = file.to_case(Case::UpperCamel);
|
2024-10-16 21:59:35 +02:00
|
|
|
csbindgen::Builder::default()
|
|
|
|
.input_extern_file(path)
|
2024-10-19 14:21:50 +02:00
|
|
|
.csharp_class_name(format!("{class}Native"))
|
2024-10-16 21:59:35 +02:00
|
|
|
.csharp_dll_name("servicepoint_binding_c")
|
2024-10-19 14:21:50 +02:00
|
|
|
.csharp_namespace("ServicePoint")
|
2024-10-16 21:59:35 +02:00
|
|
|
.csharp_use_nint_types(true)
|
|
|
|
.csharp_class_accessibility("public")
|
|
|
|
.csharp_generate_const_filter(|_| true)
|
|
|
|
.always_included_types(["SPByteSlice", "SPCompressionCode"])
|
2024-10-19 14:21:50 +02:00
|
|
|
.csharp_group_methods("sp_bitmap_", "Bitmap", "SPBitmap")
|
|
|
|
.csharp_group_methods("sp_bitvec_", "BitVec", "SPBitVec")
|
|
|
|
.csharp_group_methods("sp_command_", "Command", "SPCommand")
|
|
|
|
.csharp_group_methods(
|
|
|
|
"sp_connection_",
|
|
|
|
"Connection",
|
|
|
|
"SPConnection",
|
|
|
|
)
|
|
|
|
.csharp_group_methods("sp_cp437_grid_", "Cp437Grid", "SPCp437Grid")
|
|
|
|
.csharp_group_methods("sp_packet_", "Packet", "SPPacket")
|
|
|
|
.csharp_group_methods(
|
|
|
|
"sp_brightness_grid_",
|
|
|
|
"BrightnessGrid",
|
|
|
|
"SPBrightnessGrid",
|
|
|
|
)
|
2024-10-16 22:46:34 +02:00
|
|
|
.csharp_type_rename(move |name| {
|
2024-10-19 14:21:50 +02:00
|
|
|
if name == "SPCompressionCode"
|
2024-10-16 22:46:34 +02:00
|
|
|
{
|
2024-10-19 14:21:50 +02:00
|
|
|
"CompressionCode".to_string()
|
2024-10-16 22:46:34 +02:00
|
|
|
} else {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
})
|
2024-10-19 14:21:50 +02:00
|
|
|
.generate_csharp_file(format!("ServicePoint/{class}.g.cs"))
|
2024-10-16 21:59:35 +02:00
|
|
|
.unwrap();
|
2024-09-07 13:34:13 +02:00
|
|
|
}
|
2024-05-25 11:16:37 +02:00
|
|
|
}
|