This is question I believe is mostly a CLang issue, though there are some interactions with LLVM, LibC++, Compiler-RT, LibCLC, and so on.
For the most part the compilers I work on are cross-compilers for embedded systems with varying degrees of OS support (from none at all, to pretty much everything), and things like the local host’s suite of header files are entirely inappropriate.
If I configure and build GCC for a particular target triple with a specific C library (e.g.: ‘glibc’, ‘newlib’, ‘uclibc’, ‘musl’), then the corresponding suites of headers and libraries are particular to that configuration.
The built cross-compiler has a sub-directory named after the triple (e.g.: ‘foo-unknown-elf’) which contains the ‘include’, ‘bin’ and ‘lib’ directories specific to this particular configuration, and this allows me to also configure and build GCC for multiple targets with different choices of supporting C libraries, and they can co-exist in the same base directory without cross contaminating each other.
I would like to do something similar with CLang/LLVM but there does not appear to be a convention for doing this, even though CLang (unlike GCC) can have a single compiler instance that can handle multiple targets.
A related aspect is that if I want to also build the supporting libraries for the selected target (e.g.: ‘libc++’, ‘compiler-rt’), then I really need the CMake configuration tools for the LLVM projects to be able to incorporate building the selected C library in advance of cross-compiling these other libraries; that is, the ‘include’ files from the selected C library would need to be staged as part of the build process, and the libraries (e.g.: ‘libc’, ‘libm’) would also need to be built for this cross-compiled target, before ‘libc++’ or the ‘compiler-rt’ libraries are built.
Typically I would like to build CLang and libraries to support one or more cross-targets plus the local host target, and then choose which target I want at runtime using the triple. For example, let’s say I want to support two targets ‘foo’ and ‘bar’, plus the local target; then I would like configure my build (one possible configuration choice) so that:
· target ‘foo’ prepares and builds the C library based on Newlib
· target ‘bar’ prepares and builds the C library based on uClibc
· local target uses the existing installed C library support on the host
Are there any plans within the LLVM community to standardise how to do this kind of build? The CLang Driver would need to adopt conventions that would allow this, and I think that perhaps a new CMake module could be added that would optionally prep & stage a selected and supported C library for a cross-compiler configuration, and that this could be made an optional dependency of the libraries which are to be cross-compiled (‘libc++’ and ‘compiler-rt’).
Related to this is how to build and manage the equivalent of GCC’s MULTILIBs for cross-compiler targets in a regularised way.
Does anybody have any experience of doing this kind of thing with CLang, and advice on how I should approach this? So far I have done this in an ad-hoc way for each of my intended targets, and use intermediate non-integrated build processes to ensure that the right headers and C libraries are prepared in advance of being used by the subsequent dependent libraries from the LLVM project.
Thanks,
MartinO