Files
gamestream-webtransport-proxy/moonlight-common-c-sys/build.rs
T

52 lines
1.7 KiB
Rust

extern crate bindgen;
extern crate cmake;
use std::env;
use std::path::PathBuf;
use bindgen::callbacks::{IntKind, ParseCallbacks};
#[derive(Debug)]
struct CustomCallbacks;
impl ParseCallbacks for CustomCallbacks {
fn int_macro(&self, name: &str, _value: i64) -> Option<IntKind> {
match name {
//"STREAM_CFG_LOCAL" => Some(IntKind::I32),
//"STREAM_CFG_REMOTE" => Some(IntKind::I32),
//"STREAM_CFG_AUTO" => Some(IntKind::I32),
"KEY_ACTION_DOWN" => Some(IntKind::I8),
"KEY_ACTION_UP" => Some(IntKind::I8),
"BUTTON_ACTION_PRESS" => Some(IntKind::I8),
"BUTTON_ACTION_RELEASE" => Some(IntKind::I8),
_ => None, // Default behavior for all others
}
}
}
fn main() {
// Build moonlight-common-c as static library via CMake
let dst = cmake::Config::new("moonlight-common-c")
.define("CMAKE_POLICY_VERSION_MINIMUM", "3.5")
.build();
// Link to static library
println!("cargo:rustc-link-search=native={}/build", dst.display());
println!("cargo:rustc-link-lib=moonlight-common-c");
// Configure bindgen for Limelight.h
let bindings = bindgen::Builder::default()
.header("moonlight-common-c/src/Limelight.h")
.clang_arg(format!("-I{}/src", dst.display())) // Include built headers
.parse_callbacks(Box::new(CustomCallbacks))
.default_macro_constant_type(bindgen::MacroTypeVariation::Signed)
.generate()
.expect("Failed to generate bindings");
// Write bindings to output
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Failed to write bindings");
}