Conversation
In case multiple LLVM/Clang versions are installed on a machine it is not determined which one is used. In this commit LLVM 7 is enforced because cpp plugin compiles with this version.
|
This change breaks the CI pipeline on Ubuntu 16.04, where LLVM 7 is installed from the official LLVM repo. (Since the version in the Ubuntu package repository is without RTTI.) Can you take a look at it? |
|
Yes, I've seen the error. This is a little strange to me because in |
|
I have pushed a minor modification (see commit aeab84a) to dump the LLVM related information BEFORE locating the Clang package. This uncovered the fact that with the modification of this PR, an incorrect LLVM instance in found. The source of the issue is complex. I will summarize how these Travis CI containers are configured regarding the LLVM/Clang tooling:
Now, requiring LLVM to be version 7 in the |
|
Looking at this I found the root of the problem the same, unfortunately there is a bug in the cmake code which does not accept 7.1 as version 7. Cmake will even give a message that says version 7.1.0.0 was considered but not accepted. (I tested this behavior in an Ubuntu Xenial derived docker image.) This is a link to the cmake dev forum. They know about this issue, but it's not solved even in the newest version (I tested it). |
…into bruntib-llvm_version
|
I have updated this PR with master, because our Travis configuration has changed since and now we depend on the I believed that this would solve the issue of having multiple LLVM/Clang versions on Xenial (7.0.0 without RTTI and 7.1.0 with RTTI) and CMake selecting the incorrect one. My belief was based on the above linked documentation of Travis, which states that Clang is preinstalled (without RTTI) on the Well, that is not the case, the documentation of Travis is incorrect. So the CI still fails unfortunately for this. |
|
Minimal LLVM/Clang version (now 10) is still not configured in the appropriate |
|
How will this handle 10.0.1 or even 11? Are we sure that there aren't any breaking changes between 10 and 11? (Most likely there won't be between 10 and 10.0.1, but from 10 to 11 there could be...) LLVM 11 isn't released yet (AFAIK it shall be in a few weeks). Is there a way CMake could require exact version, and not minimal one? If the user follows the guide in specifying The two breaking changes from 7 to 10 that we had to tackle happened between different major version releases, IIRC. |
According to the documentation the developers of LLVM/Clang have to properly set up compatibility between versions and then CMake will decide if the requested version is compatible with the found one.
There is an |
|
CI passes with these modifications. |
@mcserep Note that the CI script has
The only thing that Clang's found CMake file does, both for version 12 (current master) and version 7 and version 10, etc, is this. For the package manager version of Clang 7.0 on Ubuntu 20.04: # This file allows users to call find_package(Clang) and pick up our targets.
# Compute the installation prefix from this LLVMConfig.cmake file location.
get_filename_component(CLANG_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_FILE}" REALPATH)
get_filename_component(CLANG_INSTALL_PREFIX "${CLANG_INSTALL_PREFIX}" PATH)
get_filename_component(CLANG_INSTALL_PREFIX "${CLANG_INSTALL_PREFIX}" PATH)
get_filename_component(CLANG_INSTALL_PREFIX "${CLANG_INSTALL_PREFIX}" PATH)
get_filename_component(CLANG_INSTALL_PREFIX "${CLANG_INSTALL_PREFIX}" PATH)
find_package(LLVM REQUIRED CONFIG
HINTS "${CLANG_INSTALL_PREFIX}/lib/cmake/llvm")I guess those set(LLVM_VERSION_MAJOR 7)
set(LLVM_VERSION_MINOR 0)
set(LLVM_VERSION_PATCH 1)
set(LLVM_PACKAGE_VERSION 7.0.1)For a local compilation of find_package(LLVM REQUIRED CONFIG
HINTS "/home/w/Work/LLVM/Build/lib/cmake/llvm")So there isn't any connection between the two, in terms of versions. I need a bit more information for understanding this. What will happen, if someone somehow has installed LLVM version X, and Clang version Y. Namely, if I have done the following in Docker:
While I understand this particular environment isn't up to the documentation, this shows the discrepancy. CodeCompass's CMake happily eats the broken environment, giving me no errors, if I omit the But of course, doing the build fails, with incredibly weird errors. Weird because this output has zero indication that we are dealing with a version discrepancy. How could an include chain of only All in all, I believe it is not a good idea to pose restrictions on requiring a particular LLVM version, while we let the user loose with "any" Clang version. Au contraire, perhaps we should first require the proper version of Clang, considering the dependency is that we (CodeCompass) depend on Clang mainly (and not "on LLVM" per se), which in turn depends (as seen, on the package manager and CMake level!) on the right "version" (not expressed as version tags but rather the install directory of the right version of LLVM baked into the config file) of LLVM. |
|
Another funny thing: due to having both LLVM 7 and 10 installed in the CI, another discrepancy is present: the |
It was only left there, because previously there was two LLVM 7 versions in the Travis containers, so the precise path was required to be defined. This should be removable now, and we can also specify the Clang version in the I have done that in 8720f8b, but unfortunately it seems that the CMake support for Clang is incomplete, it does not provide version information:
So ultimately yes: we cannot specify the Clang version, because Clang's CMake support is deficient. Therefore we either:
|
|
Bl... blimey. Yeah, this is a bummer, thank you for checking this out. I'm not terribly opposed to this patch, just want to make sure we don't do anything that gives users a false sense of security if it results in hard to grasp errors. For the sake of clarity, could you add two lines to the CMakeList? Basically, just make sure that during configure time, we at least give the user a message that uses So in case of us getting a bug report about compilation issues we can be explicit about "Hey, you definitely have the wrong version installed, see Clang said it's 7.0.1!". Although if we want this to be extra pedantic, a preprocessor magic could also work, Clang defines the (This file should trickle down into every header whatsoever, but if not, including I vaguely remember something about CMake's |
|
Unfortunately while there is a So there is really no way to get the Clang version in CMake. Note, that even if the binary folder would be known, we still wouldn't know the binary's name! E.g. on Bionic it is I think this is the best we can do for now: # Find LLVM
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
# Check whether RTTI is on for LLVM
message(STATUS "Using RTTI for LLVM: ${LLVM_ENABLE_RTTI}")
if(NOT LLVM_ENABLE_RTTI)
message(SEND_ERROR "RTTI is required for LLVM")
endif()
# Check LLVM version
if (${LLVM_PACKAGE_VERSION} VERSION_LESS "10")
message(SEND_ERROR "Loaded LLVM version must be at least 10.0, ${LLVM_PACKAGE_VERSION} found.")
endif()
# Add LLVM to the library path
mark_as_run_env_path(LD_LIBRARY_PATH "${LLVM_BUILD_LIBRARY_DIR}")
# Find Clang
find_package(Clang REQUIRED CONFIG)
message(STATUS "Using ClangConfig.cmake in: ${Clang_DIR}")And then |
|
Can we merge this @whisperity , @intjftw ? |
whisperity
left a comment
There was a problem hiding this comment.
@mcserep Yes, sorry, I realise my previous letter was full of thoughts but also very vague. I think it's okay... I think I'll try getting around to fixing the CMake parts of Clang to support this, surely we aren't the only ones out there who get broken over this.
In case multiple LLVM/Clang versions are installed on a machine it is
not determined which one is used. In this commit LLVM 7 is enforced
because cpp plugin compiles with this version.