-
-
Notifications
You must be signed in to change notification settings - Fork 267
Support building phobos against a system copy of zlib #4742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c2b3503
Support building phobos against a system copy of zlib
the-horo 0db1ea3
CHANGELOG.md: Add PHOBOS_SYSTEM_ZLIB entry
the-horo aa87ad3
.github/workflows/supported_llvm_versions: test PHOBOS_SYSTEM_ZLIB=ON
the-horo 4859d83
runtime/ldc-build-runtime: Support PHOBOS_SYSTEM_ZLIB
the-horo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -61,6 +61,10 @@ if (RT_SUPPORT_SANITIZERS) | |||||||||||||
list(APPEND D_FLAGS -d-version=SupportSanitizers) | ||||||||||||||
endif() | ||||||||||||||
|
||||||||||||||
if(PHOBOS_SYSTEM_ZLIB) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, we'd bake this into the ldc/runtime/ldc-build-runtime.d.in Lines 152 to 157 in 0cc531e
|
||||||||||||||
message(STATUS "-- Building PHOBOS against system zlib") | ||||||||||||||
endif() | ||||||||||||||
|
||||||||||||||
# Auto-detect TARGET_SYSTEM from host | ||||||||||||||
if("${TARGET_SYSTEM}" STREQUAL "AUTO") | ||||||||||||||
set(TARGET_SYSTEM ${CMAKE_SYSTEM_NAME}) | ||||||||||||||
|
@@ -243,14 +247,22 @@ if(PHOBOS2_DIR) | |||||||||||||
list(REMOVE_ITEM PHOBOS2_D ${PHOBOS2_D_WINDOWS}) | ||||||||||||||
endif() | ||||||||||||||
|
||||||||||||||
# Phobos C parts | ||||||||||||||
file(GLOB_RECURSE PHOBOS2_C ${PHOBOS2_DIR}/etc/*.c) | ||||||||||||||
# remove zlib test modules | ||||||||||||||
list(REMOVE_ITEM PHOBOS2_C | ||||||||||||||
${PHOBOS2_DIR}/etc/c/zlib/test/example.c | ||||||||||||||
${PHOBOS2_DIR}/etc/c/zlib/test/infcover.c | ||||||||||||||
${PHOBOS2_DIR}/etc/c/zlib/test/minigzip.c | ||||||||||||||
) | ||||||||||||||
if(PHOBOS_SYSTEM_ZLIB) | ||||||||||||||
find_package(ZLIB REQUIRED) | ||||||||||||||
else() | ||||||||||||||
# Phobos C parts | ||||||||||||||
file(GLOB_RECURSE PHOBOS2_C ${PHOBOS2_DIR}/etc/*.c) | ||||||||||||||
# remove zlib test modules | ||||||||||||||
list(REMOVE_ITEM PHOBOS2_C | ||||||||||||||
${PHOBOS2_DIR}/etc/c/zlib/test/example.c | ||||||||||||||
${PHOBOS2_DIR}/etc/c/zlib/test/infcover.c | ||||||||||||||
${PHOBOS2_DIR}/etc/c/zlib/test/minigzip.c | ||||||||||||||
) | ||||||||||||||
CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H) | ||||||||||||||
if (HAVE_UNISTD_H) | ||||||||||||||
append("-DHAVE_UNISTD_H" CMAKE_C_FLAGS) | ||||||||||||||
endif() | ||||||||||||||
endif() | ||||||||||||||
endif() | ||||||||||||||
|
||||||||||||||
# | ||||||||||||||
|
@@ -397,11 +409,6 @@ if("${TARGET_SYSTEM}" MATCHES "MSVC") | |||||||||||||
# warning C4996: zlib uses 'deprecated' POSIX names | ||||||||||||||
append("/wd4100 /wd4127 /wd4131 /wd4206 /wd4244 /wd4245 /wd4267 /wd4996" CMAKE_C_FLAGS_RELEASE) | ||||||||||||||
endif() | ||||||||||||||
CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H) | ||||||||||||||
if (HAVE_UNISTD_H) | ||||||||||||||
# Needed for zlib | ||||||||||||||
append("-DHAVE_UNISTD_H" CMAKE_C_FLAGS) | ||||||||||||||
endif() | ||||||||||||||
# 2) Set all other CMAKE_C_FLAGS variants to CMAKE_C_FLAGS_RELEASE | ||||||||||||||
set(variables | ||||||||||||||
CMAKE_C_FLAGS_DEBUG | ||||||||||||||
|
@@ -412,6 +419,16 @@ foreach(variable ${variables}) | |||||||||||||
set(${variable} "${CMAKE_C_FLAGS_RELEASE}") | ||||||||||||||
endforeach() | ||||||||||||||
|
||||||||||||||
function(link_zlib phobos_target library_type) | ||||||||||||||
if(PHOBOS_SYSTEM_ZLIB) | ||||||||||||||
if(${library_type} STREQUAL "SHARED") | ||||||||||||||
target_link_libraries(${phobos_target} ZLIB::ZLIB) | ||||||||||||||
endif() | ||||||||||||||
else() | ||||||||||||||
target_sources(${phobos_target} PRIVATE ${PHOBOS2_C}) | ||||||||||||||
endif() | ||||||||||||||
endfunction() | ||||||||||||||
|
||||||||||||||
# Compiles the given D modules to object files, and if enabled, bitcode files. | ||||||||||||||
# The paths of the output files are appended to outlist_o and outlist_bc, respectively. | ||||||||||||||
macro(dc src_files src_basedir d_flags output_basedir emit_bc all_at_once single_obj_name outlist_o outlist_bc) | ||||||||||||||
|
@@ -638,8 +655,8 @@ macro(build_runtime_libs druntime_o druntime_bc phobos2_o phobos2_bc c_flags ld_ | |||||||||||||
list(APPEND ${outlist_targets} druntime-ldc${target_suffix}) | ||||||||||||||
|
||||||||||||||
if(PHOBOS2_DIR) | ||||||||||||||
add_library(phobos2-ldc${target_suffix} ${library_type} | ||||||||||||||
${phobos2_o} ${PHOBOS2_C}) | ||||||||||||||
add_library(phobos2-ldc${target_suffix} ${library_type} ${phobos2_o}) | ||||||||||||||
link_zlib(phobos2-ldc${target_suffix} ${library_type}) | ||||||||||||||
set_common_library_properties(phobos2-ldc${target_suffix} | ||||||||||||||
phobos2-ldc${lib_suffix} ${output_path} | ||||||||||||||
"${c_flags}" "${ld_flags}" ${is_shared} | ||||||||||||||
|
@@ -669,8 +686,8 @@ macro(build_runtime_libs druntime_o druntime_bc phobos2_o phobos2_bc c_flags ld_ | |||||||||||||
"${c_flags}" "${ld_flags}" OFF | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
add_library(phobos2-ldc-lto${target_suffix} STATIC | ||||||||||||||
${phobos2_bc} ${PHOBOS2_C}) | ||||||||||||||
add_library(phobos2-ldc-lto${target_suffix} STATIC ${phobos2_bc}) | ||||||||||||||
link_zlib(phobos2-ldc-lto${target_suffix} STATIC) | ||||||||||||||
set_common_library_properties(phobos2-ldc-lto${target_suffix} | ||||||||||||||
phobos2-ldc-lto${lib_suffix} ${output_path} | ||||||||||||||
"${c_flags}" "${ld_flags}" OFF | ||||||||||||||
|
@@ -1004,6 +1021,9 @@ function(build_test_runners name_suffix path_suffix d_flags linkflags is_shared) | |||||||||||||
LINK_FLAGS ${linkflags} | ||||||||||||||
LINK_DEPENDS ${tested_lib_path} | ||||||||||||||
) | ||||||||||||||
if(PHOBOS_SYSTEM_ZLIB AND "${is_shared}" STREQUAL "OFF") | ||||||||||||||
target_link_libraries(${phobos_name} ZLIB::ZLIB) | ||||||||||||||
endif() | ||||||||||||||
add_test(build-${phobos_name} "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${phobos_name}) | ||||||||||||||
set(_GLOBAL_TESTRUNNERS "${_GLOBAL_TESTRUNNERS};${phobos_name}" CACHE INTERNAL "") | ||||||||||||||
endif() | ||||||||||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, to enable what Steven wants, we'd just remove the
!linkAgainstSharedDefaultLibs()
condition here. Meaning that if the compiler was configured with PHOBOS_SYSTEM_ZLIB, and the user hasn't cleared the-defaultlib
list, it implicitly adds-lz
for linking on Posix.On Windows, we'd actually have to export all zlib symbols from the Phobos DLL in order to enable user code to use the
etc.c.zlib
bindings directly when using-link-defaultlib-shared
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#4963