Skip to content

Commit bacf5bc

Browse files
committed
Auto merge of #112982 - lukas-code:bootstrap-alias-default-crates, r=albertlarsan68
bootstrap: update defaults for `compiler` and `library` aliases * `x doc compiler` now documents all of compiler, not just `rustc_driver`. * `x doc` with compiler docs enabled now includes `rustc-main` and `rustc_smir`. `rustc_codegen_llvm` is only included if the LLVM backend is enabled, which is the default. * `x doc library` now excludes `sysroot`. * `x check compiler` and `x check library` now properly check tests/benches/examples of all compiler or library crates, respectively. Note that `x check compiler` will check the library artifacts, but not tests. fixes the fallout from #111955, cc `@jyn514`
2 parents df5c2cf + 9d6bfc2 commit bacf5bc

File tree

10 files changed

+118
-89
lines changed

10 files changed

+118
-89
lines changed

compiler/rustc_smir/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! The WIP stable interface to rustc internals.
22
//!
3-
//! For more information see https://github.com/rust-lang/project-stable-mir
3+
//! For more information see <https://github.com/rust-lang/project-stable-mir>
44
//!
55
//! # Note
66
//!
@@ -14,6 +14,7 @@
1414
#![feature(local_key_cell_methods)]
1515
#![feature(ptr_metadata)]
1616
#![feature(type_alias_impl_trait)] // Used to define opaque types.
17+
#![feature(intra_doc_pointers)]
1718

1819
// Declare extern rustc_* crates to enable building this crate separately from the compiler.
1920
#[cfg(not(feature = "default"))]

compiler/rustc_smir/src/stable_mir/mir/body.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ pub enum Rvalue {
185185
/// [#91095]. Note too that the value of the discriminant is not the same thing as the
186186
/// variant index; use [`discriminant_for_variant`] to convert.
187187
///
188-
/// [`discriminant_ty`]: crate::ty::Ty::discriminant_ty
188+
/// [`discriminant_ty`]: rustc_middle::ty::Ty::discriminant_ty
189189
/// [#91095]: https://github.com/rust-lang/rust/issues/91095
190-
/// [`discriminant_for_variant`]: crate::ty::Ty::discriminant_for_variant
190+
/// [`discriminant_for_variant`]: rustc_middle::ty::Ty::discriminant_for_variant
191191
Discriminant(Place),
192192

193193
/// Yields the length of the place, as a `usize`.

src/bootstrap/builder.rs

+37
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,43 @@ impl RunConfig<'_> {
115115
}
116116
INTERNER.intern_list(crates)
117117
}
118+
119+
/// Given an `alias` selected by the `Step` and the paths passed on the command line,
120+
/// return a list of the crates that should be built.
121+
///
122+
/// Normally, people will pass *just* `library` if they pass it.
123+
/// But it's possible (although strange) to pass something like `library std core`.
124+
/// Build all crates anyway, as if they hadn't passed the other args.
125+
pub fn make_run_crates(&self, alias: Alias) -> Interned<Vec<String>> {
126+
let has_alias =
127+
self.paths.iter().any(|set| set.assert_single_path().path.ends_with(alias.as_str()));
128+
if !has_alias {
129+
return self.cargo_crates_in_set();
130+
}
131+
132+
let crates = match alias {
133+
Alias::Library => self.builder.in_tree_crates("sysroot", Some(self.target)),
134+
Alias::Compiler => self.builder.in_tree_crates("rustc-main", Some(self.target)),
135+
};
136+
137+
let crate_names = crates.into_iter().map(|krate| krate.name.to_string()).collect();
138+
INTERNER.intern_list(crate_names)
139+
}
140+
}
141+
142+
#[derive(Debug, Copy, Clone)]
143+
pub enum Alias {
144+
Library,
145+
Compiler,
146+
}
147+
148+
impl Alias {
149+
fn as_str(self) -> &'static str {
150+
match self {
151+
Alias::Library => "library",
152+
Alias::Compiler => "compiler",
153+
}
154+
}
118155
}
119156

120157
/// A description of the crates in this set, suitable for passing to `builder.info`.

src/bootstrap/builder/tests.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,17 @@ macro_rules! std {
6868
}
6969

