This is an archive of the discontinued LLVM Phabricator instance.

[LLDB][Docs] Update cross compilation docs and examples
ClosedPublic

Authored by DavidSpickett on Aug 16 2023, 7:40 AM.

Details

Summary

To address https://github.com/llvm/llvm-project/issues/64616, this change
does the following:

  • Links back to the "Optional Dependencies" section from the cross compilation instructions where we talk about removing libraries. In the reported issue, the host libXML was found by CMAke somehow and disabling libXML fixed it, so this link should encourage users to try as many of those options as needed.
  • Removes the use of CMAKE_CROSS_COMPILING. In older CMake versions it seems you could set this manually but now the advice is to set CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR then let CMake figure it out.

    There is also CMAKE_SYSTEM_VERSION which the docs say you have to set too, but I can only find examples of Windows and Android builds using this. It might be needed to "cross" compile from one version of AArch64 Linux to another, but I can't confirm that.
  • Removes the tablegen tools paths in favour of DLLVM_NATIVE_TOOL_DIR. This one setting deals with all build tools in llvm that must be host versions.
  • Updates the explanations of the common options and orders them in some rough order of relevance with the "might be needed" later.

Diff Detail

Event Timeline

DavidSpickett created this revision.Aug 16 2023, 7:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 16 2023, 7:40 AM
DavidSpickett requested review of this revision.Aug 16 2023, 7:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 16 2023, 7:40 AM

I've confirmed the instructions work for x86 -> AArch64. The original issue was x86 -> Arm 32 bit, so I hope to get the issue reporter to confirm whether the instructions make sense with this change.

This revision is now accepted and ready to land.Aug 16 2023, 8:37 AM
bulbazord accepted this revision.Aug 16 2023, 10:11 AM

This is in line with my understanding of cross-compiling LLDB. It could be useful to also document some other interesting cross-compilation options like CMAKE_TOOLCHAIN_FILE or mention the use of CMake caches, but if you're unfamiliar or aren't comfortable listing those that's ok too.

I think CMAKE_TOOLCHAIN_FILE is the "proper" way to be passing CMAKE_SYSTEM_NAME etc. so let me look into that. It may be something we get away with with current CMake, but breaks later, much like CMAKE_CROSS_COMPILING seemed to be less effective as time went on.

On caches, let me check the rest of the doc because there are some caches in tree for Mac OS. If they're already mentioned I can expand that. Maybe I'll add a cache for the x86 -> aarch64 cross compile.

Address feedback from Github issue:

  • Include the whole command not just the additions.
  • Note how to find the possible values of CMAKE_SYSTEM_*.
  • Add a note about testing and setting the test compiler.

It could be useful to also document some other interesting cross-compilation options like CMAKE_TOOLCHAIN_FILE

So this is the way CMake prefers you to do it, but I don't really understand the best practice so I'll leave it out for now. We have plenty of caches that directly set the system and processor name in llvm already, so I am in good (/not as good as could be) company.

or mention the use of CMake caches, but if you're unfamiliar or aren't comfortable listing those that's ok too.

This seems like a general tip so I'm not sure it belongs here, beyond the fact that you might have 99 options to get a cross build, but want to tweak just one on top. Again, bit of a generic tip.

As to adding a cache file, one thing the Github poster mentioned is that if you don't set LLVM_NATIVE_TOOL_DIR we appear to compile the host tools for you now. So I'd like to land this as is, then I'll look into that and see if it can be even simpler.

Use <path-to-monorepo> so people have to think about what that should be for their build.

Will land Monday unless there are other comments.

It could be useful to also document some other interesting cross-compilation options like CMAKE_TOOLCHAIN_FILE

So this is the way CMake prefers you to do it, but I don't really understand the best practice so I'll leave it out for now. We have plenty of caches that directly set the system and processor name in llvm already, so I am in good (/not as good as could be) company.

IMO it's usually the safest/most sustainable way to maintain cross-compilation jobs. CMake documents all of the intricacies with cross-compiling to other platforms here on their page documenting cmake toolchains: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html
I don't think we need to include all the intricacies, but it might be nice to maintain a link to the cmake documentation so people can self-service a bit when they encounter issues.

or mention the use of CMake caches, but if you're unfamiliar or aren't comfortable listing those that's ok too.

This seems like a general tip so I'm not sure it belongs here, beyond the fact that you might have 99 options to get a cross build, but want to tweak just one on top. Again, bit of a generic tip.

As to adding a cache file, one thing the Github poster mentioned is that if you don't set LLVM_NATIVE_TOOL_DIR we appear to compile the host tools for you now. So I'd like to land this as is, then I'll look into that and see if it can be even simpler.

Sounds good to me. Thanks for working on this!

Link to CMake's cross compilation docs up front, as a fallback.

IMO it's usually the safest/most sustainable way to maintain cross-compilation jobs.

Part of my unfamiliarity is that I don't cross compile more than one configuration at a time, so a another config file just to do what I already do always seems like work I don't need to do.

Anything else is liable to break eventually though, so I'll look into it for further updates to these instructions.