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

dependency(LLVM) always finds newest installation #13906

Open
mathstuf opened this issue Nov 15, 2024 · 5 comments
Open

dependency(LLVM) always finds newest installation #13906

mathstuf opened this issue Nov 15, 2024 · 5 comments
Labels
dependencies dependency:cmake Issues related to `dependency` with the `cmake` method

Comments

@mathstuf
Copy link
Contributor

Describe the bug
Meson's CMake LLVM strategy ends up finding the newest version rather than the intended version if it is older than any version found by default. This is because of the LLVM_MESON_VERSIONS loop that searches for versions in decreasing order. When it finds the first one, it stops searching thinking it is suitable.

I was able to find the intended one by leveraging CMake's search mechanisms by neutering the version loops and just searching for LLVM with a suitable CMAKE_PREFIX_PATH setup rather than searching for any specific versions.

Ideas:

  • apply any version constraints to the LLVM_MESON_VERSIONS list before searching (allows projects to say ['>= 15', '< 16'] or something)
  • remove the version loop and direct CMake through its find_package mechanisms
  • prefer the llvm-config search strategy (easy to override at build time with LLVM_CONFIG envvar)
  • add a way for end users to influence package search strategies

To Reproduce
Building mesa with LLVM support. System LLVM installed is newer (e.g., 17, 19) than custom build (e.g., 15). By default Meson will use the CMake search strategy and always find the newest (system here) version rather than the intended version.

Setup:

  • Fedora 41 container
  • dnf install llvm-devel (brings LLVM 19)
  • build and install an older LLVM (15.0.6 in my case)
  • try to point Mesa's build to use LLVM 15

Expected behavior
Selecting the LLVM to use should be "easy".

system parameters

  • what meson --version
    1.5.2
@mathstuf
Copy link
Contributor Author

@dcbaker
Copy link
Member

dcbaker commented Nov 15, 2024

If you're using cmake, invoking with meson setup builddir -Dcmake_prefix_path=... may solve the problem.

Upstream Mesa moved to requring llvm-config for !Windows. I'm not sure that the move the cmake as the default finder was a good one, and I'd be okay with swapping back to llvm-config before cmake if others are cool with that.

As an aside, LLVM + Clang are the reason I got involved with cps. This is a hard set of dependencies to use.

@rilian-la-te
Copy link
Contributor

rilian-la-te commented Nov 15, 2024

@dcbaker can you show why upstream Mesa went for llvm-config for !Windows (especially for Linux) and how to fix it (for using CMake with Mesa's Meson scripts)?

@dcbaker
Copy link
Member

dcbaker commented Nov 15, 2024

@rilian-la-te https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25042

Basically the same complaint we have here, the cmake finder doesn't do the right thing, even when you set the options correctly

@mathstuf
Copy link
Contributor Author

I think the issue is that the CMake code wrapping find_package tries "too hard" and ends up making uncontrollable behavior. About the only thing that needs to happen is to support alternative NAMES of the CMake package rather than any version-specific queries. Then CMAKE_PREFIX_PATH can be used to direct CMake to do any preferential search locations with -Dcmake_prefix_path= rather than have to work with the LLVM_MESON_VERSIONS loop.

@eli-schwartz eli-schwartz added dependencies dependency:cmake Issues related to `dependency` with the `cmake` method labels Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies dependency:cmake Issues related to `dependency` with the `cmake` method
Projects
None yet
Development

No branches or pull requests

4 participants