From 5b35cfcfb2ce7a89f5a7cfac85c5d84d22ed475d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Mon, 4 Mar 2024 11:16:48 +0000 Subject: [PATCH] build-information: pick up vergen from consuming crate (#4424) --- .../bin-common/src/build_information/mod.rs | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/common/bin-common/src/build_information/mod.rs b/common/bin-common/src/build_information/mod.rs index a29e5ccf29..7b1a9d3321 100644 --- a/common/bin-common/src/build_information/mod.rs +++ b/common/bin-common/src/build_information/mod.rs @@ -69,6 +69,35 @@ impl BinaryBuildInformation { } } + // Varient where we want to use the metadata generated by vergen in the consuming crate. + pub const fn new_with_local_vergen( + binary_name: &'static str, + build_timestamp: &'static str, + build_version: &'static str, + commit_sha: &'static str, + commit_timestamp: &'static str, + commit_branch: &'static str, + ) -> Self { + let cargo_debug = env!("VERGEN_CARGO_DEBUG"); + let cargo_profile = if const_str::equal!(cargo_debug, "true") { + "debug" + } else { + "release" + }; + + BinaryBuildInformation { + binary_name, + build_timestamp, + build_version, + commit_sha, + commit_timestamp, + commit_branch, + rustc_version: env!("VERGEN_RUSTC_SEMVER"), + rustc_channel: env!("VERGEN_RUSTC_CHANNEL"), + cargo_profile, + } + } + pub fn to_owned(&self) -> BinaryBuildInformationOwned { BinaryBuildInformationOwned { binary_name: self.binary_name.to_owned(), @@ -187,3 +216,33 @@ macro_rules! bin_info_owned { .to_owned() }; } + +// variant that picks up the vergen build information generated by the build.rs in the consumer +// crate. +#[macro_export] +macro_rules! bin_info_local_vergen { + () => { + $crate::build_information::BinaryBuildInformation::new_vergen( + env!("CARGO_PKG_NAME"), + env!("VERGEN_BUILD_TIMESTAMP"), + env!("CARGO_PKG_VERSION"), + env!("VERGEN_GIT_SHA"), + env!("VERGEN_GIT_COMMIT_TIMESTAMP"), + env!("VERGEN_GIT_BRANCH"), + ) + }; +} + +#[macro_export] +macro_rules! bin_info_local_vergen_owned { + () => { + $crate::build_information::BinaryBuildInformation::new_vergen( + env!("CARGO_PKG_NAME"), + env!("VERGEN_BUILD_TIMESTAMP"), + env!("CARGO_PKG_VERSION"), + env!("VERGEN_GIT_SHA"), + env!("VERGEN_GIT_COMMIT_TIMESTAMP"), + env!("VERGEN_GIT_BRANCH"), + ) + }; +}