2023-05-14 19:54:17 +00:00
|
|
|
use std::{env, fs, path::Path};
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
|
|
println!("cargo:rerun-if-env-changed=RELEASE_TAG_NAME");
|
|
|
|
println!("cargo:rerun-if-env-changed=CARGO_PKG_VERSION");
|
|
|
|
|
2023-05-22 08:20:59 +00:00
|
|
|
#[cfg(not(debug_assertions))]
|
2023-08-27 13:02:26 +00:00
|
|
|
let (version, release) = {
|
2023-05-14 19:54:17 +00:00
|
|
|
let tag = env::var("RELEASE_TAG_NAME").unwrap_or(String::from("nightly"));
|
|
|
|
|
2023-08-27 13:02:26 +00:00
|
|
|
let release = if tag.starts_with('v') {
|
|
|
|
"Stable"
|
2023-05-14 19:54:17 +00:00
|
|
|
} else {
|
2023-08-27 13:02:26 +00:00
|
|
|
"Nightly"
|
2023-05-22 08:20:59 +00:00
|
|
|
};
|
2023-05-14 19:54:17 +00:00
|
|
|
|
2023-08-27 13:02:26 +00:00
|
|
|
(tag, release)
|
2023-05-14 19:54:17 +00:00
|
|
|
};
|
|
|
|
|
2023-05-22 08:20:59 +00:00
|
|
|
#[cfg(debug_assertions)]
|
2023-08-27 13:02:26 +00:00
|
|
|
let (version, release) = (String::from("debug"), "Debug");
|
2023-05-22 08:20:59 +00:00
|
|
|
|
2023-05-14 19:54:17 +00:00
|
|
|
let meta_file = Path::new(&env::var("OUT_DIR")?).join("meta.rs");
|
|
|
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
let meta = format!(r#"
|
2023-05-21 23:52:00 +00:00
|
|
|
pub const NAME: &str = "Lapce-{release}";
|
2023-05-22 08:20:59 +00:00
|
|
|
pub const VERSION: &str = "{version}";
|
2023-05-14 19:54:17 +00:00
|
|
|
pub const RELEASE: ReleaseType = ReleaseType::{release};
|
|
|
|
"#);
|
|
|
|
|
|
|
|
fs::write(meta_file, meta)?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|