Skip to content

Commit e9e0908

Browse files
committed
Auto merge of #106520 - ehuss:update-mdbook, r=Mark-Simulacrum
Update mdbook This updates mdbook from 0.4.21 to 0.4.25. The list of changes is [here](https://github.com/rust-lang/mdBook/blob/master/CHANGELOG.md#mdbook-0425). The only user-visible changes are some changes around the theme picker, and change to the copy-to-clipboard ignoring hidden lines. Internally there were some dependency updates and small fixes. This also updates `clap` from 4.0.15 to 4.0.32 whose changelog is [here](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md#4032---2022-12-22). This impacts tools like cargo. I don't see anything particularly noteworthy there, though there are some small user-visible changes. Unfortunately this required adding a hack for building `rustix` with a bootstrap tool. The comment explains why. I am unable to think of some other workaround (or even a cleaner way to set the rustflag). Ideas are welcome if you can think of alternatives. I'm struggling to even think of a long-term solution, other than asking projects not to do auto-nightly feature detection. One medium-term solution is to avoid the clap dependency for the mdbook library (which is how rustix gets pulled in). That is one of my goals for the 0.5 release of mdbook, but that probably won't happen until later this year. It would also require dropping clap from `rustbook` and using some other means to parse arguments (there's only two options, so it can probably be done manually).
2 parents ca5d92d + 2717f60 commit e9e0908

File tree

8 files changed

+146
-49
lines changed

8 files changed

+146
-49
lines changed

Cargo.lock

+30-19
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ dependencies = [
340340
"cargo-test-macro",
341341
"cargo-test-support",
342342
"cargo-util",
343-
"clap 4.0.15",
343+
"clap 4.0.32",
344344
"crates-io",
345345
"curl",
346346
"curl-sys",
@@ -644,26 +644,27 @@ dependencies = [
644644

645645
[[package]]
646646
name = "clap"
647-
version = "4.0.15"
647+
version = "4.0.32"
648648
source = "registry+https://github.com/rust-lang/crates.io-index"
649-
checksum = "6bf8832993da70a4c6d13c581f4463c2bdda27b9bf1c5498dc4365543abe6d6f"
649+
checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39"
650650
dependencies = [
651-
"atty",
652651
"bitflags",
653-
"clap_derive 4.0.13",
652+
"clap_derive 4.0.21",
654653
"clap_lex 0.3.0",
654+
"is-terminal",
655655
"once_cell",
656656
"strsim",
657657
"termcolor",
658+
"terminal_size",
658659
]
659660

660661
[[package]]
661662
name = "clap_complete"
662-
version = "3.1.1"
663+
version = "4.0.7"
663664
source = "registry+https://github.com/rust-lang/crates.io-index"
664-
checksum = "df6f3613c0a3cddfd78b41b10203eb322cb29b600cbdf808a7d3db95691b8e25"
665+
checksum = "10861370d2ba66b0f5989f83ebf35db6421713fd92351790e7fdd6c36774c56b"
665666
dependencies = [
666-
"clap 3.2.20",
667+
"clap 4.0.32",
667668
]
668669

669670
[[package]]
@@ -681,9 +682,9 @@ dependencies = [
681682

682683
[[package]]
683684
name = "clap_derive"
684-
version = "4.0.13"
685+
version = "4.0.21"
685686
source = "registry+https://github.com/rust-lang/crates.io-index"
686-
checksum = "c42f169caba89a7d512b5418b09864543eeb4d497416c917d7137863bd2076ad"
687+
checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014"
687688
dependencies = [
688689
"heck",
689690
"proc-macro-error",
@@ -2273,7 +2274,7 @@ name = "jsondoclint"
22732274
version = "0.1.0"
22742275
dependencies = [
22752276
"anyhow",
2276-
"clap 4.0.15",
2277+
"clap 4.0.32",
22772278
"fs-err",
22782279
"rustdoc-json-types",
22792280
"serde",
@@ -2529,21 +2530,21 @@ dependencies = [
25292530

25302531
[[package]]
25312532
name = "mdbook"
2532-
version = "0.4.21"
2533+
version = "0.4.25"
25332534
source = "registry+https://github.com/rust-lang/crates.io-index"
2534-
checksum = "23f3e133c6d515528745ffd3b9f0c7d975ae039f0b6abb099f2168daa2afb4f9"
2535+
checksum = "d1ed28d5903dde77bd5182645078a37ee57014cac6ccb2d54e1d6496386648e4"
25352536
dependencies = [
25362537
"ammonia",
25372538
"anyhow",
25382539
"chrono",
2539-
"clap 3.2.20",
2540+
"clap 4.0.32",
25402541
"clap_complete",
25412542
"elasticlunr-rs",
2542-
"env_logger 0.9.0",
2543+
"env_logger 0.10.0",
25432544
"handlebars 4.3.3",
2544-
"lazy_static",
25452545
"log",
25462546
"memchr",
2547+
"once_cell",
25472548
"opener",
25482549
"pulldown-cmark 0.9.2",
25492550
"regex",
@@ -3498,7 +3499,7 @@ dependencies = [
34983499
name = "rustbook"
34993500
version = "0.1.0"
35003501
dependencies = [
3501-
"clap 3.2.20",
3502+
"clap 4.0.32",
35023503
"env_logger 0.7.1",
35033504
"mdbook",
35043505
]
@@ -5478,6 +5479,16 @@ dependencies = [
54785479
"winapi-util",
54795480
]
54805481

5482+
[[package]]
5483+
name = "terminal_size"
5484+
version = "0.2.3"
5485+
source = "registry+https://github.com/rust-lang/crates.io-index"
5486+
checksum = "cb20089a8ba2b69debd491f8d2d023761cbf196e999218c591fa1e7e15a21907"
5487+
dependencies = [
5488+
"rustix",
5489+
"windows-sys",
5490+
]
5491+
54815492
[[package]]
54825493
name = "termize"
54835494
version = "0.1.1"
@@ -5693,9 +5704,9 @@ dependencies = [
56935704

56945705
[[package]]
56955706
name = "topological-sort"
5696-
version = "0.1.0"
5707+
version = "0.2.2"
56975708
source = "registry+https://github.com/rust-lang/crates.io-index"
5698-
checksum = "aa7c7f42dea4b1b99439786f5633aeb9c14c1b53f75e282803c2ec2ad545873c"
5709+
checksum = "ea68304e134ecd095ac6c3574494fc62b909f416c4fca77e440530221e549d3d"
56995710

57005711
[[package]]
57015712
name = "tracing"

src/bootstrap/bin/rustc.rs

+35
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,41 @@ fn main() {
154154
cmd.arg("-Z").arg("force-unstable-if-unmarked");
155155
}
156156

157+
// allow-features is handled from within this rustc wrapper because of
158+
// issues with build scripts. Some packages use build scripts to
159+
// dynamically detect if certain nightly features are available.
160+
// There are different ways this causes problems:
161+
//
162+
// * rustix runs `rustc` on a small test program to see if the feature is
163+
// available (and sets a `cfg` if it is). It does not honor
164+
// CARGO_ENCODED_RUSTFLAGS.
165+
// * proc-macro2 detects if `rustc -vV` says "nighty" or "dev" and enables
166+
// nightly features. It will scan CARGO_ENCODED_RUSTFLAGS for
167+
// -Zallow-features. Unfortunately CARGO_ENCODED_RUSTFLAGS is not set
168+
// for build-dependencies when --target is used.
169+
//
170+
// The issues above means we can't just use RUSTFLAGS, and we can't use
171+
// `cargo -Zallow-features=…`. Passing it through here ensures that it
172+
// always gets set. Unfortunately that also means we need to enable more
173+
// features than we really want (like those for proc-macro2), but there
174+
// isn't much of a way around it.
175+
//
176+
// I think it is unfortunate that build scripts are doing this at all,
177+
// since changes to nightly features can cause crates to break even if the
178+
// user didn't want or care about the use of the nightly features. I think
179+
// nightly features should be opt-in only. Unfortunately the dynamic
180+
// checks are now too wide spread that we just need to deal with it.
181+
//
182+
// If you want to try to remove this, I suggest working with the crate
183+
// authors to remove the dynamic checking. Another option is to pursue
184+
// https://github.com/rust-lang/cargo/issues/11244 and
185+
// https://github.com/rust-lang/cargo/issues/4423, which will likely be
186+
// very difficult, but could help expose -Zallow-features into build
187+
// scripts so they could try to honor them.
188+
if let Ok(allow_features) = env::var("RUSTC_ALLOW_FEATURES") {
189+
cmd.arg(format!("-Zallow-features={allow_features}"));
190+
}
191+
157192
if let Ok(flags) = env::var("MAGIC_EXTRA_RUSTFLAGS") {
158193
for flag in flags.split(' ') {
159194
cmd.arg(flag);

src/bootstrap/builder.rs

+40-12
Original file line numberDiff line numberDiff line change
@@ -1381,18 +1381,29 @@ impl<'a> Builder<'a> {
13811381
// this), as well as #63012 which is the tracking issue for this
13821382
// feature on the rustc side.
13831383
cargo.arg("-Zbinary-dep-depinfo");
1384-
match mode {
1385-
Mode::ToolBootstrap => {
1386-
// Restrict the allowed features to those passed by rustbuild, so we don't depend on nightly accidentally.
1387-
rustflags.arg("-Zallow-features=binary-dep-depinfo");
1388-
}
1389-
Mode::ToolStd => {
1390-
// Right now this is just compiletest and a few other tools that build on stable.
1391-
// Allow them to use `feature(test)`, but nothing else.
1392-
rustflags.arg("-Zallow-features=binary-dep-depinfo,test,proc_macro_internals,proc_macro_diagnostic,proc_macro_span");
1384+
let allow_features = match mode {
1385+
Mode::ToolBootstrap | Mode::ToolStd => {
1386+
// Restrict the allowed features so we don't depend on nightly
1387+
// accidentally.
1388+
//
1389+
// binary-dep-depinfo is used by rustbuild itself for all
1390+
// compilations.
1391+
//
1392+
// Lots of tools depend on proc_macro2 and proc-macro-error.
1393+
// Those have build scripts which assume nightly features are
1394+
// available if the `rustc` version is "nighty" or "dev". See
1395+
// bin/rustc.rs for why that is a problem. Instead of labeling
1396+
// those features for each individual tool that needs them,
1397+
// just blanket allow them here.
1398+
//
1399+
// If this is ever removed, be sure to add something else in
1400+
// its place to keep the restrictions in place (or make a way
1401+
// to unset RUSTC_BOOTSTRAP).
1402+
"binary-dep-depinfo,proc_macro_span,proc_macro_span_shrink,proc_macro_diagnostic"
1403+
.to_string()
13931404
}
1394-
Mode::Std | Mode::Rustc | Mode::Codegen | Mode::ToolRustc => {}
1395-
}
1405+
Mode::Std | Mode::Rustc | Mode::Codegen | Mode::ToolRustc => String::new(),
1406+
};
13961407

13971408
cargo.arg("-j").arg(self.jobs().to_string());
13981409

@@ -1915,7 +1926,7 @@ impl<'a> Builder<'a> {
19151926
}
19161927
}
19171928

1918-
Cargo { command: cargo, rustflags, rustdocflags }
1929+
Cargo { command: cargo, rustflags, rustdocflags, allow_features }
19191930
}
19201931

19211932
/// Ensure that a given step is built, returning its output. This will
@@ -2094,6 +2105,7 @@ pub struct Cargo {
20942105
command: Command,
20952106
rustflags: Rustflags,
20962107
rustdocflags: Rustflags,
2108+
allow_features: String,
20972109
}
20982110

20992111
impl Cargo {
@@ -2138,6 +2150,18 @@ impl Cargo {
21382150
self.command.current_dir(dir);
21392151
self
21402152
}
2153+
2154+
/// Adds nightly-only features that this invocation is allowed to use.
2155+
///
2156+
/// By default, all nightly features are allowed. Once this is called, it
2157+
/// will be restricted to the given set.
2158+
pub fn allow_features(&mut self, features: &str) -> &mut Cargo {
2159+
if !self.allow_features.is_empty() {
2160+
self.allow_features.push(',');
2161+
}
2162+
self.allow_features.push_str(features);
2163+
self
2164+
}
21412165
}
21422166

21432167
impl From<Cargo> for Command {
@@ -2152,6 +2176,10 @@ impl From<Cargo> for Command {
21522176
cargo.command.env("RUSTDOCFLAGS", rustdocflags);
21532177
}
21542178

2179+
if !cargo.allow_features.is_empty() {
2180+
cargo.command.env("RUSTC_ALLOW_FEATURES", cargo.allow_features);
2181+
}
2182+
21552183
cargo.command
21562184
}
21572185
}

src/bootstrap/check.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,7 @@ impl Step for RustAnalyzer {
346346
&["rust-analyzer/in-rust-tree".to_owned()],
347347
);
348348

349-
cargo.rustflag(
350-
"-Zallow-features=proc_macro_internals,proc_macro_diagnostic,proc_macro_span",
351-
);
349+
cargo.allow_features(crate::tool::RustAnalyzer::ALLOW_FEATURES);
352350

353351
// For ./x.py clippy, don't check those targets because
354352
// linting tests and benchmarks can produce very noisy results

src/bootstrap/test.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ impl Step for RustAnalyzer {
378378
SourceType::InTree,
379379
&["sysroot-abi".to_owned()],
380380
);
381+
cargo.allow_features(tool::RustAnalyzer::ALLOW_FEATURES);
381382

382383
let dir = builder.src.join(workspace_path);
383384
// needed by rust-analyzer to find its own text fixtures, cf.
@@ -690,7 +691,7 @@ impl Step for CompiletestTest {
690691
// We need `ToolStd` for the locally-built sysroot because
691692
// compiletest uses unstable features of the `test` crate.
692693
builder.ensure(compile::Std::new(compiler, host));
693-
let cargo = tool::prepare_tool_cargo(
694+
let mut cargo = tool::prepare_tool_cargo(
694695
builder,
695696
compiler,
696697
Mode::ToolStd,
@@ -700,6 +701,7 @@ impl Step for CompiletestTest {
700701
SourceType::InTree,
701702
&[],
702703
);
704+
cargo.allow_features("test");
703705

704706
try_run(builder, &mut cargo.into());
705707
}

0 commit comments

Comments
 (0)