Page MenuHomePhabricator

[CMake] Support cross-compiling with multi-stage builds

Authored by phosek on Nov 12 2018, 7:18 PM.



When using multi-stage builds, we would like support cross-compilation.
Example is 2-stage build when the first stage is compiled for host while
the second stage is compiled for the target.

Normally, the second stage would be also used for compiling runtimes,
but that's not possible when cross-compiling, so we use the first stage
compiler instead. However, we still want to use the second stage paths.
To do so, we set the -resource-dir of the first stage compiler to point
to the resource directory of the second stage.

We also need compiler tools that support the target architecture. These
tools are not guaranteed to be present on the host, but in case of
multi-stage build, we can build these tools in the first stage.

Diff Detail

rC Clang

Event Timeline

phosek created this revision.Nov 12 2018, 7:18 PM
beanz added a comment.Nov 13 2018, 2:16 PM

One slightly nitpicky comment.

169 ↗(On Diff #173805)

This could be problematic if the cross-compilation flow was ever hit using a non-clang compiler. I can't, off the top of my head, think of a use case where it would, but it might be worth checking CMAKE_<LANG>_COMPILER_ID to verify that it is *Clang.

phosek updated this revision to Diff 173956.Nov 13 2018, 4:18 PM
phosek marked an inline comment as done.

Any other comments?

beanz accepted this revision.Nov 14 2018, 12:18 PM


This revision is now accepted and ready to land.Nov 14 2018, 12:18 PM
This revision was automatically updated to reflect the committed changes.