Skip to content

Commit e0463df

Browse files
committed
re-add --disable-minification to rustdoc
this also makes the rust.docs-minification option work as advertised in config.toml nothing fancy this time, this is intended to be perma-unstable. it's only really here for the benefit of rustdoc devs. mitegates #135345
1 parent 251206c commit e0463df

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/librustdoc/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ pub(crate) struct RenderOptions {
303303
pub(crate) include_parts_dir: Vec<PathToParts>,
304304
/// Where to write crate-info
305305
pub(crate) parts_out_dir: Option<PathToParts>,
306+
/// disable minification of CSS/JS
307+
pub(crate) disable_minification: bool,
306308
}
307309

308310
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -781,6 +783,9 @@ impl Options {
781783

782784
let unstable_features =
783785
rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref());
786+
787+
let disable_minification = matches.opt_present("disable-minification");
788+
784789
let options = Options {
785790
bin_crate,
786791
proc_macro_crate,
@@ -857,6 +862,7 @@ impl Options {
857862
should_merge,
858863
include_parts_dir,
859864
parts_out_dir,
865+
disable_minification,
860866
};
861867
Some((input, options, render_options))
862868
}

src/librustdoc/html/render/write_shared.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,15 @@ fn write_static_files(
207207
if opt.emit.is_empty() || opt.emit.contains(&EmitType::Toolchain) {
208208
static_files::for_each(|f: &static_files::StaticFile| {
209209
let filename = static_dir.join(f.output_filename());
210-
fs::write(&filename, f.minified()).map_err(|e| PathError::new(e, &filename))
210+
let contents: &[u8];
211+
let contents_vec: Vec<u8>;
212+
if opt.disable_minification {
213+
contents = f.bytes;
214+
} else {
215+
contents_vec = f.minified();
216+
contents = &contents_vec;
217+
};
218+
fs::write(&filename, contents).map_err(|e| PathError::new(e, &filename))
211219
})?;
212220
}
213221

src/librustdoc/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,15 @@ fn opts() -> Vec<RustcOptGroup> {
651651
"",
652652
"add arguments to be used when compiling doctests",
653653
),
654+
opt(
655+
Unstable,
656+
FlagMulti,
657+
"",
658+
"disable-minification",
659+
"diable the minification of CSS/JS files",
660+
"",
661+
),
654662
// deprecated / removed options
655-
opt(Unstable, FlagMulti, "", "disable-minification", "removed", ""),
656663
opt(
657664
Stable,
658665
Multi,

0 commit comments

Comments
 (0)