1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-28 06:57:46 +00:00

Replace/remove criterion, walkdir, and system-deps

These are giant dependencies that for some reason pull in winapi(???)
and we actually don't need all of their features.

Criterion can be replaced with brunch, a minimalist alternative.

walkdir is replaced with a single function.

system-dep can be replaced with a single line. Eventually I would like
to make it a little bit more than one line, but that's all we need for
now.
This commit is contained in:
Joshua Goins 2024-04-20 11:13:40 -04:00
parent 3e00c35bd8
commit 7c63474175
5 changed files with 46 additions and 36 deletions

View file

@ -15,22 +15,19 @@ readme = "README.md"
lto = true lto = true
[[bench]] [[bench]]
name = "physis_benchmark" name = "benchmark"
harness = false harness = false
[build-dependencies] [[bench]]
system-deps = "6" name = "retail_benchmark"
harness = false
[package.metadata.system-deps] required-features = ["retail_game_testing"]
libunshield = { version = "1.4", feature = "game_install" }
[dev-dependencies] [dev-dependencies]
# used for patch install checking
walkdir = "2"
hmac-sha512 = "1" hmac-sha512 = "1"
# used while rust doesn't have native benchmarking capability # used while rust doesn't have native benchmarking capability
criterion = { version = "0.5.1", default-features = false } brunch = { version = "0.5.3", default-features = false }
# used for testing our jamcrc implementation # used for testing our jamcrc implementation
crc = "3" crc = "3"

14
benches/benchmark.rs Executable file
View file

@ -0,0 +1,14 @@
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
use brunch::Bench;
use physis::index::IndexFile;
fn bench_calculate_hash() {
IndexFile::calculate_hash("exd/root.exl");
}
brunch::benches!(
Bench::new("hash c alc")
.run(bench_calculate_hash),
);

View file

@ -3,19 +3,14 @@
use std::env; use std::env;
use criterion::{Criterion, criterion_group, criterion_main}; use brunch::Bench;
use physis::common::Platform; use physis::common::Platform;
use physis::index::IndexFile;
fn reload_repos() { fn reload_repos() {
let game_dir = env::var("FFXIV_GAME_DIR").unwrap(); let game_dir = env::var("FFXIV_GAME_DIR").unwrap();
physis::gamedata::GameData::from_existing(Platform::Win32, format!("{}/game", game_dir).as_str()).unwrap(); physis::gamedata::GameData::from_existing(Platform::Win32, format!("{}/game", game_dir).as_str()).unwrap();
} }
fn bench_calculate_hash() {
IndexFile::calculate_hash("exd/root.exl");
}
fn fetch_data() { fn fetch_data() {
let game_dir = env::var("FFXIV_GAME_DIR").unwrap(); let game_dir = env::var("FFXIV_GAME_DIR").unwrap();
let mut gamedata = let mut gamedata =
@ -24,15 +19,7 @@ fn fetch_data() {
gamedata.extract("exd/root.exl"); gamedata.extract("exd/root.exl");
} }
fn criterion_benchmark(c: &mut Criterion) { brunch::benches!(
c.bench_function("hash calc", |b| b.iter(bench_calculate_hash)); Bench::new("gamedata reloading repositories").run(reload_repos),
Bench::new("gamedata extract").run(fetch_data),
#[cfg(feature = "retail_game_testing")] );
{
c.bench_function("gamedata reloading repositories", |b| b.iter(reload_repos));
c.bench_function("gamedata extract", |b| b.iter(fetch_data));
}
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

View file

@ -2,5 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
fn main() { fn main() {
system_deps::Config::new().probe().unwrap(); #[cfg(feature = "game_install")]
println!("cargo::rustc-link-lib=unshield");
} }

View file

@ -2,13 +2,13 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
use std::env; use std::env;
use std::fs::read; use std::fs::{read, read_dir};
use std::process::Command; use std::process::Command;
use hmac_sha512::Hash; use hmac_sha512::Hash;
use walkdir::WalkDir;
use physis::patch::apply_patch; use physis::patch::apply_patch;
use std::collections::HashMap; use std::collections::HashMap;
use std::path::{Path, PathBuf};
use physis::common::Platform; use physis::common::Platform;
use physis::fiin::FileInfo; use physis::fiin::FileInfo;
use physis::index; use physis::index;
@ -68,22 +68,32 @@ fn make_temp_install_dir(name: &str) -> String {
game_dir.as_path().to_str().unwrap().parse().unwrap() game_dir.as_path().to_str().unwrap().parse().unwrap()
} }
// Shamelessly taken from https://stackoverflow.com/a/76820878
fn recurse(path: impl AsRef<Path>) -> Vec<PathBuf> {
let Ok(entries) = read_dir(path) else { return vec![] };
entries.flatten().flat_map(|entry| {
let Ok(meta) = entry.metadata() else { return vec![] };
if meta.is_dir() { return recurse(entry.path()); }
if meta.is_file() { return vec![entry.path()]; }
vec![]
}).collect()
}
#[cfg(feature = "patch_testing")] #[cfg(feature = "patch_testing")]
fn fill_dir_hash(game_dir: &str) -> HashMap<String, [u8; 64]> { fn fill_dir_hash(game_dir: &str) -> HashMap<String, [u8; 64]> {
let mut file_hashes: HashMap<String, [u8; 64]> = HashMap::new(); let mut file_hashes: HashMap<String, [u8; 64]> = HashMap::new();
WalkDir::new(game_dir) recurse(game_dir)
.into_iter() .into_iter()
.filter_map(Result::ok)
.filter(|e| !e.file_type().is_dir())
.for_each(|x| { .for_each(|x| {
let file = std::fs::read(x.path()).unwrap(); let path = x.as_path();
let file = std::fs::read(path).unwrap();
let mut hash = Hash::new(); let mut hash = Hash::new();
hash.update(&file); hash.update(&file);
let sha = hash.finalize(); let sha = hash.finalize();
let mut rel_path = x.path(); let mut rel_path = path;
rel_path = rel_path.strip_prefix(game_dir).unwrap(); rel_path = rel_path.strip_prefix(game_dir).unwrap();
file_hashes.insert(rel_path.to_str().unwrap().to_string(), sha); file_hashes.insert(rel_path.to_str().unwrap().to_string(), sha);