lib: remove use of zstd

`zstd` is only used to write files in the native backend right now. For now,
jettison it, to unbundle some C code that we don't really need.

(Ideally, a future compression library would be pure Rust, but we'll cross that
bridge when we get to it...)

Signed-off-by: Austin Seipp <aseipp@pobox.com>
This commit is contained in:
Austin Seipp 2025-01-03 21:01:58 -06:00
parent 02a758964a
commit 992066c60c
5 changed files with 6 additions and 40 deletions

30
Cargo.lock generated
View file

@ -2057,7 +2057,6 @@ dependencies = [
"version_check", "version_check",
"watchman_client", "watchman_client",
"winreg", "winreg",
"zstd",
] ]
[[package]] [[package]]
@ -4079,32 +4078,3 @@ dependencies = [
"quote", "quote",
"syn", "syn",
] ]
[[package]]
name = "zstd"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a27595e173641171fc74a1232b7b1c7a7cb6e18222c11e9dfb9888fa424c53c"
dependencies = [
"zstd-safe",
]
[[package]]
name = "zstd-safe"
version = "6.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee98ffd0b48ee95e6c5168188e44a54550b1564d9d530ee21d5f0eaed1069581"
dependencies = [
"libc",
"zstd-sys",
]
[[package]]
name = "zstd-sys"
version = "2.0.13+zstd.1.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38ff0f21cfee8f97d94cef41359e0c89aa6113028ab0291aa8ca0038995a95aa"
dependencies = [
"cc",
"pkg-config",
]

View file

@ -123,7 +123,6 @@ version_check = "0.9.5"
watchman_client = { version = "0.9.0" } watchman_client = { version = "0.9.0" }
whoami = "1.5.2" whoami = "1.5.2"
winreg = "0.52" winreg = "0.52"
zstd = "0.12.4"
# put all inter-workspace libraries, i.e. those that use 'path = ...' here in # put all inter-workspace libraries, i.e. those that use 'path = ...' here in
# their own (alphabetically sorted) block # their own (alphabetically sorted) block

View file

@ -109,10 +109,9 @@
openssh openssh
] ++ linuxNativeDeps; ] ++ linuxNativeDeps;
buildInputs = with pkgs; [ buildInputs = with pkgs; [
openssl zstd libgit2 libssh2 openssl libgit2 libssh2
] ++ darwinDeps; ] ++ darwinDeps;
ZSTD_SYS_USE_PKG_CONFIG = "1";
LIBSSH2_SYS_USE_PKG_CONFIG = "1"; LIBSSH2_SYS_USE_PKG_CONFIG = "1";
RUSTFLAGS = pkgs.lib.optionalString pkgs.stdenv.isLinux "-C link-arg=-fuse-ld=mold"; RUSTFLAGS = pkgs.lib.optionalString pkgs.stdenv.isLinux "-C link-arg=-fuse-ld=mold";
NIX_JJ_GIT_HASH = self.rev or ""; NIX_JJ_GIT_HASH = self.rev or "";
@ -175,7 +174,7 @@
}) })
# Foreign dependencies # Foreign dependencies
openssl zstd libgit2 libssh2 openssl libgit2 libssh2
pkg-config pkg-config
# Additional tools recommended by contributing.md # Additional tools recommended by contributing.md
@ -204,7 +203,6 @@
shellHook = '' shellHook = ''
export RUST_BACKTRACE=1 export RUST_BACKTRACE=1
export ZSTD_SYS_USE_PKG_CONFIG=1
export LIBSSH2_SYS_USE_PKG_CONFIG=1 export LIBSSH2_SYS_USE_PKG_CONFIG=1
export RUSTFLAGS="-Zthreads=0 ${rustLinkFlagsString}" export RUSTFLAGS="-Zthreads=0 ${rustLinkFlagsString}"

View file

@ -74,7 +74,6 @@ tokio = { workspace = true, optional = true }
toml_edit = { workspace = true } toml_edit = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
watchman_client = { workspace = true, optional = true } watchman_client = { workspace = true, optional = true }
zstd = { workspace = true }
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
rustix = { workspace = true } rustix = { workspace = true }

View file

@ -187,7 +187,7 @@ impl Backend for LocalBackend {
async fn read_file(&self, _path: &RepoPath, id: &FileId) -> BackendResult<Box<dyn Read>> { async fn read_file(&self, _path: &RepoPath, id: &FileId) -> BackendResult<Box<dyn Read>> {
let path = self.file_path(id); let path = self.file_path(id);
let file = File::open(path).map_err(|err| map_not_found_err(err, id))?; let file = File::open(path).map_err(|err| map_not_found_err(err, id))?;
Ok(Box::new(zstd::Decoder::new(file).map_err(to_other_err)?)) Ok(Box::new(file))
} }
async fn write_file( async fn write_file(
@ -196,7 +196,7 @@ impl Backend for LocalBackend {
contents: &mut (dyn Read + Send), contents: &mut (dyn Read + Send),
) -> BackendResult<FileId> { ) -> BackendResult<FileId> {
let temp_file = NamedTempFile::new_in(&self.path).map_err(to_other_err)?; let temp_file = NamedTempFile::new_in(&self.path).map_err(to_other_err)?;
let mut encoder = zstd::Encoder::new(temp_file.as_file(), 0).map_err(to_other_err)?; let mut file = temp_file.as_file();
let mut hasher = Blake2b512::new(); let mut hasher = Blake2b512::new();
let mut buff: Vec<u8> = vec![0; 1 << 14]; let mut buff: Vec<u8> = vec![0; 1 << 14];
loop { loop {
@ -205,10 +205,10 @@ impl Backend for LocalBackend {
break; break;
} }
let bytes = &buff[..bytes_read]; let bytes = &buff[..bytes_read];
encoder.write_all(bytes).map_err(to_other_err)?; file.write_all(bytes).map_err(to_other_err)?;
hasher.update(bytes); hasher.update(bytes);
} }
encoder.finish().map_err(to_other_err)?; file.flush().map_err(to_other_err)?;
let id = FileId::new(hasher.finalize().to_vec()); let id = FileId::new(hasher.finalize().to_vec());
persist_content_addressed_temp_file(temp_file, self.file_path(&id)) persist_content_addressed_temp_file(temp_file, self.file_path(&id))