Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Libtool is called with wrong name on Darwin if paths are absolute #385

Open
depp opened this issue Sep 2, 2024 · 0 comments
Open

Libtool is called with wrong name on Darwin if paths are absolute #385

depp opened this issue Sep 2, 2024 · 0 comments

Comments

@depp
Copy link

depp commented Sep 2, 2024

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:

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

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.

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

No branches or pull requests

1 participant