Skip to content

Commit 97ae01a

Browse files
committed
update to use blake3 instead of xxhash per rustc MCP resolution
1 parent 1bf6fb9 commit 97ae01a

File tree

4 files changed

+47
-31
lines changed

4 files changed

+47
-31
lines changed

Cargo.lock

+32-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ anstream = "0.6.13"
2323
anstyle = "1.0.6"
2424
anyhow = "1.0.82"
2525
base64 = "0.22.1"
26+
blake3 = "1.5.2"
2627
bytesize = "1.3"
2728
cargo = { path = "" }
2829
cargo-credential = { version = "0.4.2", path = "credential/cargo-credential" }
@@ -101,7 +102,6 @@ toml_edit = { version = "0.22.14", features = ["serde"] }
101102
tracing = { version = "0.1.40", default-features = false, features = ["std"] } # be compatible with rustc_log: https://github.com/rust-lang/rust/blob/e51e98dde6a/compiler/rustc_log/Cargo.toml#L9
102103
tracing-chrome = "0.7.2"
103104
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
104-
twox-hash = "1.6.3"
105105
unicase = "2.7.0"
106106
unicode-width = "0.1.12"
107107
unicode-xid = "0.2.4"
@@ -147,6 +147,7 @@ anstream.workspace = true
147147
anstyle.workspace = true
148148
anyhow.workspace = true
149149
base64.workspace = true
150+
blake3.workspace = true
150151
bytesize.workspace = true
151152
cargo-credential.workspace = true
152153
cargo-platform.workspace = true
@@ -200,7 +201,6 @@ toml.workspace = true
200201
toml_edit.workspace = true
201202
tracing = { workspace = true, features = ["attributes"] }
202203
tracing-subscriber.workspace = true
203-
twox-hash.workspace = true
204204
unicase.workspace = true
205205
unicode-width.workspace = true
206206
url.workspace = true

src/cargo/core/compiler/fingerprint/mod.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,6 @@ use serde::de;
381381
use serde::ser;
382382
use serde::{Deserialize, Serialize};
383383
use tracing::{debug, info};
384-
use twox_hash::XxHash64;
385384

386385
use crate::core::compiler::unit_graph::UnitDep;
387386
use crate::core::Package;
@@ -2516,14 +2515,13 @@ pub fn parse_rustc_dep_info(rustc_dep_info: &Path) -> CargoResult<RustcDepInfo>
25162515
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
25172516
pub enum ChecksumAlgo {
25182517
Sha256,
2519-
XxHash,
2518+
Blake3,
25202519
}
25212520

25222521
impl ChecksumAlgo {
25232522
fn hash_len(&self) -> usize {
25242523
match self {
2525-
ChecksumAlgo::Sha256 => 32,
2526-
ChecksumAlgo::XxHash => 8,
2524+
ChecksumAlgo::Sha256 | ChecksumAlgo::Blake3 => 32,
25272525
}
25282526
}
25292527
}
@@ -2534,7 +2532,7 @@ impl FromStr for ChecksumAlgo {
25342532
fn from_str(s: &str) -> Result<Self, Self::Err> {
25352533
match s {
25362534
"sha256" => Ok(Self::Sha256),
2537-
"xxhash" => Ok(Self::XxHash),
2535+
"blake3" => Ok(Self::Blake3),
25382536
_ => Err(InvalidChecksumAlgo {}),
25392537
}
25402538
}
@@ -2544,7 +2542,7 @@ impl Display for ChecksumAlgo {
25442542
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25452543
f.write_str(match self {
25462544
ChecksumAlgo::Sha256 => "sha256",
2547-
ChecksumAlgo::XxHash => "xxhash",
2545+
ChecksumAlgo::Blake3 => "blake3",
25482546
})
25492547
}
25502548
}
@@ -2554,7 +2552,7 @@ pub struct InvalidChecksumAlgo {}
25542552

25552553
impl Display for InvalidChecksumAlgo {
25562554
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
2557-
write!(f, "expected `sha256`, or `xxhash`")
2555+
write!(f, "expected `sha256`, or `blake3`")
25582556
}
25592557
}
25602558

@@ -2573,11 +2571,9 @@ impl Checksum {
25732571
}
25742572

25752573
pub fn compute(algo: ChecksumAlgo, contents: impl Read) -> Result<Self, io::Error> {
2576-
// Buffer size is the same as default for std::io::BufReader.
2577-
// This was completely arbitrary and can probably be improved upon.
2578-
//
2579-
// Mostly I just don't want to read the entire file into memory at once if it's massive.
2580-
let mut buf = vec![0; 8 * 1024];
2574+
// Buffer size is the recommended amount to fully leverage SIMD instructions on AVX-512 as per
2575+
// blake3 documentation.
2576+
let mut buf = vec![0; 16 * 1024];
25812577
let mut ret = Self {
25822578
algo,
25832579
value: [0; 32],
@@ -2617,13 +2613,13 @@ impl Checksum {
26172613
value,
26182614
)?;
26192615
}
2620-
ChecksumAlgo::XxHash => {
2616+
ChecksumAlgo::Blake3 => {
26212617
digest(
2622-
XxHash64::with_seed(0),
2618+
blake3::Hasher::new(),
26232619
|h, b| {
2624-
h.write(b);
2620+
h.update(b);
26252621
},
2626-
|h, out| out.copy_from_slice(&h.finish().to_be_bytes()),
2622+
|h, out| out.copy_from_slice(h.finalize().as_bytes()),
26272623
contents,
26282624
&mut buf,
26292625
value,

src/cargo/core/compiler/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ fn prepare_rustc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult
688688
base.arg("-Z").arg("binary-dep-depinfo");
689689
}
690690
if build_runner.bcx.gctx.cli_unstable().checksum_freshness {
691-
base.arg("-Z").arg("checksum-hash-algorithm=xxhash");
691+
base.arg("-Z").arg("checksum-hash-algorithm=blake3");
692692
}
693693

694694
if is_primary {

0 commit comments

Comments
 (0)