Burn cargo version within binary.

This commit is contained in:
Nicolas Patry 2023-05-01 16:11:44 +02:00
parent 15756ba1d4
commit 982a04246b
No known key found for this signature in database
GPG Key ID: 6AE76ACC68FFBAF9
4 changed files with 13 additions and 12 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.idea
target
router/tokenizer.json
launcher/src/versions.rs

View File

@ -2,13 +2,23 @@ use std::fs::File;
use std::io::Write;
use std::process::Command;
pub fn cargo_version() -> Option<String> {
let output = Command::new("cargo").args(&["version"]).output().ok()?;
let output = String::from_utf8(output.stdout).ok()?;
Some(output.trim().to_string())
}
fn main() {
let output = Command::new("git")
.args(&["rev-parse", "HEAD"])
.output()
.unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap().trim().to_string();
let cargo_version = cargo_version().unwrap_or("N/A".to_string());
let mut file = File::create("src/versions.rs").unwrap();
file.write(format!(r#"pub static GIT_HASH: &str = "{git_hash}";"#).as_bytes())
file.write(format!("pub static GIT_HASH: &str = \"{git_hash}\";\n").as_bytes())
.unwrap();
file.write(format!(r#"pub static CARGO_VERSION: &str = "{cargo_version}";"#).as_bytes())
.unwrap();
}

View File

@ -7,12 +7,6 @@ pub fn nvidia_smi() -> Option<String> {
Some(output.trim().to_string())
}
pub fn cargo_version() -> Option<String> {
let output = Command::new("cargo").args(&["version"]).output().ok()?;
let output = String::from_utf8(output.stdout).ok()?;
Some(output.trim().to_string())
}
pub fn docker_image() -> Option<String> {
let output = Command::new("docker")
.args(&[
@ -29,10 +23,7 @@ pub fn docker_image() -> Option<String> {
}
pub fn print_env() {
println!(
"Cargo version: {}",
cargo_version().unwrap_or("N/A".to_string())
);
println!("Cargo version: {}", crate::versions::CARGO_VERSION);
println!("Commit SHA: {}", crate::versions::GIT_HASH);
println!(
"Docker image sha: {}",

View File

@ -1 +0,0 @@
pub static GIT_HASH: &str = "61fd8c3c014d9ea31bc1df736fd276606ce29d66";