Rollup merge of #129957 - chenx97:lint-docs-linker-opt, r=albertlarsan68

forward linker option to lint-docs

This fixes an error found when building the doc for a cross-built toolchain.

```
warning: the code example in lint `unstable_syntax_pre_expansion` in /buildroots/chenx97/rustc-1.80.1-src/compiler/rustc_lint_defs/src/builtin.rs failed to generate the expected output: did not find lint `unstable_syntax_p
re_expansion` in output of example, got:

error: linking with `cc` failed: exit status: 1
...
```
Closes: #129956
This commit is contained in:
Matthias Krüger 2024-09-05 19:43:51 +02:00 committed by GitHub
commit d34ad5d9aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 0 deletions

View File

@ -1186,6 +1186,9 @@ impl Step for RustcBook {
cmd.arg("--rustc");
cmd.arg(&rustc);
cmd.arg("--rustc-target").arg(self.target.rustc_target_arg());
if let Some(target_linker) = builder.linker(self.target) {
cmd.arg("--rustc-linker").arg(target_linker);
}
if builder.is_verbose() {
cmd.arg("--verbose");
}

View File

@ -56,6 +56,8 @@ pub struct LintExtractor<'a> {
pub rustc_path: &'a Path,
/// The target arch to build the docs for.
pub rustc_target: &'a str,
/// The target linker overriding `rustc`'s default
pub rustc_linker: Option<&'a str>,
/// Verbose output.
pub verbose: bool,
/// Validate the style and the code example.
@ -459,6 +461,9 @@ impl<'a> LintExtractor<'a> {
}
cmd.arg("--error-format=json");
cmd.arg("--target").arg(self.rustc_target);
if let Some(target_linker) = self.rustc_linker {
cmd.arg(format!("-Clinker={target_linker}"));
}
if options.contains(&"test") {
cmd.arg("--test");
}

View File

@ -27,6 +27,7 @@ fn doit() -> Result<(), Box<dyn Error>> {
let mut out_path = None;
let mut rustc_path = None;
let mut rustc_target = None;
let mut rustc_linker = None;
let mut verbose = false;
let mut validate = false;
while let Some(arg) = args.next() {
@ -55,6 +56,12 @@ fn doit() -> Result<(), Box<dyn Error>> {
None => return Err("--rustc-target requires a value".into()),
};
}
"--rustc-linker" => {
rustc_linker = match args.next() {
Some(s) => Some(s),
None => return Err("--rustc-linker requires a value".into()),
};
}
"-v" | "--verbose" => verbose = true,
"--validate" => validate = true,
s => return Err(format!("unexpected argument `{}`", s).into()),
@ -77,6 +84,7 @@ fn doit() -> Result<(), Box<dyn Error>> {
out_path: &out_path.unwrap(),
rustc_path: &rustc_path.unwrap(),
rustc_target: &rustc_target.unwrap(),
rustc_linker: rustc_linker.as_deref(),
verbose,
validate,
};