bazel-contrib / bazel-contrib/rules_foreign_cc
ld.lld seems unavailable when linking with libtool & using an hermetic toolchain
- Dominant language
- Starlark
- Stars
- 737
- Forks
- 270
- PR merge metrics
- No merged PRs in 30d
Description
Hello 👋
First of all, I'm very new to bazel, so please forgive any incorrect wording and stupid questions 😅
I'm trying to switch to bazel with a bunch of native dependencies, most of which get built using autotools, which we're wrapping from bazel using `foreign_cc`
Our main issue comes down to libtool not detecting `ld.lld` as a GNU linker, but I believe that's because the linker is simply not there.
Here's a minimal repro:
[minimal_repro.zip](https://github.com/user-attachments/files/17522208/minimal_repro.zip)
Libtool gets confused by what the linker is and fails to generate the .so, which causes the main visible error:
```
$> bazel build :libxcrypt --sandbox_debug
...
/usr/bin/install: cannot stat '.libs/libcrypt.so.2.0.0': No such file or directory
make[1]: *** [Makefile:1418: install-libLTLIBRARIES] Error 1
make[1]: Leaving directory '/home/hugo.beauzee/.cache/bazel/_bazel_hugo.beauzee/d935f933fb7b3a399ddc63c1fd0c0e1d/sandbox/processwrapper-sandbox/4/execroot/_main/bazel-out/k8-fastbuild/bin/libxcrypt.build_tmpdir'
make: *** [Makefile:3246: install-am] Error 2
_____ END BUILD LOGS _____
```
Looking at `bazel-out/k8-fastbuild/bin/libxcrypt_foreign_cc/Configure.log` we can see the compiler and linker being provided to xcrypt's build system:
```
+ CC=/home/hugo.beauzee/.cache/bazel/_bazel_hugo.beauzee/d935f933fb7b3a399ddc63c1fd0c0e1d/sandbox/processwrapper-sandbox/5/execroot/_main/external/hermetic_cc_toolchain~~toolchains~zig_sdk/tools/x86_64-linux-gnu.2.28/c++
+ CXX=/home/hugo.beauzee/.cache/bazel/_bazel_hugo.beauzee/d935f933fb7b3a399ddc63c1fd0c0e1d/sandbox/processwrapper-sandbox/5/execroot/_main/external/hermetic_cc_toolchain~~toolchains~zig_sdk/tools/x86_64-linux-gnu.2.28/c++
+ LD=/home/hugo.beauzee/.cache/bazel/_bazel_hugo.beauzee/d935f933fb7b3a399ddc63c1fd0c0e1d/sandbox/processwrapper-sandbox/5/execroot/_main/external/hermetic_cc_toolchain~~toolchains~zig_sdk/tools/ld.lld
```
While C compiler is there:
```
$> /home/hugo.beauzee/.cache/bazel/_bazel_hugo.beauzee/d935f933fb7b3a399ddc63c1fd0c0e1d/sandbox/processwrapper-sandbox/5/execroot/_main/external/hermetic_cc_toolchain~~toolchains~zig_sdk/tools/x86_64-linux-gnu.2.28/c++ -v
clang version 17.0.6 (https://github.com/ziglang/zig-bootstrap 4c78aa1bba84dbd324e178932cd52221417f63da)
Target: x86_64-unknown-linux-gnu.2.28
```
The linker doesn't appear to be:
```
$> /home/hugo.beauzee/.cache/bazel/_bazel_hugo.beauzee/d935f933fb7b3a399ddc63c1fd0c0e1d/sandbox/processwrapper-sandbox/5/execroot/_main/external/hermetic_cc_toolchain~~toolchains~zig_sdk/tools/ld.lld -v
zsh: no such file or directory: /home/hugo.beauzee/.cache/bazel/_bazel_hugo.beauzee/d935f933fb7b3a399ddc63c1fd0c0e1d/sandbox/processwrapper-sandbox/5/execroot/_main/external/hermetic_cc_toolchain~~toolchains~zig_sdk/tools/ld.lld
```
while I'd expect it to be, since the build is ran with `--sandbox_debug`
It's also worth noting that when running with `--spawn_strategy=local`, the issue doesn't reproduce
Thanks a lot in advance for taking a look!
Contributor guide
Research direction
Start with minimal_repro.zip and reproduce the build using --sandbox_debug, then compare it with --spawn_strategy=local. Inspect libxcrypt_foreign_cc/Configure.log and the reported CC and LD paths, especially the missing tools/ld.lld entry. Done means the hermetic sandbox build completes and generates the expected .so file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- zig
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100