proxmox-backup-qemu/build.rs
Stefan Reiter 2eb96573b8 include crate version and git rev in header file
...so we can get the library version a binary is currently running with.

Version information is retrieved from the build environment (set by
cargo/make) and appended using 'with_after_include' to appear within the
include guard.

The version string in current-api.h is inconsequential, so ignore it in
diff. This way we only have to re-commit that file whenever the *actual*
API changes, not the version.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>

modified to avoid spawning subcommands

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-11-11 15:22:35 +01:00

33 lines
919 B
Rust

// build.rs
extern crate cbindgen;
use std::env;
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let header = std::fs::read_to_string("header-preamble.c").unwrap();
let crate_ver = env!("CARGO_PKG_VERSION");
let git_ver = match option_env!("GITVERSION") {
Some(ver) if !ver.is_empty() => ver,
_ => "UNKNOWN",
};
let version_define = format!(
"\n#define PROXMOX_BACKUP_QEMU_VERSION \"{} ({})\"",
crate_ver,
git_ver,
);
cbindgen::Builder::new()
.with_language(cbindgen::Language::C)
.with_crate(&crate_dir)
.with_header(header)
.with_include_guard("PROXMOX_BACKUP_QEMU_H")
.with_after_include(version_define)
.generate()
.unwrap()
.write_to_file("proxmox-backup-qemu.h");
println!("cargo:rustc-cdylib-link-arg=-Wl,-soname,libproxmox_backup_qemu.so.0");
}