dbus-ai/build.rs
2025-04-19 21:51:44 +02:00

27 lines
721 B
Rust

use dbus_codegen::{GenOpts, generate};
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;
fn write_to_file(code: &str, path: &Path) {
let mut f = File::create(path).unwrap();
Write::write_all(&mut f, code.as_bytes()).unwrap();
}
fn generate_code(xml: &str, opts: &GenOpts, outfile: &str) {
let code = generate(xml, opts).unwrap();
let out_dir = env::var("OUT_DIR").unwrap();
let path = Path::new(&out_dir).join(outfile);
println!("cargo::warning={:?}", path);
write_to_file(&code, &path);
}
fn main() {
let opts = GenOpts::default();
generate_code(
include_str!("dbus/com.example.mytest.xml"),
&opts,
"com_example_mytest.rs",
);
}