mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-25 22:07:44 +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:
parent
3e00c35bd8
commit
7c63474175
5 changed files with 46 additions and 36 deletions
15
Cargo.toml
15
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"
|
||||
|
|
14
benches/benchmark.rs
Executable file
14
benches/benchmark.rs
Executable 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),
|
||||
);
|
25
benches/physis_benchmark.rs → benches/retail_benchmark.rs
Executable file → Normal file
25
benches/physis_benchmark.rs → benches/retail_benchmark.rs
Executable file → Normal file
|
@ -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),
|
||||
);
|
4
build.rs
4
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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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<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")]
|
||||
fn fill_dir_hash(game_dir: &str) -> HashMap<String, [u8; 64]> {
|
||||
let mut file_hashes: HashMap<String, [u8; 64]> = 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);
|
||||
|
|
Loading…
Add table
Reference in a new issue