This is an archive of the discontinued LLVM Phabricator instance.

[lldb][NFCI] Change logic to find clang resource dir in standalone builds
ClosedPublic

Authored by bulbazord on Jul 25 2023, 3:41 PM.

Details

Summary

As of 0beffb854209a41f31beb18f9631258349a99299 there is a CMake
function to actually calculate the relative path to the clang resource
directory. Currently we have some bespoke logic that looks in a few
places, but with this new function we should be able to eliminate some
complexity here.

Also, I moved the functionality from LLDBConfig to LLDBStandalone since
it is only used in standalone builds.

Diff Detail

Event Timeline

bulbazord created this revision.Jul 25 2023, 3:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2023, 3:41 PM
bulbazord requested review of this revision.Jul 25 2023, 3:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2023, 3:41 PM
This revision is now accepted and ready to land.Jul 25 2023, 3:44 PM

This broke the standalone bot: https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake-standalone/

I was able to reproduce the issue locally and reverting this commit fixes the issue.

mgorny added subscribers: paperchalice, tstellar, mgorny.EditedAug 3 2023, 8:22 AM

I'm not sure if it was really intended but the new API is kinda horrible, at least for us in Gentoo.

Our install prefix is /usr/lib/llvm/NN, whereas clang resource dir is /usr/lib/clang/NN.

If I don't override CLANG_RESOURCE_DIR, it infers the wrong directory:
/usr/lib/llvm/18/lib64/cmake/clang/../../..//lib64/clang/18.

To get the correct directory, I need to pass:
-DCLANG_RESOURCE_DIR="../../../clang/${LLVM_MAJOR}"
which is absolutely counterintuitive (the path gets appended to:
/usr/lib/llvm/18/lib64/cmake/clang/../../../bin
).

Not saying it's not workable but I'd hardly call that an improvement over the previous API.

CC @tstellar, @paperchalice.

I'm not sure if it was really intended but the new API is kinda horrible, at least for us in Gentoo.

Our install prefix is /usr/lib/llvm/NN, whereas clang resource dir is /usr/lib/clang/NN.

If I don't override CLANG_RESOURCE_DIR, it infers the wrong directory:
/usr/lib/llvm/18/lib64/cmake/clang/../../..//lib64/clang/18.

To get the correct directory, I need to pass:
-DCLANG_RESOURCE_DIR="../../../clang/${LLVM_MAJOR}"
which is absolutely counterintuitive (the path gets appended to:
/usr/lib/llvm/18/lib64/cmake/clang/../../../bin
).

Not saying it's not workable but I'd hardly call that an improvement over the previous API.

CC @tstellar, @paperchalice.

To give some context for my change, downstream for swift there are further changes that involve finding and/or using the clang resource directory. I wanted to take advantage of the new functionality get_clang_resource_dir in order to replace the bespoke logic that existed before. Downstream, we had some additional logic to find it again in some cases (which was frustratingly different than what was here before).

If the API is unintuitive or doesn't serve you well, I'm of the opinion that we should change the API. It think it would be a lot easier for your use case if we could tell CMake the absolute path to the clang resource dir instead of having to craft some relative directory that works around the implementation instead of with it.

mgorny added a comment.Aug 4 2023, 8:18 AM

Yeah, that's why I CC-ed the two people who committed that API, as I don't really understand how it's supposed to work (and don't really have the capacity to figure it out).

When I made D141907, I want get_clang_resource_dir in cmake and GetResourcesPath in clang to have the same behavior and it also respects the doc string of CLANG_RESOURCE_DIR, but the behavior of GetResourcesPath itself is unintuitive when custom resource path is empty.

I'm not sure if it was really intended but the new API is kinda horrible, at least for us in Gentoo.

Our install prefix is /usr/lib/llvm/NN, whereas clang resource dir is /usr/lib/clang/NN.

If I don't override CLANG_RESOURCE_DIR, it infers the wrong directory:
/usr/lib/llvm/18/lib64/cmake/clang/../../..//lib64/clang/18.

IIUC, the resource dir should be /usr/lib/llvm/18/lib64/clang/18 when CLANG_RESOURCE_DIR is empty.

To get the correct directory, I need to pass:
-DCLANG_RESOURCE_DIR="../../../clang/${LLVM_MAJOR}"
which is absolutely counterintuitive (the path gets appended to:
/usr/lib/llvm/18/lib64/cmake/clang/../../../bin
).

Not saying it's not workable but I'd hardly call that an improvement over the previous API.

CC @tstellar, @paperchalice.

The API here is indeed user unfriendly, a possible improvement is to let CLANG_RESOURCE_DIR aslo accept absolute path.
Also, CLANG_RESOURCE_DIR doesn't seem to work in standalone mode, some extra variables should be exported to ClangConfig.cmake e.g. the install prefix and bin dir of clang.