Skip to content

Commit

Permalink
switch to zstd for asset archive
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Apr 19, 2024
1 parent 7ec3b18 commit f64e7bd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 28 deletions.
59 changes: 40 additions & 19 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ tokio = { version = "1", features = ["rt", "macros", "sync", "time", "signal", "
url = "2"
serde_repr = "0.1"
webpki-roots = "0.26"
xz2 = { version = "0.1", features = ["static"] }
ar = "0.9"
quick-xml = { version = "0.31", features = ["serialize"] }
semver = "1"
futures-util = "0.3"
self-replace = "1"
zstd = { version = "0.13", default-features = false }

[target.'cfg(target_arch = "x86_64")'.dependencies]
raw-cpuid = "11"

[build-dependencies]
glob = "0.3"
xz2 = "0.1"
ar = "0.9"
zstd = { version = "0.13", default-features = false }

[target.'cfg(windows)'.build-dependencies]
winres = "0.1"
13 changes: 8 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{env, fs, fs::File, io::Write, path::Path, process::Command};

use glob::glob;
use xz2::write::XzEncoder;
use zstd::stream::write::Encoder as ZstdEncoder;

const EVAL_FILE: &str = "nn-b1a57edbea57.nnue";
const EVAL_FILE_SMALL: &str = "nn-baff1ede1f90.nnue";
Expand All @@ -16,10 +16,13 @@ fn main() {

hooks();

let mut archive = ar::Builder::new(XzEncoder::new(
File::create(Path::new(&env::var("OUT_DIR").unwrap()).join("assets.ar.xz")).unwrap(),
6,
));
let mut archive = ar::Builder::new(
ZstdEncoder::new(
File::create(Path::new(&env::var("OUT_DIR").unwrap()).join("assets.ar.xz")).unwrap(),
6,
)
.unwrap(),
);
stockfish_build(&mut archive);
stockfish_eval_file(EVAL_FILE, &mut archive);
stockfish_eval_file(EVAL_FILE_SMALL, &mut archive);
Expand Down
4 changes: 2 additions & 2 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ar::Archive;
use bitflags::bitflags;
use serde::Serialize;
use tempfile::TempDir;
use xz2::read::XzDecoder;
use zstd::stream::read::Decoder as ZstdDecoder;

static ASSETS_AR_XZ: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/assets.ar.xz"));

Expand Down Expand Up @@ -189,7 +189,7 @@ impl Assets {
let mut stockfish = ByEngineFlavor::<Option<PathBuf>>::default();
let dir = tempfile::Builder::new().prefix("fishnet-").tempdir()?;

let mut archive = Archive::new(XzDecoder::new(ASSETS_AR_XZ));
let mut archive = Archive::new(ZstdDecoder::new(ASSETS_AR_XZ)?);
while let Some(entry) = archive.next_entry() {
let mut entry = entry?;
let filename = str::from_utf8(entry.header().identifier()).expect("utf-8 filename");
Expand Down

0 comments on commit f64e7bd

Please sign in to comment.