iree icon indicating copy to clipboard operation
iree copied to clipboard

Stop relying on `CLANG_EXECUTABLE_VERSION` cached variable

Open bjacob opened this issue 1 year ago • 0 comments

Our build needs to know the path to Clang built-in headers to set up the compilation command line to build bitcode.

That path is always of the form clang/${LLVM_VERSION_MAJOR}/include.

In the bundled-LLVM case, we have a problem: LLVM_VERSION_MAJOR is only defined internally in llvm/CMakeLists.txt, not exported.

Historically we have worked around that by relying on the cached (and thus, exported) variable, CLANG_EXECUTABLE_VERSION. But that was very fragile. Being cached, it only had the expected meaning on a freshly nuked and cmake'd build directory. Anything beyond that, was gradually drifting, with CLANG_EXECUTABLE_VERSION retaining the original value that it had when the build directory was originally CMake'd. As the CLang CMake setup copies headers to the build directory and we were #including them from there, that means that we were building bitcode against whichever stale copy of clang built-in headers we originally copied and used when first configured that build dir.

And when nuking a build dir's contents while preserving CMakeCache.txt, today I ran into a build failure: my cached CLANG_EXECUTABLE_VERSION was still saying 18 but the built-in headers were now being copied to another directory as the upstream version number had been bumped to 19.

So, however fragile that is, this PR switching this to just parsing the source llvm/CMakeLists.txt is an improvement.

bjacob avatar Feb 28 '24 20:02 bjacob