use std::path::Path;
fn version_of(manifest: &str, dep: &str) -> Option<String> {
manifest.lines().find_map(|line| {
let (name, value) = line.split_once('=')?;
if name.trim() != dep {
return None;
}
let value = value.trim();
let quoted = match value.strip_prefix('{') {
Some(table) => table.split_once("version")?.1.split_once('=')?.1,
None => value,
};
Some(quoted.split('"').nth(1)?.to_string())
})
}
fn main() {
let dir = std::env::var("CARGO_MANIFEST_DIR").expect("cargo sets CARGO_MANIFEST_DIR");
let rkyv = Path::new(&dir)
.ancestors()
.filter_map(|p| std::fs::read_to_string(p.join("Cargo.toml")).ok())
.find_map(|m| version_of(&m, "rkyv"))
.expect("rkyv's version: in this manifest or the workspace root's");
println!("cargo:rustc-env=RKYV_VERSION={rkyv}");
}