Skip to content

Commit 40be2d0

Browse files
committed
update to use blake3 instead of xxhash per rustc MCP resolution
1 parent 39f61cf commit 40be2d0

File tree

4 files changed

+47
-31
lines changed

4 files changed

+47
-31
lines changed

Cargo.lock

Lines changed: 32 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ anstream = "0.6.15"
2323
anstyle = "1.0.8"
2424
anyhow = "1.0.86"
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" }
@@ -103,7 +104,6 @@ toml_edit = { version = "0.22.20", features = ["serde"] }
103104
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
104105
tracing-chrome = "0.7.2"
105106
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
106-
twox-hash = "1.6.3"
107107
unicase = "2.7.0"
108108
unicode-width = "0.2.0"
109109
unicode-xid = "0.2.4"
@@ -149,6 +149,7 @@ anstream.workspace = true
149149
anstyle.workspace = true
150150
anyhow.workspace = true
151151
base64.workspace = true
152+
blake3.workspace = true
152153
bytesize.workspace = true
153154
cargo-credential.workspace = true
154155
cargo-platform.workspace = true
@@ -203,7 +204,6 @@ toml.workspace = true
203204
toml_edit.workspace = true
204205
tracing = { workspace = true, features = ["attributes"] }
205206
tracing-subscriber.workspace = true
206-
twox-hash.workspace = true
207207
unicase.workspace = true
208208
unicode-width.workspace = true
209209
url.workspace = true

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

Lines changed: 12 additions & 16 deletions
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;
@@ -2494,14 +2493,13 @@ pub fn parse_rustc_dep_info(rustc_dep_info: &Path) -> CargoResult<RustcDepInfo>
24942493
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
24952494
pub enum ChecksumAlgo {
24962495
Sha256,
2497-
XxHash,
2496+
Blake3,
24982497
}
24992498

25002499
impl ChecksumAlgo {
25012500
fn hash_len(&self) -> usize {
25022501
match self {
2503-
ChecksumAlgo::Sha256 => 32,
2504-
ChecksumAlgo::XxHash => 8,
2502+
ChecksumAlgo::Sha256 | ChecksumAlgo::Blake3 => 32,
25052503
}
25062504
}
25072505
}
@@ -2512,7 +2510,7 @@ impl FromStr for ChecksumAlgo {
25122510
fn from_str(s: &str) -> Result<Self, Self::Err> {
25132511
match s {
25142512
"sha256" => Ok(Self::Sha256),
2515-
"xxhash" => Ok(Self::XxHash),
2513+
"blake3" => Ok(Self::Blake3),
25162514
_ => Err(InvalidChecksumAlgo {}),
25172515
}
25182516
}
@@ -2522,7 +2520,7 @@ impl Display for ChecksumAlgo {
25222520
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25232521
f.write_str(match self {
25242522
ChecksumAlgo::Sha256 => "sha256",
2525-
ChecksumAlgo::XxHash => "xxhash",
2523+
ChecksumAlgo::Blake3 => "blake3",
25262524
})
25272525
}
25282526
}
@@ -2532,7 +2530,7 @@ pub struct InvalidChecksumAlgo {}
25322530

25332531
impl Display for InvalidChecksumAlgo {
25342532
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
2535-
write!(f, "expected `sha256`, or `xxhash`")
2533+
write!(f, "expected `sha256`, or `blake3`")
25362534
}
25372535
}
25382536

@@ -2551,11 +2549,9 @@ impl Checksum {
25512549
}
25522550

25532551
pub fn compute(algo: ChecksumAlgo, contents: impl Read) -> Result<Self, io::Error> {
2554-
// Buffer size is the same as default for std::io::BufReader.
2555-
// This was completely arbitrary and can probably be improved upon.
2556-
//
2557-
// Mostly I just don't want to read the entire file into memory at once if it's massive.
2558-
let mut buf = vec![0; 8 * 1024];
2552+
// Buffer size is the recommended amount to fully leverage SIMD instructions on AVX-512 as per
2553+
// blake3 documentation.
2554+
let mut buf = vec![0; 16 * 1024];
25592555
let mut ret = Self {
25602556
algo,
25612557
value: [0; 32],
@@ -2595,13 +2591,13 @@ impl Checksum {
25952591
value,
25962592
)?;
25972593
}
2598-
ChecksumAlgo::XxHash => {
2594+
ChecksumAlgo::Blake3 => {
25992595
digest(
2600-
XxHash64::with_seed(0),
2596+
blake3::Hasher::new(),
26012597
|h, b| {
2602-
h.write(b);
2598+
h.update(b);
26032599
},
2604-
|h, out| out.copy_from_slice(&h.finish().to_be_bytes()),
2600+
|h, out| out.copy_from_slice(h.finalize().as_bytes()),
26052601
contents,
26062602
&mut buf,
26072603
value,

src/cargo/core/compiler/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ fn prepare_rustc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult
705705
base.arg("-Z").arg("binary-dep-depinfo");
706706
}
707707
if build_runner.bcx.gctx.cli_unstable().checksum_freshness {
708-
base.arg("-Z").arg("checksum-hash-algorithm=xxhash");
708+
base.arg("-Z").arg("checksum-hash-algorithm=blake3");
709709
}
710710

711711
if is_primary {

0 commit comments

Comments
 (0)