relay/src/build.rs

58 lines
1.6 KiB
Rust
Raw Permalink Normal View History

2020-03-20 18:40:18 +00:00
use ructe::Ructe;
2021-09-20 17:49:07 +00:00
use std::{fs::File, io::Read, path::Path, process::Command};
fn git_info() {
if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() {
if output.status.success() {
let git_hash = String::from_utf8_lossy(&output.stdout);
println!("cargo:rustc-env=GIT_HASH={git_hash}");
println!("cargo:rustc-env=GIT_SHORT_HASH={}", &git_hash[..8])
2021-09-20 17:49:07 +00:00
}
}
if let Ok(output) = Command::new("git")
.args(["rev-parse", "--abbrev-ref", "HEAD"])
.output()
{
if output.status.success() {
let git_branch = String::from_utf8_lossy(&output.stdout);
println!("cargo:rustc-env=GIT_BRANCH={git_branch}");
2021-09-20 17:49:07 +00:00
}
}
}
fn version_info() -> Result<(), anyhow::Error> {
let cargo_toml = Path::new(&std::env::var("CARGO_MANIFEST_DIR")?).join("Cargo.toml");
2022-12-19 18:23:06 +00:00
let mut file = File::open(cargo_toml)?;
2021-09-20 17:49:07 +00:00
let mut cargo_data = String::new();
file.read_to_string(&mut cargo_data)?;
let data: toml::Value = toml::from_str(&cargo_data)?;
if let Some(version) = data["package"]["version"].as_str() {
println!("cargo:rustc-env=PKG_VERSION={version}");
2021-09-20 17:49:07 +00:00
}
if let Some(name) = data["package"]["name"].as_str() {
println!("cargo:rustc-env=PKG_NAME={name}");
2021-09-20 17:49:07 +00:00
}
Ok(())
}
2020-03-20 18:40:18 +00:00
fn main() -> Result<(), anyhow::Error> {
dotenv::dotenv().ok();
2021-09-20 17:49:07 +00:00
git_info();
version_info()?;
2020-03-20 18:40:18 +00:00
let mut ructe = Ructe::from_env()?;
let mut statics = ructe.statics()?;
statics.add_sass_file("scss/index.scss")?;
ructe.compile_templates("templates")?;
Ok(())
}