It is possible to build LLVM with just the "llvm" and "cmake" components checked out. This requires disabling the LLVM_INCLUDE_BENCHMARKS and LLVM_INCLUDE_TESTS options. These options are not passed through to the native build when cross-compiling though, so the build will break if the "third-party" component is missing. We don't need the benchmarks or tests for the native build, so disable these unconditionally. This fixes cross-compiling on Gentoo, where only the required components are checked out.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
If this is accepted, note that I don't have commit access. Please merge it as James Le Cuirot <chewi@gentoo.org>.
Can you show an example CMake command line?
I am unfamiliar with CMake: how is "third-party components" related to LLVM_INCLUDE_TESTS and LLVM_INCLUDE_BENCHMARKS?
Is it possible to use qemu-user to run some cross-compiling tests?
It's hard to demonstrate, but I'll explain in more detail. Gentoo disables the options here. If they weren't disabled, you'd need the third-party directory/component present here and here. That's fine for a regular build, but with a cross build, CMake is invoked a second time so that it can build and execute binaries on the build host (e.g. llvm-tblgen). This happens here and here. That second invocation doesn't pass through any of the original CMake arguments, so LLVM_INCLUDE_TESTS and LLVM_INCLUDE_BENCHMARKS get enabled by default, and the build breaks because third-party is missing.
Thanks for the patch!
The change seems okay in this case, though I wonder if passing through all other LLVM_INCLUDE_* parameters could be cleaner in principle, instead of hard-disabling. (I know the NATIVE build isn't meant to be used in a way that requires those optional components e.g. benchmarks, examples, runtimes to be enabled, but IMO passing through is less of a special-case than overriding in general.)
OTOH while at it I think you could add the other LLVM_INCLUDE_* as well, for better future-proofing.
It looks good to me as-is.
@chewi, let me know if you're planning to change it or if I should merge as-is.
I'd like to keep it as it is
I'm not sure if you meant dynamically checking for anything beginning with LLVM_INCLUDE_. While that is possible, it relies on a CMake feature that is really meant for debugging. I'd also need to avoid LLVM_INCLUDE_DIR(S) which is used for something else.
Even then, I think hard-disabling is safer than passing through. If we know these things aren't needed then disabling them means less chance of something going wrong. What is one of them requires a library you don't have on your build host?
So I was going to hard-disable the others, but I think you'd actually need UTILS and possibly TOOLS. I doubt the others would impact the build time, as I think it only builds the things you need anyway. BENCHMARKS and TESTS are just special cases because the third-party directory needs to exist at configure time.