Private
Public Access
1
0
Files
Kordophone/kordophoned/build.rs

56 lines
2.2 KiB
Rust
Raw Normal View History

2025-02-11 23:15:24 -08:00
const KORDOPHONE_XML: &str = "include/net.buzzert.kordophonecd.Server.xml";
fn main() {
2025-07-15 16:39:57 -07:00
// Generate D-Bus code
2025-02-11 23:15:24 -08:00
let out_dir = std::env::var("OUT_DIR").unwrap();
let out_path = std::path::Path::new(&out_dir).join("kordophone-server.rs");
let opts = dbus_codegen::GenOpts {
connectiontype: dbus_codegen::ConnectionType::Nonblock,
methodtype: None, // Set to None for crossroads
crossroads: true,
..Default::default()
};
2025-06-06 16:39:31 -07:00
let xml = std::fs::read_to_string(KORDOPHONE_XML).expect("Error reading server dbus interface");
2025-02-11 23:15:24 -08:00
2025-06-06 16:39:31 -07:00
let output =
dbus_codegen::generate(&xml, &opts).expect("Error generating server dbus interface");
2025-02-11 23:15:24 -08:00
2025-06-06 16:39:31 -07:00
std::fs::write(out_path, output).expect("Error writing server dbus code");
2025-02-11 23:15:24 -08:00
println!("cargo:rerun-if-changed={}", KORDOPHONE_XML);
2025-07-15 16:39:57 -07:00
// Create hybrid version: use Cargo.toml version as base, augment with git info
let cargo_version = env!("CARGO_PKG_VERSION");
let final_version = if let Ok(output) = std::process::Command::new("git")
.args(&["describe", "--tags", "--always", "--dirty"])
.output()
{
let git_desc = String::from_utf8_lossy(&output.stdout).trim().to_string();
// Check if we're on a clean tag that matches the cargo version
if git_desc == format!("v{}", cargo_version) || git_desc == cargo_version {
// Clean release build - just use cargo version
cargo_version.to_string()
} else {
// Development build - append git info
if git_desc.contains("-dirty") {
format!("{}-dev-{}", cargo_version, git_desc)
} else if git_desc.starts_with("v") && git_desc.contains(&format!("v{}", cargo_version)) {
// We're N commits ahead of the tag
format!("{}-dev-{}", cargo_version, git_desc.strip_prefix("v").unwrap_or(&git_desc))
} else {
// Fallback: just append the git description
format!("{}-dev-{}", cargo_version, git_desc)
}
}
} else {
// Git not available - just use cargo version
cargo_version.to_string()
};
println!("cargo:rustc-env=GIT_VERSION={}", final_version);
2025-02-11 23:15:24 -08:00
}