desktop: Use vergen to get version info
This commit is contained in:
parent
f6d0fcf822
commit
01e33d82c9
|
@ -3741,6 +3741,7 @@ dependencies = [
|
|||
"tracing-tracy",
|
||||
"unic-langid",
|
||||
"url",
|
||||
"vergen",
|
||||
"webbrowser",
|
||||
"wgpu",
|
||||
"winapi",
|
||||
|
@ -4967,6 +4968,17 @@ version = "0.8.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||
|
||||
[[package]]
|
||||
name = "vergen"
|
||||
version = "8.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e884903ddba094df9bcdeb43b41170658bb4c2001ca8c47df7368244f4210ee"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"rustversion",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "version-compare"
|
||||
version = "0.1.1"
|
||||
|
|
|
@ -43,6 +43,7 @@ winapi = "0.3.9"
|
|||
|
||||
[build-dependencies]
|
||||
embed-resource = "2"
|
||||
vergen = { version = "8.2.0", features = ["build", "git", "gitcl", "cargo"] }
|
||||
|
||||
[features]
|
||||
default = ["software_video"]
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::error::Error;
|
||||
use vergen::EmitBuilder;
|
||||
|
||||
fn main() {
|
||||
// This build script to generate Git version info is from the rustfmt project
|
||||
|
||||
// Only check .git/HEAD dirty status if it exists - doing so when
|
||||
// building dependent crates may lead to false positives and rebuilds
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
if Path::new(".git/HEAD").exists() {
|
||||
println!("cargo:rerun-if-changed=.git/HEAD");
|
||||
}
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
// Emit version info, and "rerun-if-changed" for relevant files, including build.rs
|
||||
EmitBuilder::builder()
|
||||
.all_build()
|
||||
.all_cargo()
|
||||
.all_git()
|
||||
.emit()?;
|
||||
|
||||
// Embed resource file w/ icon on windows
|
||||
// To allow for cross-compilation, this must not be behind cfg(windows)!
|
||||
|
@ -20,33 +16,13 @@ fn main() {
|
|||
embed_resource::compile("assets/ruffle_desktop.rc", embed_resource::NONE);
|
||||
|
||||
println!("cargo:rerun-if-env-changed=CFG_RELEASE_CHANNEL");
|
||||
if option_env!("CFG_RELEASE_CHANNEL").map_or(true, |c| c == "nightly" || c == "dev") {
|
||||
let channel = channel();
|
||||
if channel == "nightly" || channel == "dev" {
|
||||
println!("cargo:rustc-cfg=nightly");
|
||||
}
|
||||
println!("cargo:rustc-env=CFG_RELEASE_CHANNEL={channel}");
|
||||
|
||||
let out_dir: PathBuf = env::var_os("OUT_DIR")
|
||||
.expect("OUT_DIR environment variable must be set and valid")
|
||||
.into();
|
||||
|
||||
File::create(out_dir.join("version-info.txt"))
|
||||
.expect("Must be able to create a file in OUT_DIR")
|
||||
.write_all(commit_info().as_bytes())
|
||||
.expect("Must be able to write to OUT_DIR");
|
||||
}
|
||||
|
||||
// Try to get hash and date of the last commit on a best effort basis. If anything goes wrong
|
||||
// (git not installed or if this is not a git repository) just return an empty string.
|
||||
fn commit_info() -> String {
|
||||
match (channel(), commit_hash(), commit_date()) {
|
||||
(channel, Some(hash), Some(date)) => format!(
|
||||
"{}-{} ({} {})",
|
||||
option_env!("CARGO_PKG_VERSION").unwrap_or("unknown"),
|
||||
channel,
|
||||
hash.trim_end(),
|
||||
date
|
||||
),
|
||||
_ => String::new(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn channel() -> String {
|
||||
|
@ -56,19 +32,3 @@ fn channel() -> String {
|
|||
"nightly".to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
fn commit_hash() -> Option<String> {
|
||||
Command::new("git")
|
||||
.args(["rev-parse", "--short", "HEAD"])
|
||||
.output()
|
||||
.ok()
|
||||
.and_then(|r| String::from_utf8(r.stdout).ok())
|
||||
}
|
||||
|
||||
fn commit_date() -> Option<String> {
|
||||
Command::new("git")
|
||||
.args(["log", "-1", "--date=short", "--pretty=format:%cd"])
|
||||
.output()
|
||||
.ok()
|
||||
.and_then(|r| String::from_utf8(r.stdout).ok())
|
||||
}
|
||||
|
|
|
@ -40,7 +40,16 @@ thread_local! {
|
|||
static GLOBAL: tracing_tracy::client::ProfiledAllocator<std::alloc::System> =
|
||||
tracing_tracy::client::ProfiledAllocator::new(std::alloc::System, 0);
|
||||
|
||||
static RUFFLE_VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/version-info.txt"));
|
||||
static RUFFLE_VERSION: &str = concat!(
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
"-",
|
||||
env!("CFG_RELEASE_CHANNEL"),
|
||||
" (",
|
||||
env!("VERGEN_GIT_SHA"),
|
||||
" ",
|
||||
env!("VERGEN_GIT_COMMIT_DATE"),
|
||||
")"
|
||||
);
|
||||
|
||||
fn init() {
|
||||
// When linked with the windows subsystem windows won't automatically attach
|
||||
|
|
Loading…
Reference in New Issue