forked from rust-lang/cargo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SourceId): use stable hash from rustc-stable-hash
This helps `-Ztrim-paths` build a stable cross-platform path for the registry and git sources. Sources files then can be found from the same path when debugging. It also helps cache registry index all at once for all platforms, for example the use case in rust-lang#14795 (despite they should use `cargo vendor` instead IMO). Some caveats: * Newer cargo will need to re-download files for global caches (index files, git/registry sources). The old cache is still kept and used when running with older cargoes. * Windows is not really covered by the "cross-platform" hash, because path prefix components like `C:` are always there. That means hashes of some sources kind, like local registry and local path, are not going to be real cross-platform stable. There might be hash collisions if you have two registries under the same domain. This won't happen to crates.io, as the infra would have to intentionally put another registry on index.crates.io to collide. We don't consider this is an actual threat model, so we are not going to use any cryptographically secure hash algorithm like BLAKE3. See also <rust-lang#13171 (comment)>
- Loading branch information
Showing
5 changed files
with
80 additions
and
59 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,6 @@ | ||
//! Implementation of a hasher that produces the same values across releases. | ||
//! A hasher that produces the same values across releases and platforms. | ||
//! | ||
//! The hasher should be fast and have a low chance of collisions (but is not | ||
//! sufficient for cryptographic purposes). | ||
#![allow(deprecated)] | ||
use std::hash::{Hasher, SipHasher}; | ||
|
||
#[derive(Clone)] | ||
pub struct StableHasher(SipHasher); | ||
|
||
impl StableHasher { | ||
pub fn new() -> StableHasher { | ||
StableHasher(SipHasher::new()) | ||
} | ||
} | ||
|
||
impl Hasher for StableHasher { | ||
fn finish(&self) -> u64 { | ||
self.0.finish() | ||
} | ||
fn write(&mut self, bytes: &[u8]) { | ||
self.0.write(bytes) | ||
} | ||
} | ||
pub use rustc_stable_hash::StableSipHasher128 as StableHasher; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters