Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustbuild: Build tests with LLD if use-lld = true was passed #76378

Merged
merged 5 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@
# supported platforms. The LLD from the bootstrap distribution will be used
# and not the LLD compiled during the bootstrap.
#
# LLD will not be used if we're cross linking or running tests.
# LLD will not be used if we're cross linking.
#
# Explicitly setting the linker for a target will override this option when targeting MSVC.
#use-lld = false
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ fn main() {
if let Ok(host_linker) = env::var("RUSTC_HOST_LINKER") {
cmd.arg(format!("-Clinker={}", host_linker));
}
if env::var_os("RUSTC_HOST_FUSE_LD_LLD").is_some() {
cmd.arg("-Clink-args=-fuse-ld=lld");
}

if let Ok(s) = env::var("RUSTC_HOST_CRT_STATIC") {
if s == "true" {
Expand Down
5 changes: 4 additions & 1 deletion src/bootstrap/bin/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ fn main() {
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
cmd.arg("-Z").arg("force-unstable-if-unmarked");
}
if let Some(linker) = env::var_os("RUSTC_TARGET_LINKER") {
if let Some(linker) = env::var_os("RUSTDOC_LINKER") {
let mut arg = OsString::from("-Clinker=");
arg.push(&linker);
cmd.arg(arg);
}
if env::var_os("RUSTDOC_FUSE_LD_LLD").is_some() {
cmd.arg("-Clink-args=-fuse-ld=lld");
}

// Needed to be able to run all rustdoc tests.
if let Some(ref x) = env::var_os("RUSTDOC_RESOURCE_SUFFIX") {
Expand Down
17 changes: 11 additions & 6 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,11 @@ impl<'a> Builder<'a> {
cmd.env_remove("MAKEFLAGS");
cmd.env_remove("MFLAGS");

if let Some(linker) = self.linker(compiler.host, true) {
cmd.env("RUSTC_TARGET_LINKER", linker);
if let Some(linker) = self.linker(compiler.host) {
cmd.env("RUSTDOC_LINKER", linker);
}
if self.is_fuse_ld_lld(compiler.host) {
cmd.env("RUSTDOC_FUSE_LD_LLD", "1");
}
cmd
}
Expand Down Expand Up @@ -1041,16 +1044,18 @@ impl<'a> Builder<'a> {
}
}

if let Some(host_linker) = self.linker(compiler.host, true) {
if let Some(host_linker) = self.linker(compiler.host) {
cargo.env("RUSTC_HOST_LINKER", host_linker);
}
if self.is_fuse_ld_lld(compiler.host) {
cargo.env("RUSTC_HOST_FUSE_LD_LLD", "1");
}

if let Some(target_linker) = self.linker(target, true) {
if let Some(target_linker) = self.linker(target) {
let target = crate::envify(&target.triple);
cargo.env(&format!("CARGO_TARGET_{}_LINKER", target), target_linker);
}

if self.config.use_lld && !target.contains("msvc") {
if self.is_fuse_ld_lld(target) {
rustflags.arg("-Clink-args=-fuse-ld=lld");
}

Expand Down
15 changes: 8 additions & 7 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ impl Build {
}

/// Returns the path to the linker for the given target if it needs to be overridden.
fn linker(&self, target: TargetSelection, can_use_lld: bool) -> Option<&Path> {
fn linker(&self, target: TargetSelection) -> Option<&Path> {
if let Some(linker) = self.config.target_config.get(&target).and_then(|c| c.linker.as_ref())
{
Some(linker)
Expand All @@ -863,18 +863,19 @@ impl Build {
&& !target.contains("msvc")
{
Some(self.cc(target))
} else if target.contains("msvc")
&& can_use_lld
&& self.config.use_lld
&& self.build == target
{
// Currently we support using LLD directly via `rust.use_lld` option only with MSVC
} else if self.config.use_lld && !self.is_fuse_ld_lld(target) && self.build == target {
Some(&self.initial_lld)
} else {
None
}
}

// LLD is used through `-fuse-ld=lld` rather than directly.
// Only MSVC targets use LLD directly at the moment.
fn is_fuse_ld_lld(&self, target: TargetSelection) -> bool {
self.config.use_lld && !target.contains("msvc")
}

/// Returns if this target should statically link the C runtime, if specified
fn crt_static(&self, target: TargetSelection) -> Option<bool> {
if target.contains("pc-windows-msvc") {
Expand Down
16 changes: 12 additions & 4 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,11 @@ impl Step for RustdocTheme {
.env("CFG_RELEASE_CHANNEL", &builder.config.channel)
.env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
.env("RUSTC_BOOTSTRAP", "1");
if let Some(linker) = builder.linker(self.compiler.host, true) {
cmd.env("RUSTC_TARGET_LINKER", linker);
if let Some(linker) = builder.linker(self.compiler.host) {
cmd.env("RUSTDOC_LINKER", linker);
}
if builder.is_fuse_ld_lld(self.compiler.host) {
cmd.env("RUSTDOC_FUSE_LD_LLD", "1");
}
try_run(builder, &mut cmd);
}
Expand Down Expand Up @@ -1061,17 +1064,22 @@ impl Step for Compiletest {
flags.push("-Zunstable-options".to_string());
flags.push(builder.config.cmd.rustc_args().join(" "));

// Don't use LLD here since we want to test that rustc finds and uses a linker by itself.
if let Some(linker) = builder.linker(target, false) {
if let Some(linker) = builder.linker(target) {
cmd.arg("--linker").arg(linker);
}

let mut hostflags = flags.clone();
hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
if builder.is_fuse_ld_lld(compiler.host) {
hostflags.push("-Clink-args=-fuse-ld=lld".to_string());
}
cmd.arg("--host-rustcflags").arg(hostflags.join(" "));

let mut targetflags = flags;
targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
if builder.is_fuse_ld_lld(target) {
targetflags.push("-Clink-args=-fuse-ld=lld".to_string());
}
cmd.arg("--target-rustcflags").arg(targetflags.join(" "));

cmd.arg("--docck-python").arg(builder.python());
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-make-fulldeps/tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ BARE_RUSTDOC := $(HOST_RPATH_ENV) '$(RUSTDOC)'
RUSTC := $(BARE_RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR) $(RUSTFLAGS)
RUSTDOC := $(BARE_RUSTDOC) -L $(TARGET_RPATH_DIR)
ifdef RUSTC_LINKER
RUSTC := $(RUSTC) -Clinker=$(RUSTC_LINKER)
RUSTDOC := $(RUSTDOC) -Clinker=$(RUSTC_LINKER)
RUSTC := $(RUSTC) -Clinker='$(RUSTC_LINKER)'
RUSTDOC := $(RUSTDOC) -Clinker='$(RUSTC_LINKER)'
endif
#CC := $(CC) -L $(TMPDIR)
HTMLDOCCK := '$(PYTHON)' '$(S)/src/etc/htmldocck.py'
Expand Down