7070
macro_rules! doc_std {
71-
($host:ident => $target:ident, stage = $stage:literal) => {
71+
($host:ident => $target:ident, stage = $stage:literal) => {{
72+
let config = configure("doc", &["A"], &["A"]);
73+
let build = Build::new(config);
74+
let builder = Builder::new(&build);
7275
doc::Std::new(
7376
$stage,
7477
TargetSelection::from_user(stringify!($target)),
78+
&builder,
7579
DocumentationFormat::HTML,
7680
)
77-
};
81+
}};
7882
}
7983

8084
macro_rules! rustc {

src/bootstrap/check.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
//! Implementation of compiling the compiler and standard library, in "check"-based modes.
22
3-
use crate::builder::{crate_description, Builder, Kind, RunConfig, ShouldRun, Step};
3+
use crate::builder::{crate_description, Alias, Builder, Kind, RunConfig, ShouldRun, Step};
44
use crate::cache::Interned;
5-
use crate::compile::{
6-
add_to_sysroot, make_run_crates, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo,
7-
};
5+
use crate::compile::{add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo};
86
use crate::config::TargetSelection;
97
use crate::tool::{prepare_tool_cargo, SourceType};
108
use crate::INTERNER;
@@ -89,7 +87,7 @@ impl Step for Std {
8987
}
9088

9189
fn make_run(run: RunConfig<'_>) {
92-
let crates = make_run_crates(&run, "library");
90+
let crates = run.make_run_crates(Alias::Library);
9391
run.builder.ensure(Std { target: run.target, crates });
9492
}
9593

@@ -140,7 +138,7 @@ impl Step for Std {
140138

141139
// don't run on std twice with x.py clippy
142140
// don't check test dependencies if we haven't built libtest
143-
if builder.kind == Kind::Clippy || !self.crates.is_empty() {
141+
if builder.kind == Kind::Clippy || !self.crates.iter().any(|krate| krate == "test") {
144142
return;
145143
}
146144

@@ -200,10 +198,11 @@ pub struct Rustc {
200198

201199
impl Rustc {
202200
pub fn new(target: TargetSelection, builder: &Builder<'_>) -> Self {
203-
let mut crates = vec![];
204-
for krate in builder.in_tree_crates("rustc-main", None) {
205-
crates.push(krate.name.to_string());
206-
}
201+
let crates = builder
202+
.in_tree_crates("rustc-main", Some(target))
203+
.into_iter()
204+
.map(|krate| krate.name.to_string())
205+
.collect();
207206
Self { target, crates: INTERNER.intern_list(crates) }
208207
}
209208
}
@@ -218,7 +217,7 @@ impl Step for Rustc {
218217
}
219218

220219
fn make_run(run: RunConfig<'_>) {
221-
let crates = make_run_crates(&run, "compiler");
220+
let crates = run.make_run_crates(Alias::Compiler);
222221
run.builder.ensure(Rustc { target: run.target, crates });
223222
}
224223

src/bootstrap/compile.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,6 @@ impl Std {
5555
}
5656
}
5757

58-
/// Given an `alias` selected by the `Step` and the paths passed on the command line,
59-
/// return a list of the crates that should be built.
60-
///
61-
/// Normally, people will pass *just* `library` if they pass it.
62-
/// But it's possible (although strange) to pass something like `library std core`.
63-
/// Build all crates anyway, as if they hadn't passed the other args.
64-
pub(crate) fn make_run_crates(run: &RunConfig<'_>, alias: &str) -> Interned<Vec<String>> {
65-
let has_alias = run.paths.iter().any(|set| set.assert_single_path().path.ends_with(alias));
66-
if has_alias { Default::default() } else { run.cargo_crates_in_set() }
67-
}
68-
6958
impl Step for Std {
7059
type Output = ();
7160
const DEFAULT: bool = true;
@@ -80,10 +69,15 @@ impl Step for Std {
8069
}
8170

8271
fn make_run(run: RunConfig<'_>) {
72+
// If the paths include "library", build the entire standard library.
73+
let has_alias =
74+
run.paths.iter().any(|set| set.assert_single_path().path.ends_with("library"));
75+
let crates = if has_alias { Default::default() } else { run.cargo_crates_in_set() };
76+
8377
run.builder.ensure(Std {
8478
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
8579
target: run.target,
86-
crates: make_run_crates(&run, "library"),
80+
crates,
8781
force_recompile: false,
8882
});
8983
}

src/bootstrap/dist.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ impl Step for JsonDocs {
106106
/// Builds the `rust-docs-json` installer component.
107107
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
108108
let host = self.host;
109-
builder.ensure(crate::doc::Std::new(builder.top_stage, host, DocumentationFormat::JSON));
109+
builder.ensure(crate::doc::Std::new(
110+
builder.top_stage,
111+
host,
112+
builder,
113+
DocumentationFormat::JSON,
114+
));
110115

111116
let dest = "share/doc/rust/json";
112117

src/bootstrap/doc.rs

+47-60
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ use std::fs;
1111
use std::path::{Path, PathBuf};
1212

1313
use crate::builder::crate_description;
14-
use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
14+
use crate::builder::{Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
1515
use crate::cache::{Interned, INTERNER};
1616
use crate::compile;
17-
use crate::compile::make_run_crates;
1817
use crate::config::{Config, TargetSelection};
1918
use crate::tool::{self, prepare_tool_cargo, SourceType, Tool};
2019
use crate::util::{symlink_dir, t, up_to_date};
@@ -424,8 +423,18 @@ pub struct Std {
424423
}
425424

426425
impl Std {
427-
pub(crate) fn new(stage: u32, target: TargetSelection, format: DocumentationFormat) -> Self {
428-
Std { stage, target, format, crates: INTERNER.intern_list(vec![]) }
426+
pub(crate) fn new(
427+
stage: u32,
428+
target: TargetSelection,
429+
builder: &Builder<'_>,
430+
format: DocumentationFormat,
431+
) -> Self {
432+
let crates = builder
433+
.in_tree_crates("sysroot", Some(target))
434+
.into_iter()
435+
.map(|krate| krate.name.to_string())
436+
.collect();
437+
Std { stage, target, format, crates: INTERNER.intern_list(crates) }
429438
}
430439
}
431440

@@ -447,15 +456,15 @@ impl Step for Std {
447456
} else {
448457
DocumentationFormat::HTML
449458
},
450-
crates: make_run_crates(&run, "library"),
459+
crates: run.make_run_crates(Alias::Library),
451460
});
452461
}
453462

454463
/// Compile all standard library documentation.
455464
///
456465
/// This will generate all documentation for the standard library and its
457466
/// dependencies. This is largely just a wrapper around `cargo doc`.
458-
fn run(mut self, builder: &Builder<'_>) {
467+
fn run(self, builder: &Builder<'_>) {
459468
let stage = self.stage;
460469
let target = self.target;
461470
let out = match self.format {
@@ -493,20 +502,17 @@ impl Step for Std {
493502
return;
494503
}
495504

496-
// Look for library/std, library/core etc in the `x.py doc` arguments and
497-
// open the corresponding rendered docs.
498-
if self.crates.is_empty() {
499-
self.crates = INTERNER.intern_list(vec!["library".to_owned()]);
500-
};
501-
502-
for requested_crate in &*self.crates {
503-
if requested_crate == "library" {
504-
// For `x.py doc library --open`, open `std` by default.
505-
let index = out.join("std").join("index.html");
506-
builder.open_in_browser(index);
507-
} else if STD_PUBLIC_CRATES.iter().any(|&k| k == requested_crate) {
508-
let index = out.join(requested_crate).join("index.html");
509-
builder.open_in_browser(index);
505+
if builder.paths.iter().any(|path| path.ends_with("library")) {
506+
// For `x.py doc library --open`, open `std` by default.
507+
let index = out.join("std").join("index.html");
508+
builder.open_in_browser(index);
509+
} else {
510+
for requested_crate in &*self.crates {
511+
if STD_PUBLIC_CRATES.iter().any(|&k| k == requested_crate) {
512+
let index = out.join(requested_crate).join("index.html");
513+
builder.open_in_browser(index);
514+
break;
515+
}
510516
}
511517
}
512518
}
@@ -539,9 +545,6 @@ impl DocumentationFormat {
539545
}
540546

541547
/// Build the documentation for public standard library crates.
542-
///
543-
/// `requested_crates` can be used to build only a subset of the crates. If empty, all crates will
544-
/// be built.
545548
fn doc_std(
546549
builder: &Builder<'_>,
547550
format: DocumentationFormat,
@@ -592,19 +595,11 @@ fn doc_std(
592595
cargo.rustdocflag("--document-private-items").rustdocflag("--document-hidden-items");
593596
}
594597

595-
// HACK: because we use `--manifest-path library/sysroot/Cargo.toml`, cargo thinks we only want to document that specific crate, not its dependencies.
596-
// Override its default.
597-
let built_crates = if requested_crates.is_empty() {
598-
builder
599-
.in_tree_crates("sysroot", None)
600-
.into_iter()
601-
.map(|krate| krate.name.to_string())
602-
.collect()
603-
} else {
604-
requested_crates.to_vec()
605-
};
606-
607-
for krate in built_crates {
598+
for krate in requested_crates {
599+
if krate == "sysroot" {
600+
// The sysroot crate is an implementation detail, don't include it in public docs.
601+
continue;
602+
}
608603
cargo.arg("-p").arg(krate);
609604
}
610605

@@ -621,20 +616,10 @@ pub struct Rustc {
621616

622617
impl Rustc {
623618
pub(crate) fn new(stage: u32, target: TargetSelection, builder: &Builder<'_>) -> Self {
624-
// Find dependencies for top level crates.
625-
let root_crates = vec![
626-
INTERNER.intern_str("rustc_driver"),
627-
INTERNER.intern_str("rustc_codegen_llvm"),
628-
INTERNER.intern_str("rustc_codegen_ssa"),
629-
];
630-
let crates: Vec<_> = root_crates
631-
.iter()
632-
.flat_map(|krate| {
633-
builder
634-
.in_tree_crates(krate, Some(target))
635-
.into_iter()
636-
.map(|krate| krate.name.to_string())
637-
})
619+
let crates = builder
620+
.in_tree_crates("rustc-main", Some(target))
621+
.into_iter()
622+
.map(|krate| krate.name.to_string())
638623
.collect();
639624
Self { stage, target, crates: INTERNER.intern_list(crates) }
640625
}
@@ -656,7 +641,7 @@ impl Step for Rustc {
656641
run.builder.ensure(Rustc {
657642
stage: run.builder.top_stage,
658643
target: run.target,
659-
crates: make_run_crates(&run, "compiler"),
644+
crates: run.make_run_crates(Alias::Compiler),
660645
});
661646
}
662647

@@ -666,7 +651,7 @@ impl Step for Rustc {
666651
/// Compiler documentation is distributed separately, so we make sure
667652
/// we do not merge it with the other documentation from std, test and
668653
/// proc_macros. This is largely just a wrapper around `cargo doc`.
669-
fn run(mut self, builder: &Builder<'_>) {
654+
fn run(self, builder: &Builder<'_>) {
670655
let stage = self.stage;
671656
let target = self.target;
672657

@@ -726,24 +711,26 @@ impl Step for Rustc {
726711

727712
let mut to_open = None;
728713

729-
if self.crates.is_empty() {
730-
self.crates = INTERNER.intern_list(vec!["rustc_driver".to_owned()]);
731-
};
732-
733714
for krate in &*self.crates {
734715
// Create all crate output directories first to make sure rustdoc uses
735716
// relative links.
736717
// FIXME: Cargo should probably do this itself.
737-
t!(fs::create_dir_all(out_dir.join(krate)));
718+
let dir_name = krate.replace("-", "_");
719+
t!(fs::create_dir_all(out_dir.join(&*dir_name)));
738720
cargo.arg("-p").arg(krate);
739721
if to_open.is_none() {
740-
to_open = Some(krate);
722+
to_open = Some(dir_name);
741723
}
742724
}
743725

744726
builder.run(&mut cargo.into());
745-
// Let's open the first crate documentation page:
746-
if let Some(krate) = to_open {
727+
728+
if builder.paths.iter().any(|path| path.ends_with("compiler")) {
729+
// For `x.py doc compiler --open`, open `rustc_middle` by default.
730+
let index = out.join("rustc_middle").join("index.html");
731+
builder.open_in_browser(index);
732+
} else if let Some(krate) = to_open {
733+
// Let's open the first crate documentation page:
747734
let index = out.join(krate).join("index.html");
748735
builder.open_in_browser(index);
749736
}

0 commit comments

Comments
 (0)