Problem
-Zchecksum-hash-algorithm writes magic comments to dep-info files to info build tool like Cargo about source file checksum and file length
# checksum:{checksum_hash} file_len:{file_len} {path}
|
// If caller requested this information, add special comments about source file checksums. |
|
// These are not necessarily the same checksums as was used in the debug files. |
|
if sess.opts.unstable_opts.checksum_hash_algorithm().is_some() { |
|
files |
|
.iter() |
|
.filter_map(|(path, file_len, hash_algo)| { |
|
hash_algo.map(|hash_algo| (path, file_len, hash_algo)) |
|
}) |
|
.try_for_each(|(path, file_len, checksum_hash)| { |
|
writeln!(file, "# checksum:{checksum_hash} file_len:{file_len} {path}") |
|
})?; |
|
} |
However, the above code uses SourceFile.source_len from SourceMap that the length of the file is normalized length (BOM-removed, newline normalized). That makes external tools harder to verify the checksum, as they need to follow all the normalizations rustc did to compute exact the same checksum
Possible solution
Instead of using normalized file length, SourceFile should keep the original file length, and serialize it to dep-info file correctly.
Meta
rustc 1.93.0-nightly (bd3ac0330 2025-11-01)
6d41834
Cargo issue: rust-lang/cargo#16253
Problem
-Zchecksum-hash-algorithmwrites magic comments to dep-info files to info build tool like Cargo about source file checksum and file lengthrust/compiler/rustc_interface/src/passes.rs
Lines 747 to 758 in d6deffe
However, the above code uses
SourceFile.source_lenfromSourceMapthat the length of the file is normalized length (BOM-removed, newline normalized). That makes external tools harder to verify the checksum, as they need to follow all the normalizations rustc did to compute exact the same checksumPossible solution
Instead of using normalized file length,
SourceFileshould keep the original file length, and serialize it to dep-info file correctly.Meta
6d41834
Cargo issue: rust-lang/cargo#16253