Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test: hash value depends on endianness and bitness. #10011

Merged
merged 3 commits into from
Nov 10, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/cargo/core/source/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,13 @@ impl Ord for SourceKind {
// you're able to restore the hash to its original value, please do so!
// Otherwise please just leave a comment in your PR as to why the hash value is
// changing and why the old value can't be easily preserved.
//
// The hash value differs depending on endianess and bit-width since Rust 1.45
// (see https://github.com/rust-lang/rust/issues/74215). We run this test only
// on 64-bit little-endian platforms which are most commonly used for
// development and tested in CI.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the bit about 1.45 or linking to a Rust issue is really all that relevant here, I think the comment can basically say that the hash value here is machine-specific, so this test is limited to run only on machines where the listed value is actually correct. This platform happens to correspond to x86_64 which is used for CI which means we should see failures.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hash-value is machine-specific because of that issue. I think it's not representative of "the whole picture" to say that this test behaviour is "intended for us as developers of Cargo really and not much else." - the hash is used on end-users' filesystems as part of a file path. This is not machine-dependent e.g. when home directories are mounted via NFS and shared across different machines e.g. in a university network.

It may not be a big deal in this particular case, at the very least it will result in some duplication, but I think it's important to understand what the consequences are in the wider context of general computing environments rather than wave it away as a "developer-only" issue.

Stable hashing is a really nice thing to have for protocols and other situations where you want to interoperate, and it's a shame if the Rust standard library wouldn't support it.

Copy link
Contributor

@infinity0 infinity0 Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment in src/cargo/core/compiler/fingerprint.rs suggests that StableHasher was originally intended to be platform-independent (as would be a reasonable assumption from the naming):

//! Note: Fingerprinting is not a perfect solution. Filesystem mtime tracking
//! is notoriously imprecise and problematic. Only a small part of the
//! environment is captured. This is a balance of performance, simplicity, and
//! completeness. Sandboxing, hashing file contents, tracking every file
//! access, environment variable, and network operation would ensure more
//! reliable and reproducible builds at the cost of being complex, slow, and
//! platform-dependent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok well in that case I'll leave this to the tagged reviewer.

Copy link
Contributor Author

@hkratz hkratz Oct 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok well in that case I'll leave this to the tagged reviewer.

@alexcrichton Oh, I did not see that reply when commenting (below). 😦

hkratz marked this conversation as resolved.
Show resolved Hide resolved
#[test]
#[cfg(all(target_endian = "little", target_pointer_width = "64"))]
fn test_cratesio_hash() {
let config = Config::default().unwrap();
let crates_io = SourceId::crates_io(&config).unwrap();
Expand Down