lapce/lapce-core/build.rs

39 lines
984 B
Rust
Raw Normal View History

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");
#[cfg(not(debug_assertions))]
let (version, release) = {
2023-05-14 19:54:17 +00:00
let tag = env::var("RELEASE_TAG_NAME").unwrap_or(String::from("nightly"));
let release = if tag.starts_with('v') {
"Stable"
2023-05-14 19:54:17 +00:00
} else {
"Nightly"
};
2023-05-14 19:54:17 +00:00
(tag, release)
2023-05-14 19:54:17 +00:00
};
#[cfg(debug_assertions)]
let (version, release) = (String::from("debug"), "Debug");
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}";
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(())
}