Skip to content

Commit ca47be8

Browse files
authored
Rollup merge of rust-lang#76799 - Mark-Simulacrum:fix-cross-compile-dist, r=alexcrichton
Fix cross compiling dist/build invocations I am uncertain why the first commit is not affecting CI. I suspect it's because we pass --disable-docs on most of our cross-compilation builders. The second commit doesn't affect CI because CI runs x.py dist, not x.py build. Both commits are standalone; together they should resolve rust-lang#76733. The first commit doesn't really fix that issue but rather just fixes cross-compiled x.py dist, resolving a bug introduced in rust-lang#76549.
2 parents f68e089 + 363aff0 commit ca47be8

File tree

6 files changed

+90
-16
lines changed

6 files changed

+90
-16
lines changed

src/bootstrap/builder/tests.rs

+48
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,54 @@ mod defaults {
9090
assert!(builder.cache.all::<compile::Rustc>().is_empty());
9191
}
9292

93+
#[test]
94+
fn build_cross_compile() {
95+
let config = Config { stage: 1, ..configure("build", &["B"], &["B"]) };
96+
let build = Build::new(config);
97+
let mut builder = Builder::new(&build);
98+
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);
99+
100+
let a = TargetSelection::from_user("A");
101+
let b = TargetSelection::from_user("B");
102+
103+
// Ideally, this build wouldn't actually have `target: a`
104+
// rustdoc/rustcc/std here (the user only requested a host=B build, so
105+
// there's not really a need for us to build for target A in this case
106+
// (since we're producing stage 1 libraries/binaries). But currently
107+
// rustbuild is just a bit buggy here; this should be fixed though.
108+
assert_eq!(
109+
first(builder.cache.all::<compile::Std>()),
110+
&[
111+
compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },
112+
compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
113+
compile::Std { compiler: Compiler { host: a, stage: 0 }, target: b },
114+
compile::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
115+
]
116+
);
117+
assert_eq!(
118+
first(builder.cache.all::<compile::Assemble>()),
119+
&[
120+
compile::Assemble { target_compiler: Compiler { host: a, stage: 0 } },
121+
compile::Assemble { target_compiler: Compiler { host: a, stage: 1 } },
122+
compile::Assemble { target_compiler: Compiler { host: b, stage: 1 } },
123+
]
124+
);
125+
assert_eq!(
126+
first(builder.cache.all::<tool::Rustdoc>()),
127+
&[
128+
tool::Rustdoc { compiler: Compiler { host: a, stage: 1 } },
129+
tool::Rustdoc { compiler: Compiler { host: b, stage: 1 } },
130+
],
131+
);
132+
assert_eq!(
133+
first(builder.cache.all::<compile::Rustc>()),
134+
&[
135+
compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a },
136+
compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: b },
137+
]
138+
);
139+
}
140+
93141
#[test]
94142
fn doc_default() {
95143
let mut config = configure("doc", &[], &[]);

src/bootstrap/doc.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ impl Step for RustcBook {
752752
let out_listing = out_base.join("src/lints");
753753
builder.cp_r(&builder.src.join("src/doc/rustc"), &out_base);
754754
builder.info(&format!("Generating lint docs ({})", self.target));
755+
755756
let rustc = builder.rustc(self.compiler);
756757
// The tool runs `rustc` for extracting output examples, so it needs a
757758
// functional sysroot.
@@ -762,7 +763,8 @@ impl Step for RustcBook {
762763
cmd.arg("--out");
763764
cmd.arg(&out_listing);
764765
cmd.arg("--rustc");
765-
cmd.arg(rustc);
766+
cmd.arg(&rustc);
767+
cmd.arg("--rustc-target").arg(&self.target.rustc_target_arg());
766768
if builder.config.verbose() {
767769
cmd.arg("--verbose");
768770
}

src/bootstrap/tool.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,11 @@ impl Step for Rustdoc {
471471

472472
fn make_run(run: RunConfig<'_>) {
473473
run.builder.ensure(Rustdoc {
474-
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
474+
// Note: this is somewhat unique in that we actually want a *target*
475+
// compiler here, because rustdoc *is* a compiler. We won't be using
476+
// this as the compiler to build with, but rather this is "what
477+
// compiler are we producing"?
478+
compiler: run.builder.compiler(run.builder.top_stage, run.target),
475479
});
476480
}
477481

src/tools/lint-docs/src/groups.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ static GROUP_DESCRIPTIONS: &[(&str, &str)] = &[
1818
/// Updates the documentation of lint groups.
1919
pub(crate) fn generate_group_docs(
2020
lints: &[Lint],
21-
rustc_path: &Path,
21+
rustc: crate::Rustc<'_>,
2222
out_path: &Path,
2323
) -> Result<(), Box<dyn Error>> {
24-
let groups = collect_groups(rustc_path)?;
24+
let groups = collect_groups(rustc)?;
2525
let groups_path = out_path.join("groups.md");
2626
let contents = fs::read_to_string(&groups_path)
2727
.map_err(|e| format!("could not read {}: {}", groups_path.display(), e))?;
@@ -36,9 +36,9 @@ pub(crate) fn generate_group_docs(
3636
type LintGroups = BTreeMap<String, BTreeSet<String>>;
3737

3838
/// Collects the group names from rustc.
39-
fn collect_groups(rustc: &Path) -> Result<LintGroups, Box<dyn Error>> {
39+
fn collect_groups(rustc: crate::Rustc<'_>) -> Result<LintGroups, Box<dyn Error>> {
4040
let mut result = BTreeMap::new();
41-
let mut cmd = Command::new(rustc);
41+
let mut cmd = Command::new(rustc.path);
4242
cmd.arg("-Whelp");
4343
let output = cmd.output().map_err(|e| format!("failed to run command {:?}\n{}", cmd, e))?;
4444
if !output.status.success() {

src/tools/lint-docs/src/lib.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,22 @@ impl Level {
4545
}
4646
}
4747

48+
#[derive(Copy, Clone)]
49+
pub struct Rustc<'a> {
50+
pub path: &'a Path,
51+
pub target: &'a str,
52+
}
53+
4854
/// Collects all lints, and writes the markdown documentation at the given directory.
4955
pub fn extract_lint_docs(
5056
src_path: &Path,
5157
out_path: &Path,
52-
rustc_path: &Path,
58+
rustc: Rustc<'_>,
5359
verbose: bool,
5460
) -> Result<(), Box<dyn Error>> {
5561
let mut lints = gather_lints(src_path)?;
5662
for lint in &mut lints {
57-
generate_output_example(lint, rustc_path, verbose).map_err(|e| {
63+
generate_output_example(lint, rustc, verbose).map_err(|e| {
5864
format!(
5965
"failed to test example in lint docs for `{}` in {}:{}: {}",
6066
lint.name,
@@ -65,7 +71,7 @@ pub fn extract_lint_docs(
6571
})?;
6672
}
6773
save_lints_markdown(&lints, &out_path.join("listing"))?;
68-
groups::generate_group_docs(&lints, rustc_path, out_path)?;
74+
groups::generate_group_docs(&lints, rustc, out_path)?;
6975
Ok(())
7076
}
7177

@@ -208,7 +214,7 @@ fn lint_name(line: &str) -> Result<String, &'static str> {
208214
/// actual output from the compiler.
209215
fn generate_output_example(
210216
lint: &mut Lint,
211-
rustc_path: &Path,
217+
rustc: Rustc<'_>,
212218
verbose: bool,
213219
) -> Result<(), Box<dyn Error>> {
214220
// Explicit list of lints that are allowed to not have an example. Please
@@ -230,7 +236,7 @@ fn generate_output_example(
230236
// separate test suite, and use an include mechanism such as mdbook's
231237
// `{{#rustdoc_include}}`.
232238
if !lint.is_ignored() {
233-
replace_produces(lint, rustc_path, verbose)?;
239+
replace_produces(lint, rustc, verbose)?;
234240
}
235241
Ok(())
236242
}
@@ -261,7 +267,7 @@ fn check_style(lint: &Lint) -> Result<(), Box<dyn Error>> {
261267
/// output from the compiler.
262268
fn replace_produces(
263269
lint: &mut Lint,
264-
rustc_path: &Path,
270+
rustc: Rustc<'_>,
265271
verbose: bool,
266272
) -> Result<(), Box<dyn Error>> {
267273
let mut lines = lint.doc.iter_mut();
@@ -302,7 +308,7 @@ fn replace_produces(
302308
Some(line) if line.is_empty() => {}
303309
Some(line) if line == "{{produces}}" => {
304310
let output =
305-
generate_lint_output(&lint.name, &example, &options, rustc_path, verbose)?;
311+
generate_lint_output(&lint.name, &example, &options, rustc, verbose)?;
306312
line.replace_range(
307313
..,
308314
&format!(
@@ -329,7 +335,7 @@ fn generate_lint_output(
329335
name: &str,
330336
example: &[&mut String],
331337
options: &[&str],
332-
rustc_path: &Path,
338+
rustc: Rustc<'_>,
333339
verbose: bool,
334340
) -> Result<String, Box<dyn Error>> {
335341
if verbose {
@@ -364,13 +370,14 @@ fn generate_lint_output(
364370
}
365371
fs::write(&tempfile, source)
366372
.map_err(|e| format!("failed to write {}: {}", tempfile.display(), e))?;
367-
let mut cmd = Command::new(rustc_path);
373+
let mut cmd = Command::new(rustc.path);
368374
if options.contains(&"edition2015") {
369375
cmd.arg("--edition=2015");
370376
} else {
371377
cmd.arg("--edition=2018");
372378
}
373379
cmd.arg("--error-format=json");
380+
cmd.arg("--target").arg(rustc.target);
374381
if options.contains(&"test") {
375382
cmd.arg("--test");
376383
}

src/tools/lint-docs/src/main.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ fn doit() -> Result<(), Box<dyn Error>> {
1313
let mut src_path = None;
1414
let mut out_path = None;
1515
let mut rustc_path = None;
16+
let mut rustc_target = None;
1617
let mut verbose = false;
1718
while let Some(arg) = args.next() {
1819
match arg.as_str() {
@@ -34,6 +35,12 @@ fn doit() -> Result<(), Box<dyn Error>> {
3435
None => return Err("--rustc requires a value".into()),
3536
};
3637
}
38+
"--rustc-target" => {
39+
rustc_target = match args.next() {
40+
Some(s) => Some(s),
41+
None => return Err("--rustc-target requires a value".into()),
42+
};
43+
}
3744
"-v" | "--verbose" => verbose = true,
3845
s => return Err(format!("unexpected argument `{}`", s).into()),
3946
}
@@ -47,10 +54,16 @@ fn doit() -> Result<(), Box<dyn Error>> {
4754
if rustc_path.is_none() {
4855
return Err("--rustc must be specified to the path of rustc".into());
4956
}
57+
if rustc_target.is_none() {
58+
return Err("--rustc-target must be specified to the rustc target".into());
59+
}
5060
lint_docs::extract_lint_docs(
5161
&src_path.unwrap(),
5262
&out_path.unwrap(),
53-
&rustc_path.unwrap(),
63+
lint_docs::Rustc {
64+
path: rustc_path.as_deref().unwrap(),
65+
target: rustc_target.as_deref().unwrap(),
66+
},
5467
verbose,
5568
)
5669
}

0 commit comments

Comments
 (0)