Remove gold config option and use lld on Linux (#30100)

There are a few motivations for this change:

 1. lld is demonstrably faster than gold, but is really only stable on
    Linux at the moment. There's a good chance that it will be ready for
    all platforms soon though.
 2. Most people do not have gold installed on MacOS and Windows. You'd
    have to do this manually through homebrew. I think it's a safe
    assumption that this probably won't be slowing things down much on
    those platforms.
 3. We need to remove all configuration of the build that happens while
    running `./mach build` if we ever hope to make `cargo build`
    equivalent to the mach build. This unlocks static configuration of
    the rustflags. One of the big blockers for proper `cargo build`
    support.
This commit is contained in:
Martin Robinson 2023-08-15 15:53:05 +02:00 committed by GitHub
parent 2778beeb7a
commit 16445983ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 6 deletions

View file

@ -509,9 +509,11 @@ class CommandBase(object):
if self.config["build"]["rustflags"]:
env['RUSTFLAGS'] = env.get('RUSTFLAGS', "") + " " + self.config["build"]["rustflags"]
if self.config["tools"]["rustc-with-gold"]:
if shutil.which('ld.gold'):
env['RUSTFLAGS'] = env.get('RUSTFLAGS', "") + " -C link-args=-fuse-ld=gold"
# Turn on rust's version of lld if we are on x86 Linux.
# TODO(mrobinson): Gradually turn this on for more platforms, when support stabilizes.
# See https://github.com/rust-lang/rust/issues/39915
if not self.cross_compile_target and effective_target == "x86_64-unknown-linux-gnu":
env['RUSTFLAGS'] = env.get('RUSTFLAGS', "") + " -Zgcc-ld=lld"
if not (self.config["build"]["ccache"] == ""):
env['CCACHE'] = self.config["build"]["ccache"]

View file

@ -4,9 +4,6 @@
# Tool options
[tools]
# If rustc-with-gold is true, will try to find and use gold linker with rustc.
# Defaults to true
rustc-with-gold = true
# If uncommented, this command is used instead of the platforms default
# to notify at the end of a compilation that took a long time.