Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e42eeea

Browse files
committedOct 11, 2023
Add LLD flags to rustdoc cargo invocations
1 parent e993142 commit e42eeea

File tree

2 files changed

+52
-10
lines changed

2 files changed

+52
-10
lines changed
 

‎src/bootstrap/test.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use crate::synthetic_targets::MirOptPanicAbortSyntheticTarget;
2828
use crate::tool::{self, SourceType, Tool};
2929
use crate::toolstate::ToolState;
3030
use crate::util::{
31-
self, add_link_lib_path, add_rustdoc_lld_flags, dylib_path, dylib_path_var, output, t,
32-
up_to_date,
31+
self, add_link_lib_path, add_rustdoc_cargo_lld_flags, add_rustdoc_lld_flags, dylib_path,
32+
dylib_path_var, output, t, up_to_date,
3333
};
3434
use crate::{envify, CLang, DocTests, GitRepo, Mode};
3535

@@ -265,13 +265,14 @@ impl Step for Cargotest {
265265

266266
let _time = util::timeit(&builder);
267267
let mut cmd = builder.tool_cmd(Tool::CargoTest);
268-
builder.run_delaying_failure(
269-
cmd.arg(&cargo)
270-
.arg(&out_dir)
271-
.args(builder.config.test_args())
272-
.env("RUSTC", builder.rustc(compiler))
273-
.env("RUSTDOC", builder.rustdoc(compiler)),
274-
);
268+
let mut cmd = cmd
269+
.arg(&cargo)
270+
.arg(&out_dir)
271+
.args(builder.config.test_args())
272+
.env("RUSTC", builder.rustc(compiler))
273+
.env("RUSTDOC", builder.rustdoc(compiler));
274+
add_rustdoc_cargo_lld_flags(&mut cmd, builder, compiler.host, true);
275+
builder.run_delaying_failure(cmd);
275276
}
276277
}
277278

@@ -1030,6 +1031,8 @@ impl Step for RustdocGUI {
10301031
cmd.env("RUSTDOC", builder.rustdoc(self.compiler))
10311032
.env("RUSTC", builder.rustc(self.compiler));
10321033

1034+
add_rustdoc_cargo_lld_flags(&mut cmd, builder, self.compiler.host, true);
1035+
10331036
for path in &builder.paths {
10341037
if let Some(p) = util::is_valid_test_suite_arg(path, "tests/rustdoc-gui", builder) {
10351038
if !p.ends_with(".goml") {

‎src/bootstrap/util.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
use build_helper::util::{fail, try_run};
77
use std::env;
8+
use std::ffi::{OsStr, OsString};
89
use std::fs;
910
use std::io;
1011
use std::path::{Path, PathBuf};
@@ -498,7 +499,7 @@ pub fn dir_is_empty(dir: &Path) -> bool {
498499

499500
pub fn add_rustdoc_lld_flags(
500501
cmd: &mut Command,
501-
builder: &Builder,
502+
builder: &Builder<'_>,
502503
target: TargetSelection,
503504
single_threaded: bool,
504505
) {
@@ -514,3 +515,41 @@ pub fn add_rustdoc_lld_flags(
514515
}
515516
}
516517
}
518+
519+
pub fn add_rustdoc_cargo_lld_flags(
520+
cmd: &mut Command,
521+
builder: &Builder<'_>,
522+
target: TargetSelection,
523+
single_threaded: bool,
524+
) {
525+
let mut args = vec![];
526+
527+
if let Some(linker) = builder.linker(target) {
528+
let mut flag = std::ffi::OsString::from("-Clinker=");
529+
flag.push(linker);
530+
args.push(flag);
531+
}
532+
if builder.is_fuse_ld_lld(target) {
533+
args.push(OsString::from("-Clink-arg=-fuse-ld=lld"));
534+
if single_threaded {
535+
args.push(OsString::from(format!(
536+
"-Clink-arg=-Wl,{}",
537+
lld_flag_no_threads(target.contains("windows"))
538+
)));
539+
}
540+
}
541+
542+
let mut flags = cmd
543+
.get_envs()
544+
.find(|(k, _)| *k == OsStr::new("RUSTDOCFLAGS"))
545+
.and_then(|(_, v)| v)
546+
.unwrap_or(OsStr::new(""))
547+
.to_os_string();
548+
for arg in args {
549+
if !flags.is_empty() {
550+
flags.push(" ");
551+
}
552+
flags.push(arg);
553+
}
554+
cmd.env("RUSTDOCFLAGS", flags);
555+
}

0 commit comments

Comments
 (0)
Please sign in to comment.