feat: compile time optimization (#775)

This commit is contained in:
Nishant Joshi
2023-03-21 15:12:44 +05:30
committed by GitHub
parent 575abd6f5e
commit 5b5557b71d
10 changed files with 28 additions and 8 deletions

View File

@ -91,6 +91,7 @@ pub fn workspace_path() -> PathBuf {
/// - Timestamp of the latest git commit.
///
/// Example: `0.1.0-abcd012-2038-01-19T03:14:08Z`.
#[cfg(feature = "vergen")]
#[macro_export]
macro_rules! version {
() => {
@ -117,6 +118,7 @@ macro_rules! version {
/// Example: `0.1.0-f5f383e-2022-09-04T11:39:37Z-1.63.0-x86_64-unknown-linux-gnu`
///
#[cfg(feature = "vergen")]
#[macro_export]
macro_rules! build {
() => {
@ -141,7 +143,7 @@ macro_rules! build {
///
/// Example: `f5f383ee7e36214d60ce3c6353b57db03ff0ceb1`.
///
#[cfg(feature = "vergen")]
#[macro_export]
macro_rules! commit {
() => {

View File

@ -126,7 +126,9 @@ where
hostname: String,
env: String,
service: String,
#[cfg(feature = "vergen")]
version: String,
#[cfg(feature = "vergen")]
build: String,
default_fields: HashMap<String, Value>,
}
@ -159,7 +161,9 @@ where
let pid = std::process::id();
let hostname = gethostname::gethostname().to_string_lossy().into_owned();
let service = service.to_string();
#[cfg(feature = "vergen")]
let version = crate::version!().to_string();
#[cfg(feature = "vergen")]
let build = crate::build!().to_string();
let env = crate::env::which().to_string();
@ -169,7 +173,9 @@ where
hostname,
env,
service,
#[cfg(feature = "vergen")]
version,
#[cfg(feature = "vergen")]
build,
default_fields,
}
@ -195,7 +201,9 @@ where
map_serializer.serialize_entry(HOSTNAME, &self.hostname)?;
map_serializer.serialize_entry(PID, &self.pid)?;
map_serializer.serialize_entry(ENV, &self.env)?;
#[cfg(feature = "vergen")]
map_serializer.serialize_entry(VERSION, &self.version)?;
#[cfg(feature = "vergen")]
map_serializer.serialize_entry(BUILD, &self.build)?;
map_serializer.serialize_entry(LEVEL, &format!("{}", metadata.level()))?;
map_serializer.serialize_entry(TARGET, metadata.target())?;

View File

@ -6,6 +6,7 @@
/// # Panics
///
/// Panics if `vergen` fails to generate `cargo` build instructions.
#[cfg(feature = "vergen")]
#[allow(clippy::expect_used)]
pub fn generate_cargo_instructions() {
use std::io::Write;
@ -31,3 +32,6 @@ pub fn generate_cargo_instructions() {
)
.expect("Failed to set `CARGO_PROFILE` environment variable");
}
#[cfg(not(feature = "vergen"))]
pub fn generate_cargo_instructions() {}