Skip to content

bazel: use built-in rust-lld#3219

Closed
mgeisler wants to merge 1 commit into
mainfrom
disable-llvm-toolchain
Closed

bazel: use built-in rust-lld#3219
mgeisler wants to merge 1 commit into
mainfrom
disable-llvm-toolchain

Conversation

@mgeisler

Copy link
Copy Markdown
Collaborator

This removes the huge LLVM toolchain and instead instructs Rust to use its built-in linker.

This removes the huge LLVM toolchain and instead instructs Rust to use
its built-in linker.
@mgeisler

Copy link
Copy Markdown
Collaborator Author

This is an alternative to #3216 — I tested it locally, and it unfortunately doesn't work out of the box since the built-in linker cannot find the libraries linked against.

I wonder if this has something to do with a "sysroot"?

The error I get:

error: linking with `bazel-out/k8-opt-exec/bin/external/rules_rust++rust+rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools/rust_toolchain/lib/rustlib/x86_64-unknown-linux-gnu/bin/rust-lld` failed: exit status: 1
  |
  = note:  "bazel-out/k8-opt-exec/bin/external/rules_rust++rust+rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools/rust_toolchain/lib/rustlib/x86_64-unknown-linux-gnu/bin/rust-lld" "-flavor" "gnu" "/home/mg/.cache/bazel/_bazel_mg/5300e7eab28c9f30004e4618f1a962d5/sandbox/linux-san dbox/1/execroot/_main/bazel-out/k8-opt-exec/bin/external/rules_rust+/util/process_wrapper/rustcwS028J/symbols.o" "<17 object files omitted>" "--as-needed" "-Bstatic" "/home/mg/.cache/bazel/_bazel_mg/5300e7eab28c9f30004e4618f1a962d5/execroot/_main/bazel-out/k8-opt-exec/bin/external/rules_rust++i+rules_rust_tinyjson/libtinyjson-1317710085.rlib" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,libcfg_if-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/home/mg/.cache/bazel/_bazel_mg/5300e7eab28c9f30004e4618f1a962d5/sandbox/linux-sandbox/1/execroot/_main/bazel-out/k8-opt-exec/bin/external/rules_rust+/util/process_wrapper/rustcwS028J/raw-dylibs" "--eh-frame-hdr" "-z" "noexecstack" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "bazel-out/k8-opt-exec/bin/external/rules_rust+/util/process_wrapper/process_wrapper" "--gc-sections" "-pie" "-z" "relro" "-z" "now" "-O1" "--strip-debug"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: rust-lld: error: unable to find library -lgcc_s
          rust-lld: error: unable to find library -lutil
          rust-lld: error: unable to find library -lrt
          rust-lld: error: unable to find library -lpthread
          rust-lld: error: unable to find library -lm
          rust-lld: error: unable to find library -ldl
          rust-lld: error: unable to find library -lc


error: aborting due to 1 previous error

mgeisler added a commit that referenced this pull request Jun 23, 2026
This reverts #3204 due to repeated build failures in CI.

The LLVM toolchain is huge, taking up 11 GB in the Bazel repository
cache:

```
% cd  $(bazel info repository_cache)/contents/f7d96c1d09ac1778314f1a73179da702edd9e75e8ef9231c06fa7ef6229cf47d
% du -hs .
11G     .
```

This is way too large for the GitHub CI runners, which are [documentated
to have 14 GB of free disk
space](https://docs.github.com/en/actions/reference/runners/github-hosted-runners).

The result is seemingly random build failures where we run out of disk
space. See [run

27773830289](https://github.com/google/comprehensive-rust/actions/runs/27773830289)
which had several failed translation builds.

The result of this is that we fall back on non-hermetic builds for the
time being. This is the status quo from before adopting Bazel. We should
look for another way to fix the

> warning: the gold linker is deprecated and has known bugs with Rust

warnigns. Perhaps more targeted by uninstalling `gold` and making sure
another linker is picked up in CI? Universally instructing `rustc` to
use `rust-lld` does not work (#3219) and using the small
`hermetic_cc_toolchain` (Zig-based) also failed (#3216).
@mgeisler

Copy link
Copy Markdown
Collaborator Author

Closing this for now as we have #3221 merged. Perhaps we can revisit it later and make it work with some tweaks.

@mgeisler mgeisler closed this Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant