From 7c63474175d570672c2d2ff6a10a922cbbabed49 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 20 Apr 2024 11:13:40 -0400 Subject: [PATCH] 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. --- Cargo.toml | 15 +++++------ benches/benchmark.rs | 14 +++++++++++ ...hysis_benchmark.rs => retail_benchmark.rs} | 25 +++++-------------- build.rs | 4 ++- tests/integration_test.rs | 24 ++++++++++++------ 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100755 benches/benchmark.rs rename benches/{physis_benchmark.rs => retail_benchmark.rs} (51%) mode change 100755 => 100644 diff --git a/Cargo.toml b/Cargo.toml index faa67d7..e6df754 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,22 +15,19 @@ readme = "README.md" lto = true [[bench]] -name = "physis_benchmark" +name = "benchmark" harness = false -[build-dependencies] -system-deps = "6" - -[package.metadata.system-deps] -libunshield = { version = "1.4", feature = "game_install" } +[[bench]] +name = "retail_benchmark" +harness = false +required-features = ["retail_game_testing"] [dev-dependencies] -# used for patch install checking -walkdir = "2" hmac-sha512 = "1" # 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 crc = "3" diff --git a/benches/benchmark.rs b/benches/benchmark.rs new file mode 100755 index 0000000..c31f4b0 --- /dev/null +++ b/benches/benchmark.rs @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2023 Joshua Goins +// 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), +); diff --git a/benches/physis_benchmark.rs b/benches/retail_benchmark.rs old mode 100755 new mode 100644 similarity index 51% rename from benches/physis_benchmark.rs rename to benches/retail_benchmark.rs index 4c2908c..c1d0566 --- a/benches/physis_benchmark.rs +++ b/benches/retail_benchmark.rs @@ -3,36 +3,23 @@ use std::env; -use criterion::{Criterion, criterion_group, criterion_main}; +use brunch::Bench; use physis::common::Platform; -use physis::index::IndexFile; fn reload_repos() { let game_dir = env::var("FFXIV_GAME_DIR").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() { let game_dir = env::var("FFXIV_GAME_DIR").unwrap(); let mut gamedata = physis::gamedata::GameData::from_existing(Platform::Win32, format!("{}/game", game_dir).as_str()).unwrap(); - + gamedata.extract("exd/root.exl"); } -fn criterion_benchmark(c: &mut Criterion) { - c.bench_function("hash calc", |b| b.iter(bench_calculate_hash)); - - #[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); +brunch::benches!( + Bench::new("gamedata reloading repositories").run(reload_repos), + Bench::new("gamedata extract").run(fetch_data), +); diff --git a/build.rs b/build.rs index 36238e0..c86621c 100644 --- a/build.rs +++ b/build.rs @@ -2,5 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later fn main() { - system_deps::Config::new().probe().unwrap(); + #[cfg(feature = "game_install")] + println!("cargo::rustc-link-lib=unshield"); } + diff --git a/tests/integration_test.rs b/tests/integration_test.rs index be6d8a5..61ecabd 100755 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -2,13 +2,13 @@ // SPDX-License-Identifier: GPL-3.0-or-later use std::env; -use std::fs::read; +use std::fs::{read, read_dir}; use std::process::Command; use hmac_sha512::Hash; -use walkdir::WalkDir; use physis::patch::apply_patch; use std::collections::HashMap; +use std::path::{Path, PathBuf}; use physis::common::Platform; use physis::fiin::FileInfo; use physis::index; @@ -68,22 +68,32 @@ fn make_temp_install_dir(name: &str) -> String { game_dir.as_path().to_str().unwrap().parse().unwrap() } +// Shamelessly taken from https://stackoverflow.com/a/76820878 +fn recurse(path: impl AsRef) -> Vec { + 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")] fn fill_dir_hash(game_dir: &str) -> HashMap { let mut file_hashes: HashMap = HashMap::new(); - WalkDir::new(game_dir) + recurse(game_dir) .into_iter() - .filter_map(Result::ok) - .filter(|e| !e.file_type().is_dir()) .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(); hash.update(&file); let sha = hash.finalize(); - let mut rel_path = x.path(); + let mut rel_path = path; rel_path = rel_path.strip_prefix(game_dir).unwrap(); file_hashes.insert(rel_path.to_str().unwrap().to_string(), sha);