This is an archive of the discontinued LLVM Phabricator instance.

[cmake] Don't require third-party components when cross-compiling
ClosedPublic

Authored by chewi on Jan 7 2023, 6:30 AM.

Details

Summary

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.

Diff Detail

Event Timeline

chewi created this revision.Jan 7 2023, 6:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 7 2023, 6:30 AM
chewi requested review of this revision.Jan 7 2023, 6:30 AM
chewi added a comment.Jan 11 2023, 3:57 PM

If this is accepted, note that I don't have commit access. Please merge it as James Le Cuirot <chewi@gentoo.org>.

mgorny added a subscriber: MaskRay.

I think it makes sense but I'd like to get @MaskRay's opinion as well.

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?

chewi added a comment.Jan 12 2023, 1:37 PM

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.

MaskRay accepted this revision.Jan 12 2023, 3:14 PM
This revision is now accepted and ready to land.Jan 12 2023, 3:14 PM
xen0n added a comment.Jan 12 2023, 9:47 PM

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.

mgorny accepted this revision.Jan 12 2023, 11:17 PM

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.

chewi added a comment.Jan 13 2023, 1:25 AM

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.

This revision was landed with ongoing or failed builds.Jan 14 2023, 9:13 AM
This revision was automatically updated to reflect the committed changes.