Increased build time and dependencies due to rust-lld in bootstrap builds

We observed that recent changes in Rust have enabled and built rust-lld as part of the bootstrap process and has significant improvement in build and linking times.

While integrating Rust into our Yocto-based project, we attempted to support and build rust-lld as part of the Rust build process.
During this effort, we encountered a few issues and would like to confirm whether they are expected or indicative of a regression.

Observations:

  1. Additional Build Dependencies
    Enabling rust-lld introduced new dependencies not previously required for the bootstrap build:
    ninja, openssl, pkg-config, bash (A few of them are mentioned in rust/INSTALL.md at master · rust-lang/rust · GitHub)

    Following errors were encountered:

1.
   error: failed to run custom build command for `openssl-sys v0.9.106`
   | Could not find openssl via pkg-config:
   |   The pkg-config command could not be found.

   2.
   | Building LLD for x86_64-unknown-linux-gnu
   |
   | Couldn't find required command: ninja (or ninja-build)
   |
   | You should install ninja as described at
   | <https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages>,
   | or set `ninja = false` in the `[llvm]` section of `config.toml`.
   | Alternatively, set `download-ci-llvm = true` in that `[llvm]` section
   | to download LLVM rather than building it.
  1. Increase in Build Time and Filesystem Usage
    We observed significant increases in both build time and disk usage during the bootstrap process:

    Build time increased from ~32 minutes to ~45 minutes (+40%)
    Disk usage increased from ~10 GB to ~13 GB (+30%)

Questions & Concerns:

  • Is there a comprehensive document or reference for rust-lld that outlines its purpose, requirements, and implications for downstream build systems?
  • Are these additional dependencies and the observed increases in build time and space expected as part of rust-lld support, or could this be a regression?
  • Based on our understanding, rust-lld is not yet fully stable and is currently enabled by default only for x86_64-unknown-linux-gnu. We also noticed (this commit, Do not enable LLD by default in the dist profile by Kobzol · Pull Request #143255 · rust-lang/rust · GitHub) disables rust-lld by default in distributed Rust sources.

Given the impact on various downstream distributions and the current stability status of rust-lld, is it recommended to enable and build rust-lld in place of the system/default linker for Rust-based projects?

We would appreciate any clarification or guidance on the intended usage and roadmap for rust-lld, especially for embedded and cross-compilation use cases.
Thanks.

1 Like

This has nothing to do with rust-lld. Rust-lld is a renamed lld, which does not use any rust code. This error is for the rust openssl-sys crate however.

Do you have ninja installed? If not follow the suggestion in the error to disable ninja usage.

Lld is a much faster linker than ld.bfd, thus using it for building rust programs reduces build time. And it is necessary when compiling for wasm.

Lld depends on LLVM. I'm guessing you were previously using the system LLVM install, but because rust-lld got enabled, (part of) the in-tree LLVM gets built too. If you use a system LLVM install, you may want to disable building rust-lld.

No, currently we don't build ninja. Is it recommended for building lld?

Currently, we set download-ci-llvm to false in config.toml. There's a separate rust-llvm in our sources which is used to provide llvm support for build rust. Perhaps similar to what you are referring to as system llvm.

Will that internally also build rust-lld? If yes, then we can disable building it as you suggested. Also, is it recommended to build and use rust-lld for cross-compilation target builds in downstream projects?

No, I mean you can point the llvm-config config key to the location of llvm-config in an existing LLVM installation. Are you doing this? If so then disable rust-lld building. If not, it should already have been complaining about missing ninja when building LLVM if you didn't disable ninja usage.

Can you post your config.toml?

I believe you are referring to llvm-config set in [target.x86_64-unknown-linux-gnu] and [target.x86_64-poky-linux-gnu].

So, we need not build rust-lld and can disable it right?
As per the given config.toml, are we already building and using rust-lld from the path mentioned in llvm-config installation?
Could you please confirm?

Here's the config.toml:

change-id = 116881

[target.x86_64-poky-linux-gnu]
llvm-config = "/home/poky/build/tmp/work/core2-64-poky-linux/rust/1.88.0/recipe-sysroot/usr/lib/llvm-rust/bin/llvm-config"
cxx = "/home/poky/build/tmp/work/core2-64-poky-linux/rust/1.88.0/wrapper/target-rust-cxx"
cc = "/home/poky/build/tmp/work/core2-64-poky-linux/rust/1.88.0/wrapper/target-rust-cc"
linker = "/home/poky/build/tmp/work/core2-64-poky-linux/rust/1.88.0/wrapper/target-rust-ccld"

[target.x86_64-unknown-linux-gnu]
llvm-config = "/home/poky/build/tmp/work/core2-64-poky-linux/rust/1.88.0/recipe-sysroot-native/usr/lib/llvm-rust/bin/llvm-config"
cxx = "/home/poky/build/tmp/work/core2-64-poky-linux/rust/1.88.0/wrapper/build-rust-cxx"
cc = "/home/poky/build/tmp/work/core2-64-poky-linux/rust/1.88.0/wrapper/build-rust-cc"
linker = "/home/poky/build/tmp/work/core2-64-poky-linux/rust/1.88.0/wrapper/build-rust-ccld"

[llvm]
static-libstdcpp = false
download-ci-llvm = false

[rust]
rpath = true
remap-debuginfo = true
download-rustc = false
llvm-tools = false
channel = "nightly"
optimize = true
verbose-tests = true

[build]
submodules = false
docs = false
rustc = "/home/poky/build/tmp/work/core2-64-poky-linux/rust/1.88.0/recipe-sysroot-native/usr/bin/rustc"
cargo = "/home/poky/build/tmp/work/core2-64-poky-linux/rust/1.88.0/recipe-sysroot-native/usr/bin/cargo"
extended = false
vendor = true
target = ["x86_64-poky-linux-gnu"]
host = ["x86_64-poky-linux-gnu"]
build = "x86_64-unknown-linux-gnu"

[install]
prefix = "/home/poky/build/tmp/work/core2-64-poky-linux/rust/1.88.0/image/usr"
bindir = "/home/poky/build/tmp/work/core2-64-poky-linux/rust/1.88.0/image/usr/bin"
libdir = "/home/poky/build/tmp/work/core2-64-poky-linux/rust/1.88.0/image/usr/lib"
datadir = "/home/poky/build/tmp/work/core2-64-poky-linux/rust/1.88.0/image/usr/share"
mandir = "/home/poky/build/tmp/work/core2-64-poky-linux/rust/1.88.0/image/usr/share/man"
sysconfdir = "/home/poky/build/tmp/work/core2-64-poky-linux/rust/1.88.0/image/etc"

Yes

Yes, that is what I would suggest.

What about this?
Thank you for the information and your help.

You can configure whether or not you build lld when building LLVM. I don't know what you have configured. In any case the executable would be called lld, not rust-lld when doing that. We rename lld to rust-lld to prevent conflicting with a system lld install, but there is no reason to do the rename when building against an already existing LLVM.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.