Skip to content

Commit

Permalink
WIP embed git hash in build
Browse files Browse the repository at this point in the history
  • Loading branch information
trumank committed Jun 17, 2024
1 parent 7b6f40f commit ba846e2
Show file tree
Hide file tree
Showing 34 changed files with 112 additions and 25 deletions.
54 changes: 54 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified assets/integration/FSD/Content/_mint/BPL_MINT.uasset
Binary file not shown.
Binary file modified assets/integration/FSD/Content/_mint/BPL_MINT.uexp
Binary file not shown.
38 changes: 36 additions & 2 deletions hook/src/hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ pub unsafe fn initialize() -> Result<()> {
"/Game/_mint/BPL_MINT.BPL_MINT_C:Get Mod JSON",
exec_get_mod_json as ExecFn,
),
(
"/Game/_mint/BPL_MINT.BPL_MINT_C:GetUpdateAvailable",
exec_get_update_available as ExecFn,
),
(
"/Script/Engine.KismetSystemLibrary:PrintString",
exec_print_string as ExecFn,
Expand Down Expand Up @@ -327,7 +331,35 @@ unsafe extern "system" fn exec_get_mod_json(

std::mem::forget(ret);

stack.code = stack.code.add(1);
if !stack.code.is_null() {
stack.code = stack.code.add(1);
}
}

unsafe extern "system" fn exec_get_update_available(
_context: *mut ue::UObject,
stack: *mut ue::kismet::FFrame,
_result: *mut c_void,
) {
let stack = stack.as_mut().unwrap();

let _ctx: Option<&ue::UObject> = stack.arg();

stack.arg::<bool>();
let done_checking = &mut *(stack.most_recent_property_address as *mut bool);
*done_checking = true;

stack.arg::<bool>();
let available = &mut *(stack.most_recent_property_address as *mut bool);
*available = false;

std::mem::forget(stack.arg::<ue::FString>());
let version = &mut *(stack.most_recent_property_address as *mut ue::FString);
*version = ue::FString::new();

if !stack.code.is_null() {
stack.code = stack.code.add(1);
}
}

unsafe extern "system" fn exec_print_string(
Expand All @@ -346,5 +378,7 @@ unsafe extern "system" fn exec_print_string(

println!("PrintString({string})");

stack.code = stack.code.add(1);
if !stack.code.is_null() {
stack.code = stack.code.add(1);
}
}
4 changes: 4 additions & 0 deletions mint_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ authors.workspace = true
license.workspace = true
version.workspace = true
edition.workspace = true
build = "build.rs"

[dependencies]
anyhow.workspace = true
Expand All @@ -18,3 +19,6 @@ tracing-appender.workspace = true
tracing-subscriber.workspace = true
reqwest.workspace = true
snafu.workspace = true

[build-dependencies]
built = { version = "0.7.3", features = ["semver", "git2"] }
4 changes: 4 additions & 0 deletions mint_lib/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
println!("cargo:rerun-if-changed=../.git");
built::write_built_file().expect("Failed to acquire build-time information");
}
9 changes: 9 additions & 0 deletions mint_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ use fs_err as fs;
use tracing::*;
use tracing_subscriber::fmt::format::FmtSpan;

pub mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));

pub fn version() -> &'static str {
GIT_VERSION.unwrap()
}
}

#[derive(Debug)]
pub enum DRGInstallationType {
Steam,
Expand Down Expand Up @@ -202,6 +210,7 @@ pub fn setup_logging<P: AsRef<Path>>(

debug!("tracing subscriber setup");
info!("writing logs to {:?}", log_path.as_ref().display());
info!("version: {}", built_info::version());

Ok(guard)
}
15 changes: 2 additions & 13 deletions mint_lib/src/mod_info.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::BTreeSet, fmt::Display};
use std::collections::BTreeSet;

use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -126,7 +126,7 @@ impl From<&str> for ModIdentifier {
/// Stripped down mod info stored in the mod pak to be used in game
#[derive(Debug, Serialize, Deserialize)]
pub struct Meta {
pub version: SemverVersion,
pub version: String,
pub mods: Vec<MetaMod>,
pub config: MetaConfig,
}
Expand All @@ -135,17 +135,6 @@ pub struct MetaConfig {
pub disable_fix_exploding_gas: bool,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SemverVersion {
pub major: u32,
pub minor: u32,
pub patch: u32,
}
impl Display for SemverVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct MetaMod {
pub name: String,
pub version: String,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn gui(dirs: Dirs, args: Option<Vec<String>>) -> Result<(), MintError> {
..Default::default()
};
eframe::run_native(
&format!("mint {}", env!("CARGO_PKG_VERSION")),
&format!("mint {}", mint_lib::built_info::GIT_VERSION.unwrap()),
options,
Box::new(|cc| Box::new(App::new(cc, dirs, args).unwrap())),
)
Expand Down
11 changes: 2 additions & 9 deletions src/integrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use unreal_asset::AssetBuilder;

use crate::mod_lints::LintError;
use crate::providers::{ModInfo, ProviderError, ReadSeek};
use mint_lib::mod_info::{ApprovalStatus, Meta, MetaConfig, MetaMod, SemverVersion};
use mint_lib::mod_info::{ApprovalStatus, Meta, MetaConfig, MetaMod};
use mint_lib::DRGInstallation;

use unreal_asset::{
Expand Down Expand Up @@ -597,15 +597,8 @@ impl<W: Write + Seek> ModBundleWriter<W> {
config: MetaConfig,
mods: &[(ModInfo, PathBuf)],
) -> Result<(), IntegrationError> {
let mut split = env!("CARGO_PKG_VERSION").split('.');
let version = SemverVersion {
major: split.next().unwrap().parse().unwrap(),
minor: split.next().unwrap().parse().unwrap(),
patch: split.next().unwrap().parse().unwrap(),
};

let meta = Meta {
version,
version: mint_lib::built_info::version().into(),
config,
mods: mods
.iter()
Expand Down

0 comments on commit ba846e2

Please sign in to comment.