Skip to content

Commit

Permalink
Rollup merge of rust-lang#131908 - aDotInTheVoid:rustdoc-gamer-hashin…
Browse files Browse the repository at this point in the history
…g, r=notriddle,GuillaumeGomez

rustdoc: Switch from FxHash to sha256 for static file hashing.

Fixes rust-lang#129533 (comment)

fxhash isn't well defined, and it's implementation is being changed in rust-lang#129533. But because rustdoc uses it for static files (and encodes that hashing in rustdoc.css), this broke our tests. Given that this isn't performace critical, I think the right fix is to used a well-defined hash that will never change its definition. I've picked (rather arbitrarily) sha256.
  • Loading branch information
matthiaskrgr authored Oct 19, 2024
2 parents 37a7e48 + 3cf8a61 commit 9f162e1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4584,6 +4584,7 @@ dependencies = [
"rustdoc-json-types",
"serde",
"serde_json",
"sha2",
"smallvec",
"tempfile",
"threadpool",
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ tracing = "0.1"
tracing-tree = "0.3.0"
threadpool = "1.8.1"
unicode-segmentation = "1.9"
sha2 = "0.10.8"

[dependencies.tracing-subscriber]
version = "0.3.3"
Expand Down
18 changes: 9 additions & 9 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ xmlns="http://www.w3.org/2000/svg" fill="black" height="18px">\
font-style: normal;
font-weight: 400;
src: local('Fira Sans'),
url("FiraSans-Regular-018c141bf0843ffd.woff2") format("woff2");
url("FiraSans-Regular-0fe48ade.woff2") format("woff2");
font-display: swap;
}
@font-face {
font-family: 'Fira Sans';
font-style: normal;
font-weight: 500;
src: local('Fira Sans Medium'),
url("FiraSans-Medium-8f9a781e4970d388.woff2") format("woff2");
url("FiraSans-Medium-e1aa3f0a.woff2") format("woff2");
font-display: swap;
}

Expand All @@ -62,23 +62,23 @@ xmlns="http://www.w3.org/2000/svg" fill="black" height="18px">\
font-style: normal;
font-weight: 400;
src: local('Source Serif 4'),
url("SourceSerif4-Regular-46f98efaafac5295.ttf.woff2") format("woff2");
url("SourceSerif4-Regular-6b053e98.ttf.woff2") format("woff2");
font-display: swap;
}
@font-face {
font-family: 'Source Serif 4';
font-style: italic;
font-weight: 400;
src: local('Source Serif 4 Italic'),
url("SourceSerif4-It-acdfaf1a8af734b1.ttf.woff2") format("woff2");
url("SourceSerif4-It-ca3b17ed.ttf.woff2") format("woff2");
font-display: swap;
}
@font-face {
font-family: 'Source Serif 4';
font-style: normal;
font-weight: 700;
src: local('Source Serif 4 Bold'),
url("SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2") format("woff2");
url("SourceSerif4-Bold-6d4fd4c0.ttf.woff2") format("woff2");
font-display: swap;
}

Expand All @@ -89,28 +89,28 @@ xmlns="http://www.w3.org/2000/svg" fill="black" height="18px">\
font-weight: 400;
/* Avoid using locally installed font because bad versions are in circulation:
* see https://github.com/rust-lang/rust/issues/24355 */
src: url("SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2") format("woff2");
src: url("SourceCodePro-Regular-8badfe75.ttf.woff2") format("woff2");
font-display: swap;
}
@font-face {
font-family: 'Source Code Pro';
font-style: italic;
font-weight: 400;
src: url("SourceCodePro-It-1cc31594bf4f1f79.ttf.woff2") format("woff2");
src: url("SourceCodePro-It-fc8b9304.ttf.woff2") format("woff2");
font-display: swap;
}
@font-face {
font-family: 'Source Code Pro';
font-style: normal;
font-weight: 600;
src: url("SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2") format("woff2");
src: url("SourceCodePro-Semibold-aa29a496.ttf.woff2") format("woff2");
font-display: swap;
}

/* Avoid using legacy CJK serif fonts in Windows like Batang. */
@font-face {
font-family: 'NanumBarunGothic';
src: url("NanumBarunGothic-0f09457c7a19b7c6.ttf.woff2") format("woff2");
src: url("NanumBarunGothic-13b3dcba.ttf.woff2") format("woff2");
font-display: swap;
unicode-range: U+AC00-D7AF, U+1100-11FF, U+3130-318F, U+A960-A97F, U+D7B0-D7FF;
}
Expand Down
11 changes: 5 additions & 6 deletions src/librustdoc/html/static_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
//! All the static files are included here for centralized access in case anything other than the
//! HTML rendering code (say, the theme checker) needs to access one of these files.
use std::hash::Hasher;
use std::path::{Path, PathBuf};
use std::{fmt, str};

use rustc_data_structures::fx::FxHasher;

pub(crate) struct StaticFile {
pub(crate) filename: PathBuf,
pub(crate) bytes: &'static [u8],
Expand Down Expand Up @@ -64,9 +61,11 @@ pub(crate) fn static_filename(filename: &str, contents: &[u8]) -> PathBuf {
}

fn static_suffix(bytes: &[u8]) -> String {
let mut hasher = FxHasher::default();
hasher.write(bytes);
format!("-{:016x}", hasher.finish())
use sha2::Digest;
let bytes = sha2::Sha256::digest(bytes);
let mut digest = format!("-{bytes:x}");
digest.truncate(9);
digest
}

macro_rules! static_files {
Expand Down

0 comments on commit 9f162e1

Please sign in to comment.