CMake: Build both static and shared sets of stdlibs#1960
CMake: Build both static and shared sets of stdlibs#1960kinke merged 2 commits intoldc-developers:masterfrom
Conversation
|
With |
|
This needs some testing on OSX wrt. merging the 32/64-bit libs. |
|
As to the other aspect of #1282, the selection of the stdlib to be linked against, I'm still favoring #1735 - hardcoded lib suffix |
|
Pinging @JohanEngelen and @klickverbot - someone please test |
|
Will do. We should also make it the default. |
|
Setting it to default will double the tests (at least the unittests), so we'll need to slightly tweak the CI scripts. If it wasn't for |
|
With Will have a quick look. |
|
Partial patch for OS X: --- a/runtime/CMakeLists.txt
+++ b/runtime/CMakeLists.txt
@@ -405,6 +405,7 @@ macro(build_runtime d_flags c_flags ld_flags lib_suffix path_suffix is_shared ou
endif()
compile_druntime("${druntime_d_flags}" "${lib_suffix}" "${path_suffix}" druntime_o druntime_bc)
+ get_target_suffix("${lib_suffix}" "${path_suffix}" target_suffix)
add_library(druntime-ldc${target_suffix} ${library_type}
${druntime_o} ${CORE_C} ${DCRT_C} ${DCRT_ASM})
set_target_properties(
@@ -569,12 +570,8 @@ if(MULTILIB)
build_runtime_variants("-m${MULTILIB_SUFFIX}" "-m${MULTILIB_SUFFIX} ${RT_CFLAGS}" "-m${MULTILIB_SUFFIX} ${LD_FLAGS}" "${MULTILIB_SUFFIX}" multitargets)
foreach(targetname ${hosttargets})
- set(lib_path "$<TARGET_FILE:${targetname}>")
- set(lib_extension "")
- get_filename_component(lib_extension ${lib_path} EXT)
-
string(REPLACE "_${hostsuffix}" "" t ${targetname})
- set(lib_filename lib${t}${lib_extension})
+ set(lib_filename lib${t}${SHARED_LIB_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX})
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/lib${LIB_SUFFIX}/${lib_filename}
@@ -790,7 +787,13 @@ endif()
# Add the standalone druntime tests.
# TODO: Add test/excetions and test/init_fini.
if(NOT ${BUILD_SHARED_LIBS} STREQUAL "OFF")
- set(druntime_path "$<TARGET_FILE:druntime-ldc${SHARED_LIB_SUFFIX}>")
+ if(MULTILIB AND APPLE)
+ # KLUDGE: The library target is a custom command for multilib builds (lipo),
+ # so cannot use TARGET_FILE directly. Should stash away that name instead.
+ set(druntime_path "${CMAKE_BINARY_DIR}/lib${LIB_SUFFIX}/libdruntime-ldc.dylib")
+ else()
+ set(druntime_path "$<TARGET_FILE:druntime-ldc${SHARED_LIB_SUFFIX}>")
+ endif()
set(outdir ${PROJECT_BINARY_DIR}/druntime-test-shared)
add_test(NAME clean-druntime-test-sharedNow it fails because profile-rt is always built as a static library. |
|
(Just not supporting shared multilib builds on OS X at all might actually be a reasonable option.) |
|
Thanks - what's the point of these OSX 'fat' libs? Are they just a fancy way of cutting the number of lib files in half or does Apple enforce that format? Wrt. profile-rt, static libs were a deliberate choice for |
|
Still awaiting an answer wrt. any advantages of OSX fat libs... ;)
If we emit PIC by default on Linux anyway, we should exploit that and build the Phobos modules only once, greatly speeding up the build process. Making it a Linux special case will clutter the CMake m(adn)ess even more; |
It's the way to do multilib on OS X – there exists no infrastructure for handling different
Having a static libprofile-rt.a is probably a sensible choice – but it means special-casing the OS X build system.
|
628382c to
25619f0
Compare
|
Building shared druntime/Phobos libs (incl. unittest libs and running those tests) in addition to the static libs and tests now only requires a few additional minutes on Travis. |
|
From the Travis LLVM 3.8 MULTILIB=ON BUILD_SHARED_LIBS=BOTH overkill job log: So it only just just made it under 50 mins. :D More than 3,000 unittested druntime/Phobos modules (8x druntime/Phobos: release/debug, shared/static, x86/x86_64)... |
|
Travis: Seems to happen if the job previously built shared libs too (1st run works, 2nd doesn't, 3rd does...). Any idea why the LDC build directory or at least the links seem to be cached across Travis runs?! |
|
@klickverbot: Please test the merged libs on OSX again. |
This is a snag I also ran into (hence the hardcoded bit in the partial patch) – as the name suggests, CMake generator expressions ( |
|
I had another solution - all 9 potential libs (per architecture) hardcoded, until I realized this friggin The main reason for these generator expressions is that the target |
|
You are using |
|
Well now it looks like the merged shared libs don't work: I won't pursue OSX further. I don't have it, Travis takes hours to finally process the OSX jobs, so someone working on OSX please fix the last issues, I'm done with this. Edit: Actually, the reason is that the unittest libs aren't merged, unlike the regular non-unittest .dylibs. |
And never have been, so the unittests with |
| set(D_LIBRARY_TYPE SHARED) | ||
| else() | ||
| set(D_LIBRARY_TYPE STATIC) | ||
| # Only use the `-shared` lib suffix if static libs are generated too |
There was a problem hiding this comment.
Wouldn't it be better to always use -shared for uniformity? (e.g. if somebody explicitly needs to link against druntime/Phobos in their custom build system, etc.)
There was a problem hiding this comment.
adding SHARED_LIB_SUFFIX (-shared) to all shared-lib targets and files for BUILD_SHARED_LIBS == ON too would complicate generating the default config file and misc. command lines in our CI scripts.
It'd also be a breaking change.
There was a problem hiding this comment.
I'd suggest always adding -shared as soon as we have -link-sharedlib or something similar.
It's -link-sharedlib vs. -defaultlib=druntime-ldc-shared,phobos2-ldc-shared -debuglib=druntime-ldc-debug-shared,phobos2-ldc-debug-shared.
Via `-DBUILD_SHARED_LIBS=BOTH`. Compile the Phobos modules only once for static+shared libs. Build a single ldc-profile-rt.a (per architecture); `-d-version=Shared` was just copy-pasted and not needed, so no need for an extra ldc-profile-rt-shared.a.
|
Any concerns? Otherwise I'll merge it in a couple of days. This should have been tested quite extensively by intermediate commits (with |
Via
-DBUILD_SHARED_LIBS=BOTH, addressing the build part of #1282.