-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
26 lines (22 loc) · 793 Bytes
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// https://github.com/baoyachi/shadow-rs
use shadow_rs::SdResult;
use std::fs::File;
use std::io::Write;
fn main() -> SdResult<()> {
// Invalidate the build script if DEPLOYMENT_TAG changes
println!("cargo:rerun-if-env-changed=DEPLOYMENT_TAG");
// Generate build information
// https://github.com/baoyachi/shadow-rs
shadow_rs::new_hook(hook)
}
fn hook(file: &File) -> SdResult<()> {
append_deployment_tag(file)?;
Ok(())
}
fn append_deployment_tag(mut file: &File) -> SdResult<()> {
// Read the deployment version from the environment variable
let tag = std::env::var("DEPLOYMENT_TAG").unwrap_or_else(|_| "local".to_string());
let hook_const = format!("pub const DEPLOYMENT_TAG: &str = \"{tag}\";");
writeln!(file, "{hook_const}")?;
Ok(())
}