use std::fs::{create_dir, File};
use std::io::{BufWriter, Write};
use cargo_toml::Manifest;
const EGUI_PKG_NAME: &str = "egui";
fn main() {
let toml_path = concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml");
let manifest = Manifest::from_path(toml_path).unwrap_or_else(|_| {
panic!("cargo.toml path `{toml_path}` should exist before the build kicks off");
});
let directory = std::env::var("OUT_DIR").expect("OUT_DIR must exist");
let directory = directory + "/generated";
let _ = create_dir(directory.as_str());
let filepath = directory + "/meta.rs";
let out_file = File::create(filepath).expect("cannot create file");
let mut writer = BufWriter::new(out_file);
writeln!(
writer,
"// THIS IS AN AUTOGENERATED FILE AND SHOULD NOT BE MODIFIED OR SAVED"
)
.expect("failed to write");
let version = manifest.package.unwrap().version;
writeln!(writer, "const EGUI_THEME_VERSION: &str = \"{version}\";").expect("failed to write");
let version = manifest
.dependencies
.get(EGUI_PKG_NAME)
.expect("could not find egui")
.detail()
.unwrap()
.version
.clone()
.unwrap_or_default();
writeln!(writer, "const EGUI_VERSION: &str = \"{version}\";").expect("failed to write");
}