From b73a2450b46f2176c3bb12664f8cad7335b31ee9 Mon Sep 17 00:00:00 2001 From: Pedro Pelicioni Date: Thu, 13 Feb 2025 16:44:41 -0400 Subject: [PATCH] feat: capture OpenSSL and glibc version in build information Add compile-time detection of OpenSSL and glibc versions to the build information. This enhancement provides additional system context by retrieving and exposing the versions of these critical libraries during the build process. --- build.rs | 26 ++++++++++++++++++++++++++ src/infra/build_info.rs | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/build.rs b/build.rs index ca829ee3c..127e01155 100644 --- a/build.rs +++ b/build.rs @@ -6,6 +6,7 @@ use std::collections::HashSet; use std::env; use std::fs; use std::path::PathBuf; +use std::process::Command; use glob::glob; use nom::bytes::complete::tag; @@ -45,6 +46,31 @@ fn generate_build_info() { // Export BUILD_HOSTNAME as a compile-time environment variable println!("cargo:rustc-env=BUILD_HOSTNAME={}", build_hostname); + // Capture OpenSSL version + let openssl_version = Command::new("openssl") + .arg("version") + .output() + .ok() + .and_then(|output| String::from_utf8(output.stdout).ok()) + .unwrap_or_else(|| "unknown".to_string()); + + // Capture glibc version (Linux only) + let glibc_version = if cfg!(target_os = "linux") { + Command::new("ldd") + .arg("--version") + .output() + .ok() + .and_then(|output| String::from_utf8(output.stdout).ok()) + .and_then(|s| s.lines().next().map(|s| s.to_string())) + .unwrap_or_else(|| "unknown".to_string()) + } else { + "not applicable".to_string() + }; + + // Export as compile-time environment variables + println!("cargo:rustc-env=BUILD_OPENSSL_VERSION={}", openssl_version.trim()); + println!("cargo:rustc-env=BUILD_GLIBC_VERSION={}", glibc_version.trim()); + if let Err(e) = EmitBuilder::builder() .build_timestamp() .git_branch() diff --git a/src/infra/build_info.rs b/src/infra/build_info.rs index 933e35661..7f8f4da9f 100644 --- a/src/infra/build_info.rs +++ b/src/infra/build_info.rs @@ -6,6 +6,8 @@ use crate::alias::JsonValue; // Build constants // ----------------------------------------------------------------------------- pub const BUILD_HOSTNAME: &str = env!("BUILD_HOSTNAME"); +pub const BUILD_OPENSSL_VERSION: &str = env!("BUILD_OPENSSL_VERSION"); +pub const BUILD_GLIBC_VERSION: &str = env!("BUILD_GLIBC_VERSION"); pub const BUILD_TIMESTAMP: &str = env!("VERGEN_BUILD_TIMESTAMP"); pub const CARGO_DEBUG: &str = env!("VERGEN_CARGO_DEBUG"); @@ -69,6 +71,8 @@ pub fn as_json() -> JsonValue { "service_name_with_version": service_name_with_version(), "timestamp": BUILD_TIMESTAMP, "hostname": BUILD_HOSTNAME, + "openssl_version": BUILD_OPENSSL_VERSION, + "glibc_version": BUILD_GLIBC_VERSION, }, "cargo": { "debug": CARGO_DEBUG,