Skip to content

Commit

Permalink
rustdoc: Switch from FxHash to sha256 for static file hashing.
Browse files Browse the repository at this point in the history
  • Loading branch information
aDotInTheVoid committed Oct 18, 2024
1 parent b0c2d2e commit 9393a0e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4608,6 +4608,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-0fe48aded097c2a1.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-e1aa3f0abca6fd9f.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-6b053e98f0838afe.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-ca3b17ed1e3e668f.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-6d4fd4c0f08798a4.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-8badfe75c98da1e8.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-fc8b9304b4a16c34.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-aa29a496301cce84.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-13b3dcbae3b29c19.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
10 changes: 5 additions & 5 deletions src/librustdoc/html/static_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +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,
Expand Down Expand Up @@ -64,9 +62,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(17);
digest
}

macro_rules! static_files {
Expand Down

0 comments on commit 9393a0e

Please sign in to comment.