|
1 | | -use vergen_gitcl::{BuildBuilder, Emitter, GitclBuilder}; |
| 1 | +use std::collections::BTreeMap; |
2 | 2 |
|
3 | | -fn main() -> Result<(), Box<dyn std::error::Error>> { |
4 | | - // PROFILE is a standard Cargo build env var; emit it for use via env!() in source. |
5 | | - println!( |
6 | | - "cargo:rustc-env=WALLHACK_BUILD_PROFILE={}", |
7 | | - std::env::var("PROFILE").unwrap_or_else(|_| "unknown".to_string()) |
8 | | - ); |
| 3 | +use vergen_gitcl::{ |
| 4 | + AddCustomEntries, BuildBuilder, CargoRerunIfChanged, CargoWarning, DefaultConfig, Emitter, |
| 5 | + GitclBuilder, |
| 6 | +}; |
| 7 | + |
| 8 | +#[derive(Default)] |
| 9 | +struct WallhackBuildEnv; |
| 10 | + |
| 11 | +impl AddCustomEntries<&str, &str> for WallhackBuildEnv { |
| 12 | + fn add_calculated_entries( |
| 13 | + &self, |
| 14 | + _idempotent: bool, |
| 15 | + cargo_rustc_env_map: &mut BTreeMap<&str, &str>, |
| 16 | + _cargo_rerun_if_changed: &mut CargoRerunIfChanged, |
| 17 | + _cargo_warning: &mut CargoWarning, |
| 18 | + ) -> anyhow::Result<()> { |
| 19 | + let profile = std::env::var("PROFILE").unwrap_or_else(|_| "unknown".to_string()); |
| 20 | + cargo_rustc_env_map.insert("WALLHACK_BUILD_PROFILE", Box::leak(profile.into_boxed_str())); |
| 21 | + Ok(()) |
| 22 | + } |
9 | 23 |
|
| 24 | + fn add_default_entries( |
| 25 | + &self, |
| 26 | + _config: &DefaultConfig, |
| 27 | + _cargo_rustc_env_map: &mut BTreeMap<&str, &str>, |
| 28 | + _cargo_rerun_if_changed: &mut CargoRerunIfChanged, |
| 29 | + _cargo_warning: &mut CargoWarning, |
| 30 | + ) -> anyhow::Result<()> { |
| 31 | + Ok(()) |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +fn main() -> Result<(), Box<dyn std::error::Error>> { |
10 | 36 | Emitter::default() |
11 | 37 | .add_instructions(&BuildBuilder::default().build_timestamp(true).build()?)? |
12 | 38 | .add_instructions(&GitclBuilder::default().sha(true).dirty(true).build()?)? |
| 39 | + .add_custom_instructions(&WallhackBuildEnv)? |
13 | 40 | .emit()?; |
14 | 41 | Ok(()) |
15 | 42 | } |
0 commit comments