ldc
ldc copied to clipboard
Detect musl in cmake and link with libunwind
@kinke Is it worthwhile letting the CI for cross-compiling druntime/phobos (and ldc-build-runtime probably too?) know about LDC's folder with cmake modules..... Or should I just move the CHECK_MUSL macro inside the runtime CMakeLists.txt and be happy?
Sigh, if the pragma(lib, …) was supported by the GNU linkers too (not just lld), we could simply embed a reference in a central druntime object file and let the linker handle everything.
If the compiler implicitly added -lunwind as 'platform-lib' for musl targets, the druntime integration tests would require less adaptations (then only required when linking via C(++) compiler).
Wrt. detecting musl, another option might be to check the LLVM host triple (llvm-config --host-target - AFAICT, would need a new llvm_set(HOST_TARGET host-target) in FindLLVM.cmake to set LLVM_HOST_TARGET), checking for a musl environment.
Wrt. integrating that in runtime/CMakeLists.txt, a potential option might be to (ab)use our TARGET_SYSTEM variable, adding Musl to that list, similar to Android (full TARGET_SYSTEM: Android;Linux;UNIX). For autodetection as part of a full LDC build, we could use LLVM_HOST_TARGET; for cross-compiling the libs, TARGET_SYSTEM would need to be specified manually (but that's standard - just nice not having to remember to additionally set an extra MUSL_LIBC variable when cross-compiling to a musl target).
If the compiler implicitly added
-lunwindas 'platform-lib' for musl targets, the druntime integration tests would require less adaptations (then only required when linking via C(++) compiler).
LDC already does this, but indeed the problem is C/C++ linking. https://github.com/ldc-developers/ldc/blob/40ad5f7583fe90a85fd675bfc0cfc287d565c94a/driver/linker-gcc.cpp#L684-L686
Wrt. detecting musl, another option might be to check the LLVM host triple (
llvm-config --host-target- AFAICT, would need a newllvm_set(HOST_TARGET host-target)in FindLLVM.cmake to set LLVM_HOST_TARGET), checking for a musl environment.Wrt. integrating that in runtime/CMakeLists.txt, a potential option might be to (ab)use our
TARGET_SYSTEMvariable, addingMuslto that list, similar toAndroid(full TARGET_SYSTEM:Android;Linux;UNIX). For autodetection as part of a full LDC build, we could use LLVM_HOST_TARGET; for cross-compiling the libs, TARGET_SYSTEM would need to be specified manually (but that's standard - just nice not having to remember to additionally set an extra MUSL_LIBC variable when cross-compiling to a musl target).
I also want the autodetection to work for non-cross compile builds, just for building runtime with user-specified options (e.g. ASan stuff); then I cannot use llvm-config (although a good idea). So for now I'll stick with the current check but add it as macro to runtime/CMakeLists.txt. And I will add detection of "Musl" string in TARGET_SYSTEM, for user-override / cross-compiling capability.