Embed git hash using vergen instead of mach (#30030)

Embed the git hash into the servo binary using vergen instead of using
custom Python code in mach. The benefit here is ones less difference
between a normal cargo run and building via mach in addition to removing
a bunch of code.
This commit is contained in:
Martin Robinson 2023-07-28 07:03:06 +02:00 committed by GitHub
parent 17a5b9200d
commit 2ecdb8f45e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 79 additions and 54 deletions

View file

@ -31,6 +31,7 @@ libloading = "0.5"
[build-dependencies]
gl_generator = "0.14"
serde_json = { workspace = true }
vergen = { version = "8.0.0", features = [ "git", "gitcl" ]}
[features]
debugmozjs = ["libservo/debugmozjs"]

View file

@ -7,11 +7,24 @@ use serde_json::{self, Value};
use std::env;
use std::fs::File;
use std::path::PathBuf;
use vergen::EmitBuilder;
fn main() {
let target = env::var("TARGET").unwrap();
let dest = PathBuf::from(&env::var("OUT_DIR").unwrap());
if let Err(error) = EmitBuilder::builder()
.fail_on_error()
.git_sha(true /* short */)
.emit()
{
println!(
"cargo:warning=Could not generate git version information: {:?}",
error
);
println!("cargo:rustc-env=VERGEN_GIT_SHA=nogit");
}
// Generate GL bindings
// For now, we only support EGL, and only on Windows and Android.
if target.contains("android") || target.contains("windows") {

View file

@ -185,12 +185,11 @@ pub struct ServoGlue {
}
pub fn servo_version() -> String {
let cargo_version = env!("CARGO_PKG_VERSION");
let git_info = option_env!("GIT_INFO");
match git_info {
Some(info) => format!("Servo {}{}", cargo_version, info),
None => format!("Servo {}", cargo_version),
}
format!(
"Servo {}-{}",
env!("CARGO_PKG_VERSION"),
env!("VERGEN_GIT_SHA")
)
}
/// Test if a url is valid.