Open nickdesaulniers opened 3 years ago
This is difficult to be done purely in llvm-project's CMake build system. Some musl linked external libraries are needed: libtinfo, libz, libstdc++/libc++. One will need a musl targeting toolchain to build these external libraries, then build a clang+libc++ (the built clang produces object files linking against the build musl libc++), finally re-build clang with the libc++ using clang.
musl-cross-make can build a GCC toolchain, but the author does not have extra bandwidth to support Clang. @pattop's https://www.openwall.com/lists/musl/2021/01/11/1 may be helpful.
we do cross build clang in Yocto/OE world to run on musl targets, I wonder if same clang can be targeted at x86_64 and used
The current state of my musl-cross-make clang support is here https://github.com/apexrtos/musl-cross-make/tree/clang. It includes some patches for my embedded work, but the native x86_64 toolchain should be fully functional.
make COMPILER=clang
make COMPILER=clang OUTPUT=/tmp/musl-clang install
should be all you need to do to get a working musl-clang toolchain with some arm targets and x86_64. I've never tried to build clang with this though.
@MaskRay if you have time it would be great if you could review my build process & patches. Ideally it would be merged into musl-cross-make upstream but that doesn't look to be possible at the moment. There's enough complexity here that I think it's worth having one recipe for people to use.
@compnerd has something hacked up that seems to be working: https://gist.github.com/compnerd/ebbc625a359d1d3e292e1fd2007ecb52
I'm working through trying to get this working in https://github.com/ClangBuiltLinux/llvm-musl-bootstrap/pull/1/files.
What @sternenseemann did in https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-1005053204 using Musl, so we have static linking and musl link both working.
@nickdesaulniers you might be interested in https://github.com/dzbarsky/static-clang/ (Also, hi, long time no see!)
yo @dzbarsky I bookmarked that shit yesterday
Nice, I fixed/cleaned up a few things and tagged a 17.0.1 release. It works for my purposes but if you see something off, let me know
follow on to #150 , though perhaps less important. For kernel.org builds of LLVM, we should see if we can link clang itself against musl (dynamically; static linking I assume is orthogonal). @arndb had done some experiments with this (it would be good to share notes here). I've been fooling around with static linking against musl and LTO'ing in musl in here (though that's irrelevant to dynamically linking against musl; thought I'd post it somewhere so that I don't forget).