From 992066c60c1bd102a77ac378a05306a7cd314650 Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Fri, 3 Jan 2025 21:01:58 -0600 Subject: [PATCH] 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 --- Cargo.lock | 30 ------------------------------ Cargo.toml | 1 - flake.nix | 6 ++---- lib/Cargo.toml | 1 - lib/src/local_backend.rs | 8 ++++---- 5 files changed, 6 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ab8d5b3a7..69398f4d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2057,7 +2057,6 @@ dependencies = [ "version_check", "watchman_client", "winreg", - "zstd", ] [[package]] @@ -4079,32 +4078,3 @@ dependencies = [ "quote", "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", -] diff --git a/Cargo.toml b/Cargo.toml index 9a29e317a..0068c8acd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -123,7 +123,6 @@ version_check = "0.9.5" watchman_client = { version = "0.9.0" } whoami = "1.5.2" winreg = "0.52" -zstd = "0.12.4" # put all inter-workspace libraries, i.e. those that use 'path = ...' here in # their own (alphabetically sorted) block diff --git a/flake.nix b/flake.nix index c17f18637..1ea1c79a1 100644 --- a/flake.nix +++ b/flake.nix @@ -109,10 +109,9 @@ openssh ] ++ linuxNativeDeps; buildInputs = with pkgs; [ - openssl zstd libgit2 libssh2 + openssl libgit2 libssh2 ] ++ darwinDeps; - ZSTD_SYS_USE_PKG_CONFIG = "1"; LIBSSH2_SYS_USE_PKG_CONFIG = "1"; RUSTFLAGS = pkgs.lib.optionalString pkgs.stdenv.isLinux "-C link-arg=-fuse-ld=mold"; NIX_JJ_GIT_HASH = self.rev or ""; @@ -175,7 +174,7 @@ }) # Foreign dependencies - openssl zstd libgit2 libssh2 + openssl libgit2 libssh2 pkg-config # Additional tools recommended by contributing.md @@ -204,7 +203,6 @@ shellHook = '' export RUST_BACKTRACE=1 - export ZSTD_SYS_USE_PKG_CONFIG=1 export LIBSSH2_SYS_USE_PKG_CONFIG=1 export RUSTFLAGS="-Zthreads=0 ${rustLinkFlagsString}" diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 213a52520..c3ef8de2f 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -74,7 +74,6 @@ tokio = { workspace = true, optional = true } toml_edit = { workspace = true } tracing = { workspace = true } watchman_client = { workspace = true, optional = true } -zstd = { workspace = true } [target.'cfg(unix)'.dependencies] rustix = { workspace = true } diff --git a/lib/src/local_backend.rs b/lib/src/local_backend.rs index 1d218130d..35f10129f 100644 --- a/lib/src/local_backend.rs +++ b/lib/src/local_backend.rs @@ -187,7 +187,7 @@ impl Backend for LocalBackend { async fn read_file(&self, _path: &RepoPath, id: &FileId) -> BackendResult> { let path = self.file_path(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( @@ -196,7 +196,7 @@ impl Backend for LocalBackend { contents: &mut (dyn Read + Send), ) -> BackendResult { 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 buff: Vec = vec![0; 1 << 14]; loop { @@ -205,10 +205,10 @@ impl Backend for LocalBackend { break; } 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); } - encoder.finish().map_err(to_other_err)?; + file.flush().map_err(to_other_err)?; let id = FileId::new(hasher.finalize().to_vec()); persist_content_addressed_temp_file(temp_file, self.file_path(&id))