bazel-contrib / bazel-contrib/toolchains_llvm
Libtool is called with wrong name on Darwin if paths are absolute
- Dominant language
- Starlark
- Stars
- 371
- Forks
- 283
- Avg merge
- 1d 55m
- Merged PRs (30d)
- 25
Description
Libtool is called as `libtool` instead of `llvm-libtool-darwin` if you use an LLVM that is installed locally on your system, on Darwin.
## How to Reproduce
* On a Mac,
* Install Clang+LLVM at some location on your filesystem (in my example, `/opt/llvm-18`),
* Use `llvm_toolchain` with the toolchain root set to that path,
* Build a static library.
Here is a Gist that can reproduce the issue: https://gist.github.com/depp/712aea59c1699c19a658852db53511a1
1. Install LLVM + Clang 18.1.8 at `/opt/llvm-18`.
2. Run `bazel build //:example` in the Gist.
## What hapens
Bazel will invoke `/opt/lvm-18/bin/libtool`. This fails, because `libtool` *should* be `llvm-libtool-darwin`.
Linking libexample.a failed: (Exit 1): libtool failed: error executing CppArchive command (from target //:example) /opt/llvm-18/bin/libtool @bazel-out/darwin_arm64-fastbuild/bin/libexample.a-2.params
## What causes this?
I see in `toolchain/internal/configure.bzl`, this code:
```python
def llvm_config_impl(rctx):
...
if not use_absolute_paths_llvm:
...
for tool_name, symlink_name in tools.items():
rctx.symlink(llvm_dist_rel_path + "bin/" + tool_name, tools_path_prefix + symlink_name)
...
else:
...
```
In `use_absolute_paths_llvm` is false, then the `libtool` symlink is created. However, symlinks are not created if the paths are absolute. Unfortunately, this means that `libtool` is not symlinked to `llvm-libtool-darwin`.
This is as far as I got. I think the correct solution here is probably to call `llvm-libtool-darwin` directly, rather than symlinking it.
## Workaround
```sh
ln -s llvm-libtool-darwin /opt/llvm-18/bin/libtool
```
Or, you know, don’t use a local version of LLVM. But this is a difficult approach—the LLVM + Clang download is large (1 GB) and seems to fail (maybe just due to its size), and the extracted archive is over 5 GB.
Contributor guide
Research direction
Start in toolchain/internal/configure.bzl at llvm_config_impl and compare the tool handling for use_absolute_paths_llvm with the symlink path. Reproduce the failure using the linked Gist and an LLVM installation rooted at an absolute path, then run the Bazel build. Done means Darwin archive builds invoke llvm-libtool-darwin rather than libtool.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100