Skip to content

Commit

Permalink
feat: capture OpenSSL and glibc version in build information
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pedro-pelicioni-cw committed Feb 13, 2025
1 parent 9b4e5c3 commit b73a245
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
26 changes: 26 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions src/infra/build_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b73a245

Please sign in to comment.