utils: Export build ID values from rust scx_utils

We want schedulers to be able to print, log, etc the build ID of the
repository. To do this, we can use the vergen Cargo crate to generate
environment variables that contain values that we can export from scx_utils.

This patch update scx_utils accordingly to use vergen to generate build
ID output that can be printed from schedulers. A subsequent patch will
update scx_rusty to print this build ID value.

Signed-off-by: David Vernet <void@manifault.com>
This commit is contained in:
David Vernet 2024-06-18 23:07:29 -05:00
parent 9d9ece11aa
commit 2aa8bbc32d
No known key found for this signature in database
GPG Key ID: 59E4B86965C4F364
4 changed files with 70 additions and 1 deletions

View File

@ -31,4 +31,5 @@ metrics-util = "0.17.0"
[build-dependencies]
bindgen = ">=0.68, <0.70"
tar = "0.4"
vergen = { version = "8.0.0", features = ["cargo", "git", "gitcl"] }
walkdir = "2.4"

View File

@ -3,8 +3,14 @@
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2.
use vergen::EmitBuilder;
include!("src/builder.rs");
fn main() {
Builder::new().build()
Builder::new().build();
EmitBuilder::builder()
.all_git()
.cargo_target_triple()
.emit()
.unwrap();
}

View File

@ -0,0 +1,61 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2.
use std::fmt::Write;
lazy_static::lazy_static! {
static ref GIT_VERSION: String = {
let mut ver = String::new();
match option_env!("VERGEN_GIT_SHA") {
Some(v) if v != "VERGEN_IDEMPOTENT_OUTPUT" => {
ver += "g";
ver += v;
if let Some("true") = option_env!("VERGEN_GIT_DIRTY") {
ver += "-dirty";
}
}
_ => {}
}
ver
};
static ref BUILD_TAG: String = {
let mut tag = env!("VERGEN_CARGO_TARGET_TRIPLE").to_string();
if cfg!(debug_assertions) {
write!(tag, "/debug").unwrap();
}
tag
};
}
fn full_version(semver: &str) -> String {
let mut ver = semver.to_string();
if GIT_VERSION.len() > 0 {
write!(ver, "-{}", &*GIT_VERSION).unwrap();
}
if BUILD_TAG.len() > 0 {
write!(ver, " {}", &*BUILD_TAG).unwrap();
}
ver
}
lazy_static::lazy_static! {
pub static ref SCX_CARGO_VERSION: &'static str = env!("CARGO_PKG_VERSION");
pub static ref SCX_FULL_VERSION: String = full_version(*SCX_CARGO_VERSION);
}
#[cfg(test)]
mod tests {
#[test]
fn test_cargo_ver() {
//assert_eq!(super::*SCX_CARGO_VERSION, 1);
println!("{}", super::*SCX_CARGO_VERSION);
}
#[test]
fn test_full_ver() {
//assert_eq!(super::*SCX_CARGO_VERSION, 1);
println!("{}", super::*SCX_FULL_VERSION);
}
}

View File

@ -50,6 +50,7 @@ pub use user_exit_info::UeiDumpPtr;
pub use user_exit_info::UserExitInfo;
pub use user_exit_info::UEI_DUMP_PTR_MUTEX;
pub mod build_id;
pub mod compat;
mod libbpf_logger;