From fb1d1b21f9b7239cdb5fceffe4c63a0b488e402b Mon Sep 17 00:00:00 2001 From: carlossanlop <1175054+carlossanlop@users.noreply.github.com> Date: Tue, 21 May 2024 16:09:42 -0700 Subject: [PATCH 01/39] Comment zlib.cmake and zlib-intel.cmake to confirm they're not being used --- src/native/external/zlib-intel.cmake | 50 +++++++++---------- src/native/external/zlib.cmake | 72 ++++++++++++++-------------- 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/native/external/zlib-intel.cmake b/src/native/external/zlib-intel.cmake index a664f154dbef09..2f5b68c69597d9 100644 --- a/src/native/external/zlib-intel.cmake +++ b/src/native/external/zlib-intel.cmake @@ -1,29 +1,29 @@ -# IMPORTANT: do not use add_compile_options(), add_definitions() or similar functions here since it will leak to the including projects +# # IMPORTANT: do not use add_compile_options(), add_definitions() or similar functions here since it will leak to the including projects -set(ZLIB_SOURCES_BASE - adler32.c - compress.c - crc_folding.c - crc32.c - deflate_medium.c - deflate_quick.c - deflate.c - inffast.c - inflate.c - inftrees.c - match.c - slide_sse.c - trees.c - x86.c - zutil.c - ../../libs/System.IO.Compression.Native/zlib_allocator_win.c -) +# set(ZLIB_SOURCES_BASE +# adler32.c +# compress.c +# crc_folding.c +# crc32.c +# deflate_medium.c +# deflate_quick.c +# deflate.c +# inffast.c +# inflate.c +# inftrees.c +# match.c +# slide_sse.c +# trees.c +# x86.c +# zutil.c +# ../../libs/System.IO.Compression.Native/zlib_allocator_win.c +# ) -addprefix(ZLIB_SOURCES "${CMAKE_CURRENT_LIST_DIR}/zlib-intel" "${ZLIB_SOURCES_BASE}") +# addprefix(ZLIB_SOURCES "${CMAKE_CURRENT_LIST_DIR}/zlib-intel" "${ZLIB_SOURCES_BASE}") -# enable custom zlib allocator -set(ZLIB_COMPILE_DEFINITIONS "MY_ZCALLOC") +# # enable custom zlib allocator +# set(ZLIB_COMPILE_DEFINITIONS "MY_ZCALLOC") -if(HOST_WIN32 OR CLR_CMAKE_TARGET_WIN32) - set(ZLIB_COMPILE_OPTIONS "/wd4127;/wd4131") -endif() +# if(HOST_WIN32 OR CLR_CMAKE_TARGET_WIN32) +# set(ZLIB_COMPILE_OPTIONS "/wd4127;/wd4131") +# endif() diff --git a/src/native/external/zlib.cmake b/src/native/external/zlib.cmake index 498ec977960e01..fc3f7873a70e51 100644 --- a/src/native/external/zlib.cmake +++ b/src/native/external/zlib.cmake @@ -1,41 +1,41 @@ -# IMPORTANT: do not use add_compile_options(), add_definitions() or similar functions here since it will leak to the including projects +# # IMPORTANT: do not use add_compile_options(), add_definitions() or similar functions here since it will leak to the including projects -set(ZLIB_SOURCES_BASE - adler32.c - compress.c - crc32.c - uncompr.c - deflate.c - gzguts.h - trees.c - zutil.c - inflate.c - infback.c - inftrees.c - inffast.c - crc32.h - deflate.h - inffast.h - inffixed.h - inflate.h - inftrees.h - trees.h - zconf.h - zlib.h - zutil.h -) +# set(ZLIB_SOURCES_BASE +# adler32.c +# compress.c +# crc32.c +# uncompr.c +# deflate.c +# gzguts.h +# trees.c +# zutil.c +# inflate.c +# infback.c +# inftrees.c +# inffast.c +# crc32.h +# deflate.h +# inffast.h +# inffixed.h +# inflate.h +# inftrees.h +# trees.h +# zconf.h +# zlib.h +# zutil.h +# ) -if(HOST_WIN32 OR CLR_CMAKE_TARGET_WIN32) - set(ZLIB_SOURCES_BASE ${ZLIB_SOURCES_BASE} ../../libs/System.IO.Compression.Native/zlib_allocator_win.c) -else() - set(ZLIB_SOURCES_BASE ${ZLIB_SOURCES_BASE} ../../libs/System.IO.Compression.Native/zlib_allocator_unix.c) -endif() +# if(HOST_WIN32 OR CLR_CMAKE_TARGET_WIN32) +# set(ZLIB_SOURCES_BASE ${ZLIB_SOURCES_BASE} ../../libs/System.IO.Compression.Native/zlib_allocator_win.c) +# else() +# set(ZLIB_SOURCES_BASE ${ZLIB_SOURCES_BASE} ../../libs/System.IO.Compression.Native/zlib_allocator_unix.c) +# endif() -addprefix(ZLIB_SOURCES "${CMAKE_CURRENT_LIST_DIR}/zlib" "${ZLIB_SOURCES_BASE}") +# addprefix(ZLIB_SOURCES "${CMAKE_CURRENT_LIST_DIR}/zlib" "${ZLIB_SOURCES_BASE}") -# enable custom zlib allocator -set(ZLIB_COMPILE_DEFINITIONS "MY_ZCALLOC") +# # enable custom zlib allocator +# set(ZLIB_COMPILE_DEFINITIONS "MY_ZCALLOC") -if(HOST_WIN32 OR CLR_CMAKE_TARGET_WIN32) - set(ZLIB_COMPILE_OPTIONS "/wd4127;/wd4131") -endif() +# if(HOST_WIN32 OR CLR_CMAKE_TARGET_WIN32) +# set(ZLIB_COMPILE_OPTIONS "/wd4127;/wd4131") +# endif() From e19dc0f442331c65e4170111ed9569aac619e6a1 Mon Sep 17 00:00:00 2001 From: carlossanlop <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 22 May 2024 13:18:48 -0700 Subject: [PATCH 02/39] Windows, Unix, MacOS and NativeAOT adjustments and workarounds for successful local build. --- eng/native/configurecompiler.cmake | 1 + eng/native/functions.cmake | 4 +- .../Microsoft.NETCore.Native.Windows.targets | 1 + src/mono/CMakeLists.txt | 15 +---- src/mono/cmake/config.h.in | 3 - src/mono/mono/metadata/CMakeLists.txt | 10 ++-- src/mono/mono/metadata/debug-mono-ppdb.c | 4 -- src/mono/mono/mini/CMakeLists.txt | 27 ++++----- src/mono/mono/profiler/CMakeLists.txt | 6 +- src/mono/mono/profiler/log.c | 4 -- src/mono/mono/profiler/mprof-report.c | 4 -- src/native/external/zlib-ng.cmake | 22 ++++++++ src/native/libs/Common/pal_utilities.h | 6 +- .../CMakeLists.txt | 56 +++++++++++++------ .../extra_libs.cmake | 15 ----- .../System.IO.Compression.Native/pal_zlib.c | 19 +++---- .../System.IO.Compression.Native/pal_zlib.h | 18 +++--- .../zlib_allocator.h | 19 +++++++ .../zlib_allocator_unix.c | 11 ++-- .../zlib_allocator_win.c | 13 ++--- 20 files changed, 140 insertions(+), 118 deletions(-) create mode 100644 src/native/external/zlib-ng.cmake create mode 100644 src/native/libs/System.IO.Compression.Native/zlib_allocator.h diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index 76c441de6f2f56..8d48160f6ba325 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -85,6 +85,7 @@ if (MSVC) #shrink pdb size set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /PDBCOMPRESS") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /INCREMENTAL:NO") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUG") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUGTYPE:CV,FIXUP") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /IGNORE:4197,4013,4254,4070,4221") diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 6629e926afacf6..b1cb09d6620436 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -221,7 +221,7 @@ function(preprocess_file inputFilename outputFilename) get_compile_definitions(PREPROCESS_DEFINITIONS) get_include_directories(PREPROCESS_INCLUDE_DIRECTORIES) get_source_file_property(SOURCE_FILE_DEFINITIONS ${inputFilename} COMPILE_DEFINITIONS) - + foreach(DEFINITION IN LISTS SOURCE_FILE_DEFINITIONS) list(APPEND PREPROCESS_DEFINITIONS -D${DEFINITION}) endforeach() @@ -508,7 +508,7 @@ function(install_static_library targetName destination component) if (WIN32) set_target_properties(${targetName} PROPERTIES COMPILE_PDB_NAME "${targetName}" - COMPILE_PDB_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}" + COMPILE_PDB_OUTPUT_DIRECTORY "$" ) install (FILES "$/${targetName}.pdb" DESTINATION ${destination} COMPONENT ${component}) endif() diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets index 18c3c1f017a9ff..603a255fc0ca07 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets @@ -46,6 +46,7 @@ The .NET Foundation licenses this file to you under the MIT license. + diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index ba41fa4d9a489f..59d506591a3167 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -249,7 +249,6 @@ elseif(CLR_CMAKE_HOST_OS STREQUAL "emscripten") set(DISABLE_SHARED_LIBS 1) # sys/random.h exists, but its not found set(HAVE_SYS_RANDOM_H 1) - set(INTERNAL_ZLIB 1) elseif(CLR_CMAKE_HOST_OS STREQUAL "wasi") set(HOST_WASI 1) add_definitions(-D_WASI_EMULATED_PROCESS_CLOCKS -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_MMAN -DHOST_WASI) @@ -261,7 +260,6 @@ elseif(CLR_CMAKE_HOST_OS STREQUAL "wasi") add_compile_options(-Wno-unused-but-set-variable) set(ENABLE_PERFTRACING 0) set(DISABLE_SHARED_LIBS 1) - set(INTERNAL_ZLIB 1) set(DISABLE_EXECUTABLES 1) set(STATIC_COMPONENTS 1) elseif(CLR_CMAKE_HOST_OS STREQUAL "windows") @@ -270,7 +268,6 @@ elseif(CLR_CMAKE_HOST_OS STREQUAL "windows") set(HOST_NO_SYMLINKS 1) set(MONO_KEYWORD_THREAD "__declspec (thread)") set(MONO_ZERO_LEN_ARRAY 1) - set(INTERNAL_ZLIB 1) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") # statically link VC runtime library add_compile_options($<$:/W4>) # set warning level 4 add_compile_options($<$:/WX>) # treat warnings as errors @@ -511,17 +508,9 @@ if ((HOST_MACCAT AND HOST_ARM64) OR (TARGET_MACCAT AND TARGET_ARM64)) set(TARGET_APPLE_MOBILE 1) endif() -# Decide if we need zlib, and if so whether we want the system zlib or the in-tree copy. +# Decide if we need zlib-ng. if(NOT DISABLE_EMBEDDED_PDB OR NOT DISABLE_LOG_PROFILER_GZ) - if(INTERNAL_ZLIB) - # defines ZLIB_SOURCES - include(${CLR_SRC_NATIVE_DIR}/external/zlib.cmake) - else() - # if we're not on a platform where we use the in-tree zlib, require system zlib - include(${CLR_SRC_NATIVE_DIR}/libs/System.IO.Compression.Native/extra_libs.cmake) - set(Z_LIBS) - append_extra_compression_libs(Z_LIBS) - endif() + include(${CLR_SRC_NATIVE_DIR}/external/zlib-ng.cmake) endif() ###################################### diff --git a/src/mono/cmake/config.h.in b/src/mono/cmake/config.h.in index e972500d1cd81d..8ac0c0f7c3c290 100644 --- a/src/mono/cmake/config.h.in +++ b/src/mono/cmake/config.h.in @@ -168,9 +168,6 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_UNWIND_H 1 -/* Use in-tree zlib */ -#cmakedefine INTERNAL_ZLIB 1 - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_POLL_H 1 diff --git a/src/mono/mono/metadata/CMakeLists.txt b/src/mono/mono/metadata/CMakeLists.txt index 773381d6c1c9ad..2926655fdc1aaf 100644 --- a/src/mono/mono/metadata/CMakeLists.txt +++ b/src/mono/mono/metadata/CMakeLists.txt @@ -5,7 +5,7 @@ project(metadata C) # if(DISABLE_ICALL_TABLES) add_library(mono-icall-table STATIC "icall-table.c") -target_link_libraries(mono-icall-table PRIVATE monoapi eglib_api) +target_link_libraries(mono-icall-table PRIVATE monoapi eglib_api zlibstatic) target_include_directories(mono-icall-table PRIVATE ${PROJECT_BINARY_DIR}/../.. ${PROJECT_SOURCE_DIR}/../.. ${PROJECT_SOURCE_DIR}/..) @@ -200,10 +200,10 @@ set(metadata_sources "${metadata_platform_sources};${metadata_common_sources};${ if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS) add_library(metadata_objects_shared OBJECT ${metadata_sources}) target_compile_definitions(metadata_objects_shared PRIVATE ${metadata_compile_definitions}) - target_link_libraries(metadata_objects_shared PRIVATE monoapi eglib_api utils_objects_shared) + target_link_libraries(metadata_objects_shared PRIVATE monoapi eglib_api utils_objects_shared zlibstatic) # note: metadata_objects is an object library, so this doesn't force linking with sgen, # it just adds the relevant include directories - which we need even with Boehm - target_link_libraries(metadata_objects_shared PRIVATE sgen_objects_shared) + target_link_libraries(metadata_objects_shared PRIVATE sgen_objects_shared zlibstatic) target_compile_definitions(metadata_objects_shared PRIVATE -DMONO_DLL_EXPORT) target_include_directories(metadata_objects_shared PRIVATE ${PROJECT_BINARY_DIR}/../.. ${PROJECT_SOURCE_DIR}/../.. @@ -212,10 +212,10 @@ endif() add_library(metadata_objects OBJECT ${metadata_sources}) target_compile_definitions(metadata_objects PRIVATE ${metadata_compile_definitions}) -target_link_libraries(metadata_objects PRIVATE monoapi eglib_api utils_objects) +target_link_libraries(metadata_objects PRIVATE monoapi eglib_api utils_objects zlibstatic) # note: metadata_objects is an object library, so this doesn't force linking with sgen, # it just adds the relevant include directories - which we need even with Boehm -target_link_libraries(metadata_objects PRIVATE sgen_objects) +target_link_libraries(metadata_objects PRIVATE sgen_objects zlibstatic) if(NOT HOST_WIN32) target_compile_definitions(metadata_objects PRIVATE -DMONO_DLL_EXPORT) endif() diff --git a/src/mono/mono/metadata/debug-mono-ppdb.c b/src/mono/mono/metadata/debug-mono-ppdb.c index bcbbb4c7f2be03..be4cb122e78389 100644 --- a/src/mono/mono/metadata/debug-mono-ppdb.c +++ b/src/mono/mono/metadata/debug-mono-ppdb.c @@ -30,12 +30,8 @@ #include #ifndef DISABLE_EMBEDDED_PDB -#ifdef INTERNAL_ZLIB -#include -#else #include #endif -#endif #include "debug-mono-ppdb.h" diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 93ff6c431ef03b..d3af774a12154f 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -264,7 +264,7 @@ endif() if(ENABLE_INTERP_LIB) add_library(mono-ee-interp STATIC "${interp_sources}") -target_link_libraries(mono-ee-interp PRIVATE monoapi eglib_api) +target_link_libraries(mono-ee-interp PRIVATE monoapi eglib_api zlibstatic) target_include_directories(mono-ee-interp PRIVATE ${PROJECT_BINARY_DIR}/../.. ${PROJECT_SOURCE_DIR}/../.. ${PROJECT_SOURCE_DIR}/..) @@ -314,19 +314,16 @@ elseif(NOT HOST_BROWSER AND NOT HOST_WASI) set(mini_sources "${mini_sources};${VERSION_FILE_PATH}") # this is generated by GenerateNativeVersionFile in Arcade endif() -set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_DEFINITIONS "${ZLIB_COMPILE_DEFINITIONS}") -set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_OPTIONS "${ZLIB_COMPILE_OPTIONS}") - -set(monosgen-sources "${mini_sources};${ZLIB_SOURCES}") +set(monosgen-sources "${mini_sources}") if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS) add_library(monosgen-objects_shared OBJECT "${monosgen-sources}") target_compile_definitions(monosgen-objects_shared PRIVATE -DMONO_DLL_EXPORT) - target_link_libraries (monosgen-objects_shared PRIVATE monoapi eglib_api utils_objects_shared sgen_objects_shared metadata_objects_shared) + target_link_libraries (monosgen-objects_shared PRIVATE monoapi eglib_api utils_objects_shared sgen_objects_shared metadata_objects_shared zlibstatic) endif() add_library(monosgen-objects OBJECT "${monosgen-sources}") -target_link_libraries (monosgen-objects PRIVATE monoapi eglib_api utils_objects sgen_objects metadata_objects) +target_link_libraries (monosgen-objects PRIVATE monoapi eglib_api utils_objects sgen_objects metadata_objects zlibstatic) if(NOT HOST_WIN32) target_compile_definitions(monosgen-objects PRIVATE -DMONO_DLL_EXPORT) endif() @@ -352,16 +349,16 @@ if(NOT DISABLE_SHARED_LIBS) target_compile_definitions(monosgen-shared PRIVATE -DMONO_DLL_EXPORT) # musl-libc implements ucontext in a different library on s390x if(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) - target_link_libraries(monosgen-shared PRIVATE ucontext) + target_link_libraries(monosgen-shared PRIVATE ucontext zlibstatic) endif(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) set_target_properties(monosgen-shared PROPERTIES OUTPUT_NAME ${MONO_SHARED_LIB_NAME}) if(MONO_SET_RPATH_ORIGIN) set_target_properties(monosgen-shared PROPERTIES INSTALL_RPATH "$ORIGIN") endif() if(HOST_WIN32) - target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects_shared sgen_objects_shared metadata_objects_shared dn-containers) + target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects_shared sgen_objects_shared metadata_objects_shared dn-containers zlibstatic) else() - target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers) + target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers zlibstatic) endif() target_include_directories (monosgen-shared PRIVATE monoapi) if(TARGET_WIN32) @@ -395,7 +392,7 @@ if(NOT DISABLE_SHARED_LIBS) install_with_stripped_symbols(monosgen-shared TARGETS lib) if(HOST_WIN32 AND TARGET_AMD64) add_library(monosgen-shared-dac SHARED "mini-windows-dlldac.c") - target_link_libraries(monosgen-shared-dac PRIVATE monoapi eglib_api) + target_link_libraries(monosgen-shared-dac PRIVATE monoapi eglib_api zlibstatic) set_target_properties(monosgen-shared-dac PROPERTIES OUTPUT_NAME ${MONO_SHARED_LIB_NAME}-dac) endif() @@ -417,7 +414,7 @@ if(NOT DISABLE_SHARED_LIBS) endif() add_library(${frameworkconfig} SHARED $) target_compile_definitions(${frameworkconfig} PRIVATE -DMONO_DLL_EXPORT) - target_link_libraries(${frameworkconfig} PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers) + target_link_libraries(${frameworkconfig} PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers zlibstatic) target_link_libraries(${frameworkconfig} PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS}) set_property(TARGET ${frameworkconfig} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-compatibility_version -Wl,2.0 -Wl,-current_version -Wl,2.0") @@ -534,14 +531,14 @@ if(NOT DISABLE_EXECUTABLES) set_target_properties(mono-sgen PROPERTIES INSTALL_RPATH "$ORIGIN") endif() endif() - target_link_libraries(mono-sgen PRIVATE monoapi eglib_api monosgen-static dn-containers) + target_link_libraries(mono-sgen PRIVATE monoapi eglib_api monosgen-static dn-containers zlibstatic) if (HOST_WASM) - target_link_libraries(mono-sgen PRIVATE mono-wasm-nosimd) + target_link_libraries(mono-sgen PRIVATE mono-wasm-nosimd zlibstatic) endif() target_link_libraries(mono-sgen PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS}) # musl-libc implements ucontext in a different library on s390x if(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) - target_link_libraries(mono-sgen PRIVATE ucontext) + target_link_libraries(mono-sgen PRIVATE ucontex zlibstatic) endif(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) if(NOT DISABLE_COMPONENTS AND STATIC_COMPONENTS AND NOT DISABLE_LINK_STATIC_COMPONENTS) # if components are built statically, link them into runtime. diff --git a/src/mono/mono/profiler/CMakeLists.txt b/src/mono/mono/profiler/CMakeLists.txt index 511c19dbe5a322..35a377c2f3056e 100644 --- a/src/mono/mono/profiler/CMakeLists.txt +++ b/src/mono/mono/profiler/CMakeLists.txt @@ -12,11 +12,9 @@ include_directories( if(NOT DISABLE_LIBS) if(HOST_ANDROID OR HOST_IOS OR HOST_TVOS OR HOST_S390X) # Build the logging profiler only for certain platforms - set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_DEFINITIONS "${ZLIB_COMPILE_DEFINITIONS}") - set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_OPTIONS "${ZLIB_COMPILE_OPTIONS}") - add_library(mono-profiler-log SHARED helper.c log.c log-args.c ${ZLIB_SOURCES}) + add_library(mono-profiler-log SHARED helper.c log.c log-args.c) target_compile_definitions(mono-profiler-log PRIVATE -DMONO_DLL_EXPORT) - target_link_libraries(mono-profiler-log PRIVATE monosgen-shared monoapi eglib_objects) + target_link_libraries(mono-profiler-log PRIVATE monosgen-shared monoapi eglib_objects zlibstatic) if(HOST_ANDROID) target_link_libraries(mono-profiler-log PRIVATE log) endif() diff --git a/src/mono/mono/profiler/log.c b/src/mono/mono/profiler/log.c index 9d4304faae3ecb..c02058402aeafc 100644 --- a/src/mono/mono/profiler/log.c +++ b/src/mono/mono/profiler/log.c @@ -72,12 +72,8 @@ #include #endif #ifndef DISABLE_LOG_PROFILER_GZ -#ifdef INTERNAL_ZLIB -#include -#else #include #endif -#endif #ifdef HOST_WIN32 #include diff --git a/src/mono/mono/profiler/mprof-report.c b/src/mono/mono/profiler/mprof-report.c index 35c88fe0a2fd9d..c0db93ea0ca7cd 100644 --- a/src/mono/mono/profiler/mprof-report.c +++ b/src/mono/mono/profiler/mprof-report.c @@ -23,12 +23,8 @@ #endif #include #ifndef DISABLE_LOG_PROFILER_GZ -#ifdef INTERNAL_ZLIB -#include -#else #include #endif -#endif #include #include #include diff --git a/src/native/external/zlib-ng.cmake b/src/native/external/zlib-ng.cmake new file mode 100644 index 00000000000000..9c13d1203c500f --- /dev/null +++ b/src/native/external/zlib-ng.cmake @@ -0,0 +1,22 @@ +include(FetchContent) + +FetchContent_Declare( + fetchzlibng + SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/zlib-ng") + +set(ZLIB_COMPAT ON) +set(ZLIB_ENABLE_TESTS OFF) +set(ZLIBNG_ENABLE_TESTS OFF) +set(Z_PREFIX ON) + +add_compile_options($<$:-Wno-error=unused-command-line-argument>) # clang : error : argument unused during compilation: '-fno-semantic-interposition' +add_compile_options($<$:/wd4127>) # warning C4127: conditional expression is constant +add_compile_options($<$:/wd4242>) # 'function': conversion from 'unsigned int' to 'Pos', possible loss of data, in various deflate_*.c files +add_compile_options($<$:/wd4244>) # 'function': conversion from 'unsigned int' to 'Pos', possible loss of data, in various deflate_*.c files +add_compile_options($<$:/W3>) # D9025: overriding '/W4' with '/W3' + +# TODO: DO we still need to disable /wd4131 ? + +set(SKIP_INSTALL_ALL ON) +FetchContent_MakeAvailable(fetchzlibng) +set(SKIP_INSTALL_ALL OFF) diff --git a/src/native/libs/Common/pal_utilities.h b/src/native/libs/Common/pal_utilities.h index 7b5fa63b6cac03..a1a57c8ed0e8ce 100644 --- a/src/native/libs/Common/pal_utilities.h +++ b/src/native/libs/Common/pal_utilities.h @@ -12,7 +12,9 @@ #include #include #include -#include +#ifndef _WIN32 + #include +#endif #include #include @@ -69,6 +71,7 @@ inline static int ToFileDescriptorUnchecked(intptr_t fd) return (int)fd; } +#ifndef _WIN32 /** * Converts an intptr_t to a file descriptor. * intptr_t is the type used to marshal file descriptors so we can use SafeHandles effectively. @@ -86,6 +89,7 @@ static inline bool CheckInterrupted(ssize_t result) { return result < 0 && errno == EINTR; } +#endif inline static uint32_t Int32ToUint32(int32_t value) { diff --git a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt index 089363cf5554ec..d93dcc51168e5c 100644 --- a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt +++ b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt @@ -1,11 +1,23 @@ project(System.IO.Compression.Native C) +include(FetchContent) include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake) +include(${CLR_SRC_NATIVE_DIR}/external/zlib-ng.cmake) + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/../Common/pal_config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/pal_config.h) set(NATIVECOMPRESSION_SOURCES - pal_zlib.c + pal_zlib.c ) +if (HOST_WIN32 OR CLR_CMAKE_TARGET_WIN32) + list(APPEND NATIVECOMPRESSION_SOURCES "zlib_allocator_win.c") +else() + list(APPEND NATIVECOMPRESSION_SOURCES "zlib_allocator_unix.c") +endif() + if (NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) if (CLR_CMAKE_USE_SYSTEM_BROTLI) @@ -30,11 +42,8 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) append_extra_compression_libs(NATIVE_LIBS_EXTRA) if (CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) - include(${CLR_SRC_NATIVE_DIR}/external/zlib.cmake) - add_definitions(-DINTERNAL_ZLIB) - set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_DEFINITIONS "${ZLIB_COMPILE_DEFINITIONS}") - set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_OPTIONS "${ZLIB_COMPILE_OPTIONS}") - set(NATIVECOMPRESSION_SOURCES ${ZLIB_SOURCES} ${NATIVECOMPRESSION_SOURCES}) + set(NATIVECOMPRESSION_SOURCES ${NATIVECOMPRESSION_SOURCES}) + list(APPEND NATIVE_LIBS_EXTRA zlibstatic) endif() # Disable implicit fallthrough warning for Zlib and Brotli @@ -64,6 +73,7 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) target_link_libraries(System.IO.Compression.Native PRIVATE ${NATIVE_LIBS_EXTRA} + zlibstatic ) if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_USE_SYSTEM_BROTLI) @@ -95,24 +105,17 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) STATIC ${NATIVECOMPRESSION_SOURCES} ) - + target_link_libraries(System.IO.Compression.Native-Static + PRIVATE + zlibstatic + ) set_target_properties(System.IO.Compression.Native-Static PROPERTIES OUTPUT_NAME System.IO.Compression.Native CLEAN_DIRECT_OUTPUT 1) else () if (GEN_SHARED_LIB) include (GenerateExportHeader) endif () - if (CLR_CMAKE_HOST_ARCH_I386 OR CLR_CMAKE_HOST_ARCH_AMD64) - include(${CLR_SRC_NATIVE_DIR}/external/zlib-intel.cmake) - add_definitions(-DINTERNAL_ZLIB_INTEL) - else () - include(${CLR_SRC_NATIVE_DIR}/external/zlib.cmake) - endif () - - add_definitions(-DINTERNAL_ZLIB) - set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_DEFINITIONS "${ZLIB_COMPILE_DEFINITIONS}") - set_source_files_properties(${ZLIB_SOURCES} PROPERTIES COMPILE_OPTIONS "${ZLIB_COMPILE_OPTIONS}") - set(NATIVECOMPRESSION_SOURCES ${ZLIB_SOURCES} ${NATIVECOMPRESSION_SOURCES}) + set(NATIVECOMPRESSION_SOURCES ${NATIVECOMPRESSION_SOURCES}) if (GEN_SHARED_LIB) add_definitions(-DVER_FILEDESCRIPTION_STR="System.IO.Compression.Native") @@ -122,6 +125,10 @@ else () System.IO.Compression.Native.def ${VERSION_FILE_RC_PATH} ) + target_link_libraries(System.IO.Compression.Native + PRIVATE + zlibstatic + ) endif () if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) @@ -132,12 +139,20 @@ else () STATIC ${NATIVECOMPRESSION_SOURCES} ) + target_link_libraries(System.IO.Compression.Native-Static + PRIVATE + zlibstatic + ) if(STATIC_LIBS_ONLY) add_library(System.IO.Compression.Native.Aot STATIC ${NATIVECOMPRESSION_SOURCES} ) + target_link_libraries(System.IO.Compression.Native.Aot + PRIVATE + zlibstatic + ) set_target_properties(System.IO.Compression.Native.Aot PROPERTIES CLR_CONTROL_FLOW_GUARD OFF) set_target_properties(System.IO.Compression.Native.Aot PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) @@ -145,6 +160,10 @@ else () STATIC ${NATIVECOMPRESSION_SOURCES} ) + target_link_libraries(System.IO.Compression.Native.Aot.GuardCF + PRIVATE + zlibstatic + ) set_target_properties(System.IO.Compression.Native.Aot.GuardCF PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) endif() @@ -161,6 +180,7 @@ else () endif () if(STATIC_LIBS_ONLY) + install_static_library(zlibstatic aotsdk nativeaot) install_static_library(System.IO.Compression.Native.Aot aotsdk nativeaot) install_static_library(System.IO.Compression.Native.Aot.GuardCF aotsdk nativeaot) endif() diff --git a/src/native/libs/System.IO.Compression.Native/extra_libs.cmake b/src/native/libs/System.IO.Compression.Native/extra_libs.cmake index 78530ae98e8ff7..cab0e5756a741a 100644 --- a/src/native/libs/System.IO.Compression.Native/extra_libs.cmake +++ b/src/native/libs/System.IO.Compression.Native/extra_libs.cmake @@ -1,23 +1,8 @@ macro(append_extra_compression_libs NativeLibsExtra) - # TODO: remove the mono-style HOST_ variable checks once Mono is using eng/native/configureplatform.cmake to define the CLR_CMAKE_TARGET_ defines - if (CLR_CMAKE_TARGET_BROWSER OR HOST_BROWSER OR CLR_CMAKE_TARGET_WASI OR HOST_WASI) - # nothing special to link - elseif (CLR_CMAKE_TARGET_ANDROID OR HOST_ANDROID) - # need special case here since we want to link against libz.so but find_package() would resolve libz.a - set(ZLIB_LIBRARIES z) - elseif (CLR_CMAKE_TARGET_SUNOS OR HOST_SOLARIS) - set(ZLIB_LIBRARIES z m) - else () - find_package(ZLIB REQUIRED) - set(ZLIB_LIBRARIES ${ZLIB_LIBRARIES} m) - endif () - list(APPEND ${NativeLibsExtra} ${ZLIB_LIBRARIES}) - if (CLR_CMAKE_USE_SYSTEM_BROTLI) find_library(BROTLIDEC brotlidec REQUIRED) find_library(BROTLIENC brotlienc REQUIRED) - list(APPEND ${NativeLibsExtra} ${BROTLIDEC} ${BROTLIENC}) endif () endmacro() diff --git a/src/native/libs/System.IO.Compression.Native/pal_zlib.c b/src/native/libs/System.IO.Compression.Native/pal_zlib.c index bed37d1955f481..c814e927d83d0a 100644 --- a/src/native/libs/System.IO.Compression.Native/pal_zlib.c +++ b/src/native/libs/System.IO.Compression.Native/pal_zlib.c @@ -5,19 +5,14 @@ #include #include "pal_zlib.h" -#ifdef INTERNAL_ZLIB - #ifdef _WIN32 - #define c_static_assert(e) static_assert((e),"") - #endif - #ifdef INTERNAL_ZLIB_INTEL - #include - #else - #include - #endif +#ifdef _WIN32 + #define c_static_assert(e) static_assert((e),"") + #include "../Common/pal_utilities.h" #else #include "pal_utilities.h" - #include #endif +#include +#include c_static_assert(PAL_Z_NOFLUSH == Z_NO_FLUSH); c_static_assert(PAL_Z_FINISH == Z_FINISH); @@ -44,6 +39,10 @@ Initializes the PAL_ZStream by creating and setting its underlying z_stream. static int32_t Init(PAL_ZStream* stream) { z_stream* zStream = (z_stream*)calloc(1, sizeof(z_stream)); + + zStream->zalloc = z_custom_calloc; + zStream->zfree = z_custom_cfree; + stream->internalState = zStream; if (zStream != NULL) diff --git a/src/native/libs/System.IO.Compression.Native/pal_zlib.h b/src/native/libs/System.IO.Compression.Native/pal_zlib.h index b317091b843f62..efb090b0631ae7 100644 --- a/src/native/libs/System.IO.Compression.Native/pal_zlib.h +++ b/src/native/libs/System.IO.Compression.Native/pal_zlib.h @@ -5,12 +5,12 @@ #include #include #define FUNCTIONEXPORT - #define FUNCTIONCALLINGCONVENCTION WINAPI + #define FUNCTIONCALLINGCONVENTION WINAPI #else #include "pal_types.h" #include "pal_compiler.h" #define FUNCTIONEXPORT PALEXPORT - #define FUNCTIONCALLINGCONVENCTION + #define FUNCTIONCALLINGCONVENTION #endif /* @@ -84,7 +84,7 @@ Initializes the PAL_ZStream so the Deflate function can be invoked on it. Returns a PAL_ErrorCode indicating success or an error number on failure. */ -FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION CompressionNative_DeflateInit2_( +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENTION CompressionNative_DeflateInit2_( PAL_ZStream* stream, int32_t level, int32_t method, int32_t windowBits, int32_t memLevel, int32_t strategy); /* @@ -93,21 +93,21 @@ compressed bytes in nextOut. Returns a PAL_ErrorCode indicating success or an error number on failure. */ -FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION CompressionNative_Deflate(PAL_ZStream* stream, int32_t flush); +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENTION CompressionNative_Deflate(PAL_ZStream* stream, int32_t flush); /* All dynamically allocated data structures for this stream are freed. Returns a PAL_ErrorCode indicating success or an error number on failure. */ -FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION CompressionNative_DeflateEnd(PAL_ZStream* stream); +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENTION CompressionNative_DeflateEnd(PAL_ZStream* stream); /* Initializes the PAL_ZStream so the Inflate function can be invoked on it. Returns a PAL_ErrorCode indicating success or an error number on failure. */ -FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION CompressionNative_InflateInit2_(PAL_ZStream* stream, int32_t windowBits); +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENTION CompressionNative_InflateInit2_(PAL_ZStream* stream, int32_t windowBits); /* Inflates (uncompresses) the bytes in the PAL_ZStream's nextIn buffer and puts the @@ -115,14 +115,14 @@ uncompressed bytes in nextOut. Returns a PAL_ErrorCode indicating success or an error number on failure. */ -FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION CompressionNative_Inflate(PAL_ZStream* stream, int32_t flush); +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENTION CompressionNative_Inflate(PAL_ZStream* stream, int32_t flush); /* All dynamically allocated data structures for this stream are freed. Returns a PAL_ErrorCode indicating success or an error number on failure. */ -FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENCTION CompressionNative_InflateEnd(PAL_ZStream* stream); +FUNCTIONEXPORT int32_t FUNCTIONCALLINGCONVENTION CompressionNative_InflateEnd(PAL_ZStream* stream); /* Update a running CRC-32 with the bytes buffer[0..len-1] and return the @@ -130,4 +130,4 @@ updated CRC-32. Returns the updated CRC-32. */ -FUNCTIONEXPORT uint32_t FUNCTIONCALLINGCONVENCTION CompressionNative_Crc32(uint32_t crc, uint8_t* buffer, int32_t len); +FUNCTIONEXPORT uint32_t FUNCTIONCALLINGCONVENTION CompressionNative_Crc32(uint32_t crc, uint8_t* buffer, int32_t len); diff --git a/src/native/libs/System.IO.Compression.Native/zlib_allocator.h b/src/native/libs/System.IO.Compression.Native/zlib_allocator.h new file mode 100644 index 00000000000000..f174f5f3472b53 --- /dev/null +++ b/src/native/libs/System.IO.Compression.Native/zlib_allocator.h @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#ifdef _WIN32 + #include + #include + #define FUNCTIONEXPORT + #define FUNCTIONCALLINGCONVENTION WINAPI +#else + #include "pal_types.h" + #include "pal_compiler.h" + #define FUNCTIONEXPORT PALEXPORT + #define FUNCTIONCALLINGCONVENTION +#endif +#include // voidpf + +FUNCTIONEXPORT voidpf FUNCTIONCALLINGCONVENTION z_custom_calloc(voidpf opaque, unsigned items, unsigned size); + +FUNCTIONEXPORT void FUNCTIONCALLINGCONVENTION z_custom_cfree(voidpf opaque, voidpf ptr); \ No newline at end of file diff --git a/src/native/libs/System.IO.Compression.Native/zlib_allocator_unix.c b/src/native/libs/System.IO.Compression.Native/zlib_allocator_unix.c index 9eb4bbf2671057..84572466d39955 100644 --- a/src/native/libs/System.IO.Compression.Native/zlib_allocator_unix.c +++ b/src/native/libs/System.IO.Compression.Native/zlib_allocator_unix.c @@ -1,9 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#define ZLIB_COMPAT 1 + #include #include -#include +#include +#include /* A custom allocator for zlib that provides some defense-in-depth over standard malloc / free. * (non-Windows version) @@ -70,7 +73,7 @@ static void WriteAllocCookieUnaligned(void* pDest, DOTNET_ALLOC_COOKIE vCookie) const size_t DOTNET_ALLOC_HEADER_COOKIE_SIZE_WITH_PADDING = (sizeof(DOTNET_ALLOC_COOKIE) + MEMORY_ALLOCATION_ALIGNMENT - 1) & ~((size_t)MEMORY_ALLOCATION_ALIGNMENT - 1); const size_t DOTNET_ALLOC_TRAILER_COOKIE_SIZE = sizeof(DOTNET_ALLOC_COOKIE); -voidpf ZLIB_INTERNAL zcalloc(opaque, items, size) +voidpf z_custom_calloc(opaque, items, size) voidpf opaque; unsigned items; unsigned size; @@ -79,7 +82,7 @@ voidpf ZLIB_INTERNAL zcalloc(opaque, items, size) // If initializing a fixed-size structure, zero the memory. bool fZeroMemory = (items == 1); - + size_t cbRequested; if (sizeof(items) + sizeof(size) <= sizeof(cbRequested)) { @@ -119,7 +122,7 @@ static void zcfree_trash_cookie(void* pCookie) memset(pCookie, 0, sizeof(DOTNET_ALLOC_COOKIE)); } -void ZLIB_INTERNAL zcfree(opaque, ptr) +void z_custom_cfree(opaque, ptr) voidpf opaque; voidpf ptr; { diff --git a/src/native/libs/System.IO.Compression.Native/zlib_allocator_win.c b/src/native/libs/System.IO.Compression.Native/zlib_allocator_win.c index 9bdf694495e680..1e766e7b2bdc0f 100644 --- a/src/native/libs/System.IO.Compression.Native/zlib_allocator_win.c +++ b/src/native/libs/System.IO.Compression.Native/zlib_allocator_win.c @@ -1,17 +1,16 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#define ZLIB_COMPAT 1 + #include #include #include #include #include /* _ASSERTE */ -#ifdef INTERNAL_ZLIB_INTEL -#include -#else -#include -#endif +#include +#include /* A custom allocator for zlib that provides some defense-in-depth over standard malloc / free. * (Windows-specific version) @@ -92,7 +91,7 @@ typedef struct _DOTNET_ALLOC_COOKIE const SIZE_T DOTNET_ALLOC_HEADER_COOKIE_SIZE_WITH_PADDING = (sizeof(DOTNET_ALLOC_COOKIE) + MEMORY_ALLOCATION_ALIGNMENT - 1) & ~((SIZE_T)MEMORY_ALLOCATION_ALIGNMENT - 1); const SIZE_T DOTNET_ALLOC_TRAILER_COOKIE_SIZE = sizeof(DOTNET_ALLOC_COOKIE); -voidpf ZLIB_INTERNAL zcalloc(opaque, items, size) +voidpf z_custom_calloc(opaque, items, size) voidpf opaque; unsigned items; unsigned size; @@ -150,7 +149,7 @@ void zcfree_cookie_check_failed() __fastfail(FAST_FAIL_HEAP_METADATA_CORRUPTION); } -void ZLIB_INTERNAL zcfree(opaque, ptr) +void z_custom_cfree(opaque, ptr) voidpf opaque; voidpf ptr; { From 88c2ac4d5ad156d29c1338879a83009bc9027cc6 Mon Sep 17 00:00:00 2001 From: carlossanlop <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 22 May 2024 13:18:30 -0700 Subject: [PATCH 03/39] Workaround: Comment SIZEOF_DATA_PTR test due to problem when trying to override the default value of /INCREMENTAL and the order with respect to /DEBUG. --- src/native/external/zlib-ng/CMakeLists.txt | 46 +++++++++++----------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/native/external/zlib-ng/CMakeLists.txt b/src/native/external/zlib-ng/CMakeLists.txt index 8bcfaf7ea23e4e..94570b45731aec 100644 --- a/src/native/external/zlib-ng/CMakeLists.txt +++ b/src/native/external/zlib-ng/CMakeLists.txt @@ -462,29 +462,31 @@ endif() # # check for ptrdiff_t support # -check_c_source_compiles( - "#include - int main() { - ptrdiff_t *a; - (void)a; - return 0; - }" - HAVE_PTRDIFF_T -) -if(NOT HAVE_PTRDIFF_T) - set(NEED_PTRDIFF_T 1) - - check_type_size("void *" SIZEOF_DATA_PTR) - message(STATUS "sizeof(void *) is ${SIZEOF_DATA_PTR} bytes") - if(${SIZEOF_DATA_PTR} MATCHES "4") - set(PTRDIFF_TYPE "uint32_t") - elseif(${SIZEOF_DATA_PTR} MATCHES "8") - set(PTRDIFF_TYPE "uint64_t") - else() - message(FATAL_ERROR "sizeof(void *) is neither 32 nor 64 bit") - endif() -endif() +# TODO: SIZEOF_DATA_PTR is undefined when using MSVC because /INCREMENTAL:NO keeps getting overwritten to /INCREMENTAL by CMake. +# check_c_source_compiles( +# "#include +# int main() { +# ptrdiff_t *a; +# (void)a; +# return 0; +# }" +# HAVE_PTRDIFF_T +# ) +# if(NOT HAVE_PTRDIFF_T) +# set(NEED_PTRDIFF_T 1) + +# check_type_size("void *" SIZEOF_DATA_PTR) +# message(STATUS "sizeof(void *) is ${SIZEOF_DATA_PTR} bytes") + +# if(${SIZEOF_DATA_PTR} MATCHES "4") +# set(PTRDIFF_TYPE "uint32_t") +# elseif(${SIZEOF_DATA_PTR} MATCHES "8") +# set(PTRDIFF_TYPE "uint64_t") +# else() +# message(FATAL_ERROR "sizeof(void *) is neither 32 nor 64 bit") +# endif() +# endif() add_compile_options($<$:-DZLIB_DEBUG>) From 4400116bed9abec4e7237d36daa3752368f95ea5 Mon Sep 17 00:00:00 2001 From: carlossanlop <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 22 May 2024 13:24:58 -0700 Subject: [PATCH 04/39] Workaround: suppress build error 'W4 overriding W3'. --- src/native/external/zlib-ng.cmake | 2 +- src/native/external/zlib-ng/CMakeLists.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/native/external/zlib-ng.cmake b/src/native/external/zlib-ng.cmake index 9c13d1203c500f..dab26fdc91a5e7 100644 --- a/src/native/external/zlib-ng.cmake +++ b/src/native/external/zlib-ng.cmake @@ -13,7 +13,7 @@ add_compile_options($<$:-Wno-error=u add_compile_options($<$:/wd4127>) # warning C4127: conditional expression is constant add_compile_options($<$:/wd4242>) # 'function': conversion from 'unsigned int' to 'Pos', possible loss of data, in various deflate_*.c files add_compile_options($<$:/wd4244>) # 'function': conversion from 'unsigned int' to 'Pos', possible loss of data, in various deflate_*.c files -add_compile_options($<$:/W3>) # D9025: overriding '/W4' with '/W3' +# add_compile_options($<$:/W3>) # D9025: overriding '/W4' with '/W3' # Commenting because it still fails. Workaround: Comment lines 186-187 in zlib-ng/CMakeLists.txt. # TODO: DO we still need to disable /wd4131 ? diff --git a/src/native/external/zlib-ng/CMakeLists.txt b/src/native/external/zlib-ng/CMakeLists.txt index 94570b45731aec..b2e64f6807c343 100644 --- a/src/native/external/zlib-ng/CMakeLists.txt +++ b/src/native/external/zlib-ng/CMakeLists.txt @@ -183,8 +183,8 @@ elseif(MSVC) # (who'd use cmake from an IDE...) but checking for ICC before checking for MSVC should # avoid mistakes. # /Oi ? - set(WARNFLAGS /W3) - set(WARNFLAGS_MAINTAINER /W4) + # set(WARNFLAGS /W3) + # set(WARNFLAGS_MAINTAINER /W4) set(WARNFLAGS_DISABLE) if(BASEARCH_ARM_FOUND) add_definitions(-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE) From b96f889499ee8170cd2f39e732f169fa4f4718e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 22 May 2024 14:06:33 -0700 Subject: [PATCH 05/39] Workaround: Make sure MacOS ignores unused CLI arguments --- src/native/external/zlib-ng.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/native/external/zlib-ng.cmake b/src/native/external/zlib-ng.cmake index dab26fdc91a5e7..9d6b68a268157d 100644 --- a/src/native/external/zlib-ng.cmake +++ b/src/native/external/zlib-ng.cmake @@ -20,3 +20,5 @@ add_compile_options($<$:/wd4244>) # 'function': conv set(SKIP_INSTALL_ALL ON) FetchContent_MakeAvailable(fetchzlibng) set(SKIP_INSTALL_ALL OFF) + +target_compile_options(zlibstatic PUBLIC $<$:-Wno-error=unused-command-line-argument>) # Make sure MacOS respects ignoring unused CLI arguments \ No newline at end of file From 573700795b2c4f4644ac2ba3b11d90b6089eddad Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 22 May 2024 15:33:41 -0700 Subject: [PATCH 06/39] Fix HAVE_PTRDIFF_T by forcing all try_compile tests to use Release build rules. --- eng/native/configurecompiler.cmake | 6 ++- src/native/external/zlib-ng/CMakeLists.txt | 47 +++++++++++----------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index 8d48160f6ba325..c8c8270b729ada 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -12,6 +12,11 @@ set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# We need to set this to Release as there's no way to intercept configuration-specific linker flags +# for try_compile-style tests (like check_c_source_compiles) and some of the default Debug flags +# (ie. /INCREMENTAL) conflict with our own flags. +set(CMAKE_TRY_COMPILE_CONFIGURATION Release) + include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) include(CheckLinkerFlag) @@ -85,7 +90,6 @@ if (MSVC) #shrink pdb size set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /PDBCOMPRESS") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /INCREMENTAL:NO") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUG") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUGTYPE:CV,FIXUP") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /IGNORE:4197,4013,4254,4070,4221") diff --git a/src/native/external/zlib-ng/CMakeLists.txt b/src/native/external/zlib-ng/CMakeLists.txt index b2e64f6807c343..26beabb82a2ccb 100644 --- a/src/native/external/zlib-ng/CMakeLists.txt +++ b/src/native/external/zlib-ng/CMakeLists.txt @@ -463,30 +463,29 @@ endif() # check for ptrdiff_t support # -# TODO: SIZEOF_DATA_PTR is undefined when using MSVC because /INCREMENTAL:NO keeps getting overwritten to /INCREMENTAL by CMake. -# check_c_source_compiles( -# "#include -# int main() { -# ptrdiff_t *a; -# (void)a; -# return 0; -# }" -# HAVE_PTRDIFF_T -# ) -# if(NOT HAVE_PTRDIFF_T) -# set(NEED_PTRDIFF_T 1) - -# check_type_size("void *" SIZEOF_DATA_PTR) -# message(STATUS "sizeof(void *) is ${SIZEOF_DATA_PTR} bytes") - -# if(${SIZEOF_DATA_PTR} MATCHES "4") -# set(PTRDIFF_TYPE "uint32_t") -# elseif(${SIZEOF_DATA_PTR} MATCHES "8") -# set(PTRDIFF_TYPE "uint64_t") -# else() -# message(FATAL_ERROR "sizeof(void *) is neither 32 nor 64 bit") -# endif() -# endif() +check_c_source_compiles( + "#include + int main() { + ptrdiff_t *a; + (void)a; + return 0; + }" + HAVE_PTRDIFF_T +) +if(NOT HAVE_PTRDIFF_T) + set(NEED_PTRDIFF_T 1) + + check_type_size("void *" SIZEOF_DATA_PTR) + message(STATUS "sizeof(void *) is ${SIZEOF_DATA_PTR} bytes") + + if(${SIZEOF_DATA_PTR} MATCHES "4") + set(PTRDIFF_TYPE "uint32_t") + elseif(${SIZEOF_DATA_PTR} MATCHES "8") + set(PTRDIFF_TYPE "uint64_t") + else() + message(FATAL_ERROR "sizeof(void *) is neither 32 nor 64 bit") + endif() +endif() add_compile_options($<$:-DZLIB_DEBUG>) From b578594de5e5404ccdd8ba14ba9ad446008bc515 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 23 May 2024 11:13:31 -0700 Subject: [PATCH 07/39] Enable CFG and fix warning levels --- src/native/external/zlib-ng.cmake | 5 +++-- src/native/external/zlib-ng/CMakeLists.txt | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/native/external/zlib-ng.cmake b/src/native/external/zlib-ng.cmake index 9d6b68a268157d..6ea84c67c5f60e 100644 --- a/src/native/external/zlib-ng.cmake +++ b/src/native/external/zlib-ng.cmake @@ -13,7 +13,6 @@ add_compile_options($<$:-Wno-error=u add_compile_options($<$:/wd4127>) # warning C4127: conditional expression is constant add_compile_options($<$:/wd4242>) # 'function': conversion from 'unsigned int' to 'Pos', possible loss of data, in various deflate_*.c files add_compile_options($<$:/wd4244>) # 'function': conversion from 'unsigned int' to 'Pos', possible loss of data, in various deflate_*.c files -# add_compile_options($<$:/W3>) # D9025: overriding '/W4' with '/W3' # Commenting because it still fails. Workaround: Comment lines 186-187 in zlib-ng/CMakeLists.txt. # TODO: DO we still need to disable /wd4131 ? @@ -21,4 +20,6 @@ set(SKIP_INSTALL_ALL ON) FetchContent_MakeAvailable(fetchzlibng) set(SKIP_INSTALL_ALL OFF) -target_compile_options(zlibstatic PUBLIC $<$:-Wno-error=unused-command-line-argument>) # Make sure MacOS respects ignoring unused CLI arguments \ No newline at end of file +target_compile_options(zlibstatic PUBLIC $<$:-Wno-error=unused-command-line-argument>) # Make sure MacOS respects ignoring unused CLI arguments +target_compile_options(zlibstatic PRIVATE $<$:/guard:cf>) # Enable CFG always for zlib-ng so we don't need to build two flavors. +set_target_properties(zlibstatic PROPERTIES MSVC_WARNING_LEVEL 3) # Set the warning level for zlib-ng using the repo infrastructure to the same value that zlib-ng's build sets. diff --git a/src/native/external/zlib-ng/CMakeLists.txt b/src/native/external/zlib-ng/CMakeLists.txt index 26beabb82a2ccb..590e43208f1858 100644 --- a/src/native/external/zlib-ng/CMakeLists.txt +++ b/src/native/external/zlib-ng/CMakeLists.txt @@ -183,8 +183,8 @@ elseif(MSVC) # (who'd use cmake from an IDE...) but checking for ICC before checking for MSVC should # avoid mistakes. # /Oi ? - # set(WARNFLAGS /W3) - # set(WARNFLAGS_MAINTAINER /W4) + set(WARNFLAGS /W3) + set(WARNFLAGS_MAINTAINER /W4) set(WARNFLAGS_DISABLE) if(BASEARCH_ARM_FOUND) add_definitions(-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE) From a4ab08ca986a58d8bd38e4438bd831cf8d3c08c0 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 23 May 2024 13:09:02 -0700 Subject: [PATCH 08/39] Use the same inherited property model we're using for our other scenarios for the MSVC warning level option. --- eng/native/configurecompiler.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index c8c8270b729ada..aedc4825273003 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -63,6 +63,7 @@ if (MSVC) define_property(TARGET PROPERTY CLR_CONTROL_FLOW_GUARD INHERITED BRIEF_DOCS "Controls the /guard:cf flag presence" FULL_DOCS "Set this property to ON or OFF to indicate if the /guard:cf compiler and linker flag should be present") define_property(TARGET PROPERTY CLR_EH_CONTINUATION INHERITED BRIEF_DOCS "Controls the /guard:ehcont flag presence" FULL_DOCS "Set this property to ON or OFF to indicate if the /guard:ehcont compiler flag should be present") define_property(TARGET PROPERTY CLR_EH_OPTION INHERITED BRIEF_DOCS "Defines the value of the /EH option" FULL_DOCS "Set this property to one of the valid /EHxx options (/EHa, /EHsc, /EHa-, ...)") + define_property(TARGET PROPERTY MSVC_WARNING_LEVEL INHERITED BRIEF_DOCS "Define the warning level for the /Wn option" FULL_DOCS "Set this property to one of the valid /Wn options (/W0, /W1, /W2, /W3, /W4)") set_property(GLOBAL PROPERTY CLR_CONTROL_FLOW_GUARD ON) @@ -784,7 +785,8 @@ if (MSVC) # [[! Microsoft.Security.SystemsADM.10086 !]] - SDL required warnings # set default warning level to 4 but allow targets to override it. - add_compile_options($<$:/W$>,$,4>>>) + set_property(GLOBAL PROPERTY MSVC_WARNING_LEVEL 4) + add_compile_options($<$:/W$>) add_compile_options($<$:/WX>) # treat warnings as errors add_compile_options($<$:/Oi>) # enable intrinsics add_compile_options($<$:/Oy->) # disable suppressing of the creation of frame pointers on the call stack for quicker function calls From 871a5cdefb3e68d505bbe03be666b3645dbf6d0a Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 23 May 2024 13:44:22 -0700 Subject: [PATCH 09/39] Specify the warning level at the directory level. --- src/native/external/zlib-ng.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/native/external/zlib-ng.cmake b/src/native/external/zlib-ng.cmake index 6ea84c67c5f60e..28f4de947f4cca 100644 --- a/src/native/external/zlib-ng.cmake +++ b/src/native/external/zlib-ng.cmake @@ -20,6 +20,7 @@ set(SKIP_INSTALL_ALL ON) FetchContent_MakeAvailable(fetchzlibng) set(SKIP_INSTALL_ALL OFF) -target_compile_options(zlibstatic PUBLIC $<$:-Wno-error=unused-command-line-argument>) # Make sure MacOS respects ignoring unused CLI arguments +set_property(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/zlib-ng PROPERTY MSVC_WARNING_LEVEL 3) # Set the MSVC warning level for all zlib-ng targets to 3. + +target_compile_options(zlibstatic PRIVATE $<$:-Wno-error=unused-command-line-argument>) # Make sure MacOS respects ignoring unused CLI arguments target_compile_options(zlibstatic PRIVATE $<$:/guard:cf>) # Enable CFG always for zlib-ng so we don't need to build two flavors. -set_target_properties(zlibstatic PROPERTIES MSVC_WARNING_LEVEL 3) # Set the warning level for zlib-ng using the repo infrastructure to the same value that zlib-ng's build sets. From 9ab7ab081468732512c29a02ee21004e5517bb40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 23 May 2024 11:37:30 -0700 Subject: [PATCH 10/39] Fix the build in coreclr. --- .../Microsoft.NETCore.Native.Unix.targets | 2 +- src/mono/CMakeLists.txt | 4 +- src/mono/browser/browser.proj | 1 + src/mono/mono/eventpipe/test/CMakeLists.txt | 2 +- src/mono/mono/metadata/CMakeLists.txt | 10 ++--- src/mono/mono/mini/CMakeLists.txt | 28 ++++++------- src/mono/mono/profiler/CMakeLists.txt | 4 +- .../android/build/AndroidBuild.targets | 2 +- .../msbuild/apple/build/AppleBuild.targets | 1 - src/mono/wasi/wasi.proj | 1 + src/native/external/zlib-intel.cmake | 29 ------------- src/native/external/zlib-ng.cmake | 20 +++++++-- src/native/external/zlib-ng/CMakeLists.txt | 1 - src/native/external/zlib.cmake | 41 ------------------- .../CMakeLists.txt | 9 ++-- .../extra_libs.cmake | 2 +- .../zlib_allocator_unix.c | 2 - .../zlib_allocator_win.c | 2 - 18 files changed, 49 insertions(+), 112 deletions(-) delete mode 100644 src/native/external/zlib-intel.cmake delete mode 100644 src/native/external/zlib.cmake diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index d3dc85e04f82e4..c0bcb767740d20 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -129,6 +129,7 @@ The .NET Foundation licenses this file to you under the MIT license. + @@ -188,7 +189,6 @@ The .NET Foundation licenses this file to you under the MIT license. - diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index 59d506591a3167..6c13615187f112 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -655,10 +655,10 @@ if(LLVM_PREFIX) if(HOST_LINUX) # llvm-config --system-libs - set(llvm_system_libs ${MONO_cxx_lib} "-lz" "-lrt" "-ldl" "-lpthread" "-lm") + set(llvm_system_libs ${MONO_cxx_lib} "-lrt" "-ldl" "-lpthread" "-lm") elseif(HOST_OSX) # llvm-config --system-libs - set(llvm_system_libs "-lz" "-lm") + set(llvm_system_libs "-lm") endif() # llvm-config --libs analysis core bitwriter mcjit orcjit diff --git a/src/mono/browser/browser.proj b/src/mono/browser/browser.proj index 81768d43e6a536..47a351fb53b415 100644 --- a/src/mono/browser/browser.proj +++ b/src/mono/browser/browser.proj @@ -63,6 +63,7 @@ + diff --git a/src/mono/mono/eventpipe/test/CMakeLists.txt b/src/mono/mono/eventpipe/test/CMakeLists.txt index d313e630adaaba..11f37a3720af7b 100644 --- a/src/mono/mono/eventpipe/test/CMakeLists.txt +++ b/src/mono/mono/eventpipe/test/CMakeLists.txt @@ -39,7 +39,7 @@ if(ENABLE_PERFTRACING) set(CMAKE_SKIP_RPATH 1) add_executable(ep-test ${EVENTPIPE_TEST_SOURCES} ${EVENTPIPE_TEST_HEADERS}) target_sources(ep-test PRIVATE "${mono-components-objects}") - target_link_libraries(ep-test PRIVATE eglib_api monosgen-static ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS} monoapi) + target_link_libraries(ep-test PRIVATE eglib_api monosgen-static ${OS_LIBS} ${LLVM_LIBS} zlib monoapi) install_with_stripped_symbols(ep-test TARGETS bin) else(ENABLE_EVENTPIPE_TEST AND STATIC_COMPONENTS AND (NOT DISABLE_COMPONENTS) AND (NOT DISABLE_LIBS) AND (NOT DISABLE_EXECUTABLES)) message(VERBOSE "Skip building native EventPipe library test runner.") diff --git a/src/mono/mono/metadata/CMakeLists.txt b/src/mono/mono/metadata/CMakeLists.txt index 2926655fdc1aaf..1c5bd232466a6e 100644 --- a/src/mono/mono/metadata/CMakeLists.txt +++ b/src/mono/mono/metadata/CMakeLists.txt @@ -5,7 +5,7 @@ project(metadata C) # if(DISABLE_ICALL_TABLES) add_library(mono-icall-table STATIC "icall-table.c") -target_link_libraries(mono-icall-table PRIVATE monoapi eglib_api zlibstatic) +target_link_libraries(mono-icall-table PRIVATE monoapi eglib_api zlib) target_include_directories(mono-icall-table PRIVATE ${PROJECT_BINARY_DIR}/../.. ${PROJECT_SOURCE_DIR}/../.. ${PROJECT_SOURCE_DIR}/..) @@ -200,10 +200,10 @@ set(metadata_sources "${metadata_platform_sources};${metadata_common_sources};${ if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS) add_library(metadata_objects_shared OBJECT ${metadata_sources}) target_compile_definitions(metadata_objects_shared PRIVATE ${metadata_compile_definitions}) - target_link_libraries(metadata_objects_shared PRIVATE monoapi eglib_api utils_objects_shared zlibstatic) + target_link_libraries(metadata_objects_shared PRIVATE monoapi eglib_api utils_objects_shared zlib) # note: metadata_objects is an object library, so this doesn't force linking with sgen, # it just adds the relevant include directories - which we need even with Boehm - target_link_libraries(metadata_objects_shared PRIVATE sgen_objects_shared zlibstatic) + target_link_libraries(metadata_objects_shared PRIVATE sgen_objects_shared zlib) target_compile_definitions(metadata_objects_shared PRIVATE -DMONO_DLL_EXPORT) target_include_directories(metadata_objects_shared PRIVATE ${PROJECT_BINARY_DIR}/../.. ${PROJECT_SOURCE_DIR}/../.. @@ -212,10 +212,10 @@ endif() add_library(metadata_objects OBJECT ${metadata_sources}) target_compile_definitions(metadata_objects PRIVATE ${metadata_compile_definitions}) -target_link_libraries(metadata_objects PRIVATE monoapi eglib_api utils_objects zlibstatic) +target_link_libraries(metadata_objects PRIVATE monoapi eglib_api utils_objects zlib) # note: metadata_objects is an object library, so this doesn't force linking with sgen, # it just adds the relevant include directories - which we need even with Boehm -target_link_libraries(metadata_objects PRIVATE sgen_objects zlibstatic) +target_link_libraries(metadata_objects PRIVATE sgen_objects zlib) if(NOT HOST_WIN32) target_compile_definitions(metadata_objects PRIVATE -DMONO_DLL_EXPORT) endif() diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index d3af774a12154f..059533084cb201 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -264,7 +264,7 @@ endif() if(ENABLE_INTERP_LIB) add_library(mono-ee-interp STATIC "${interp_sources}") -target_link_libraries(mono-ee-interp PRIVATE monoapi eglib_api zlibstatic) +target_link_libraries(mono-ee-interp PRIVATE monoapi eglib_api zlib) target_include_directories(mono-ee-interp PRIVATE ${PROJECT_BINARY_DIR}/../.. ${PROJECT_SOURCE_DIR}/../.. ${PROJECT_SOURCE_DIR}/..) @@ -319,11 +319,11 @@ set(monosgen-sources "${mini_sources}") if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS) add_library(monosgen-objects_shared OBJECT "${monosgen-sources}") target_compile_definitions(monosgen-objects_shared PRIVATE -DMONO_DLL_EXPORT) - target_link_libraries (monosgen-objects_shared PRIVATE monoapi eglib_api utils_objects_shared sgen_objects_shared metadata_objects_shared zlibstatic) + target_link_libraries (monosgen-objects_shared PRIVATE monoapi eglib_api utils_objects_shared sgen_objects_shared metadata_objects_shared zlib) endif() add_library(monosgen-objects OBJECT "${monosgen-sources}") -target_link_libraries (monosgen-objects PRIVATE monoapi eglib_api utils_objects sgen_objects metadata_objects zlibstatic) +target_link_libraries (monosgen-objects PRIVATE monoapi eglib_api utils_objects sgen_objects metadata_objects zlib) if(NOT HOST_WIN32) target_compile_definitions(monosgen-objects PRIVATE -DMONO_DLL_EXPORT) endif() @@ -349,16 +349,16 @@ if(NOT DISABLE_SHARED_LIBS) target_compile_definitions(monosgen-shared PRIVATE -DMONO_DLL_EXPORT) # musl-libc implements ucontext in a different library on s390x if(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) - target_link_libraries(monosgen-shared PRIVATE ucontext zlibstatic) + target_link_libraries(monosgen-shared PRIVATE ucontext) endif(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) set_target_properties(monosgen-shared PROPERTIES OUTPUT_NAME ${MONO_SHARED_LIB_NAME}) if(MONO_SET_RPATH_ORIGIN) set_target_properties(monosgen-shared PROPERTIES INSTALL_RPATH "$ORIGIN") endif() if(HOST_WIN32) - target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects_shared sgen_objects_shared metadata_objects_shared dn-containers zlibstatic) + target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects_shared sgen_objects_shared metadata_objects_shared dn-containers zlib) else() - target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers zlibstatic) + target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers zlib) endif() target_include_directories (monosgen-shared PRIVATE monoapi) if(TARGET_WIN32) @@ -367,9 +367,9 @@ if(NOT DISABLE_SHARED_LIBS) set_target_properties(monosgen-shared PROPERTIES IMPORT_SUFFIX ".import.lib") endif() if(CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) - target_link_libraries(monosgen-shared PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS}) + target_link_libraries(monosgen-shared PRIVATE ${OS_LIBS} ${LLVM_LIBS} zlib) else() - target_link_libraries(monosgen-shared PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS}) + target_link_libraries(monosgen-shared PRIVATE ${OS_LIBS} ${LLVM_LIBS} zlib) endif() if(TARGET_DARWIN) set_property(TARGET monosgen-shared APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-compatibility_version -Wl,2.0 -Wl,-current_version -Wl,2.0") @@ -392,7 +392,7 @@ if(NOT DISABLE_SHARED_LIBS) install_with_stripped_symbols(monosgen-shared TARGETS lib) if(HOST_WIN32 AND TARGET_AMD64) add_library(monosgen-shared-dac SHARED "mini-windows-dlldac.c") - target_link_libraries(monosgen-shared-dac PRIVATE monoapi eglib_api zlibstatic) + target_link_libraries(monosgen-shared-dac PRIVATE monoapi eglib_api zlib) set_target_properties(monosgen-shared-dac PROPERTIES OUTPUT_NAME ${MONO_SHARED_LIB_NAME}-dac) endif() @@ -414,7 +414,7 @@ if(NOT DISABLE_SHARED_LIBS) endif() add_library(${frameworkconfig} SHARED $) target_compile_definitions(${frameworkconfig} PRIVATE -DMONO_DLL_EXPORT) - target_link_libraries(${frameworkconfig} PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers zlibstatic) + target_link_libraries(${frameworkconfig} PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers zlib) target_link_libraries(${frameworkconfig} PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS}) set_property(TARGET ${frameworkconfig} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-compatibility_version -Wl,2.0 -Wl,-current_version -Wl,2.0") @@ -531,14 +531,14 @@ if(NOT DISABLE_EXECUTABLES) set_target_properties(mono-sgen PROPERTIES INSTALL_RPATH "$ORIGIN") endif() endif() - target_link_libraries(mono-sgen PRIVATE monoapi eglib_api monosgen-static dn-containers zlibstatic) + target_link_libraries(mono-sgen PRIVATE monoapi eglib_api monosgen-static dn-containers zlib) if (HOST_WASM) - target_link_libraries(mono-sgen PRIVATE mono-wasm-nosimd zlibstatic) + target_link_libraries(mono-sgen PRIVATE mono-wasm-nosimd zlib) endif() - target_link_libraries(mono-sgen PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS}) + target_link_libraries(mono-sgen PRIVATE ${OS_LIBS} ${LLVM_LIBS} zlib) # musl-libc implements ucontext in a different library on s390x if(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) - target_link_libraries(mono-sgen PRIVATE ucontex zlibstatic) + target_link_libraries(mono-sgen PRIVATE ucontext) endif(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) if(NOT DISABLE_COMPONENTS AND STATIC_COMPONENTS AND NOT DISABLE_LINK_STATIC_COMPONENTS) # if components are built statically, link them into runtime. diff --git a/src/mono/mono/profiler/CMakeLists.txt b/src/mono/mono/profiler/CMakeLists.txt index 35a377c2f3056e..6b84015950b83e 100644 --- a/src/mono/mono/profiler/CMakeLists.txt +++ b/src/mono/mono/profiler/CMakeLists.txt @@ -14,7 +14,7 @@ if(NOT DISABLE_LIBS) # Build the logging profiler only for certain platforms add_library(mono-profiler-log SHARED helper.c log.c log-args.c) target_compile_definitions(mono-profiler-log PRIVATE -DMONO_DLL_EXPORT) - target_link_libraries(mono-profiler-log PRIVATE monosgen-shared monoapi eglib_objects zlibstatic) + target_link_libraries(mono-profiler-log PRIVATE monosgen-shared monoapi eglib_objects zlib) if(HOST_ANDROID) target_link_libraries(mono-profiler-log PRIVATE log) endif() @@ -26,7 +26,7 @@ if(NOT DISABLE_LIBS) install(TARGETS mono-profiler-log-static LIBRARY) if(NOT DISABLE_LOG_PROFILER_GZ) - target_link_libraries(mono-profiler-log PRIVATE ${Z_LIBS}) + target_link_libraries(mono-profiler-log PRIVATE zlib) endif() endif() diff --git a/src/mono/msbuild/android/build/AndroidBuild.targets b/src/mono/msbuild/android/build/AndroidBuild.targets index 917aed88506697..743084d18cdd5f 100644 --- a/src/mono/msbuild/android/build/AndroidBuild.targets +++ b/src/mono/msbuild/android/build/AndroidBuild.targets @@ -48,7 +48,6 @@ - <_CommonLinkerArgs Include="-l:libz.so" /> <_CommonLinkerArgs Include="-l:liblog.so" /> <_CommonLinkerArgs Include="-l:libc.so" /> <_CommonLinkerArgs Include="-l:libm.so" /> @@ -211,6 +210,7 @@ + diff --git a/src/mono/msbuild/apple/build/AppleBuild.targets b/src/mono/msbuild/apple/build/AppleBuild.targets index 35d0f16c35b4b8..343ab6072e83a2 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.targets +++ b/src/mono/msbuild/apple/build/AppleBuild.targets @@ -70,7 +70,6 @@ - <_CommonLinkerArgs Include="-lz" /> <_CommonLinkerArgs Include="-lc++" /> <_CommonLinkerArgs Include="-liconv" /> <_CommonLinkerArgs Include="-licucore" /> diff --git a/src/mono/wasi/wasi.proj b/src/mono/wasi/wasi.proj index 9c386481a26e19..99bf8a6ee54f80 100644 --- a/src/mono/wasi/wasi.proj +++ b/src/mono/wasi/wasi.proj @@ -49,6 +49,7 @@ + diff --git a/src/native/external/zlib-intel.cmake b/src/native/external/zlib-intel.cmake deleted file mode 100644 index 2f5b68c69597d9..00000000000000 --- a/src/native/external/zlib-intel.cmake +++ /dev/null @@ -1,29 +0,0 @@ -# # IMPORTANT: do not use add_compile_options(), add_definitions() or similar functions here since it will leak to the including projects - -# set(ZLIB_SOURCES_BASE -# adler32.c -# compress.c -# crc_folding.c -# crc32.c -# deflate_medium.c -# deflate_quick.c -# deflate.c -# inffast.c -# inflate.c -# inftrees.c -# match.c -# slide_sse.c -# trees.c -# x86.c -# zutil.c -# ../../libs/System.IO.Compression.Native/zlib_allocator_win.c -# ) - -# addprefix(ZLIB_SOURCES "${CMAKE_CURRENT_LIST_DIR}/zlib-intel" "${ZLIB_SOURCES_BASE}") - -# # enable custom zlib allocator -# set(ZLIB_COMPILE_DEFINITIONS "MY_ZCALLOC") - -# if(HOST_WIN32 OR CLR_CMAKE_TARGET_WIN32) -# set(ZLIB_COMPILE_OPTIONS "/wd4127;/wd4131") -# endif() diff --git a/src/native/external/zlib-ng.cmake b/src/native/external/zlib-ng.cmake index 28f4de947f4cca..dc2ee1c3acf6d4 100644 --- a/src/native/external/zlib-ng.cmake +++ b/src/native/external/zlib-ng.cmake @@ -9,18 +9,30 @@ set(ZLIB_ENABLE_TESTS OFF) set(ZLIBNG_ENABLE_TESTS OFF) set(Z_PREFIX ON) -add_compile_options($<$:-Wno-error=unused-command-line-argument>) # clang : error : argument unused during compilation: '-fno-semantic-interposition' +add_compile_options($<$:-Wno-unused-command-line-argument>) # clang : error : argument unused during compilation: '-fno-semantic-interposition' +add_compile_options($<$:-Wno-logical-op-parentheses>) # place parentheses around the '&&' expression to silence this warning add_compile_options($<$:/wd4127>) # warning C4127: conditional expression is constant add_compile_options($<$:/wd4242>) # 'function': conversion from 'unsigned int' to 'Pos', possible loss of data, in various deflate_*.c files add_compile_options($<$:/wd4244>) # 'function': conversion from 'unsigned int' to 'Pos', possible loss of data, in various deflate_*.c files -# TODO: DO we still need to disable /wd4131 ? +# 'aligned_alloc' is only available on iOS 13.0 or newer and in some cases it is not available on Android, yet it is set by zlib-ng/CMakeLists.txt. +if (CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS OR CLR_CMAKE_TARGET_ANDROID OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) + set(HAVE_ALIGNED_ALLOC FALSE CACHE BOOL "have aligned_alloc" FORCE) +endif() +# Workaround: Some SIMD types for ARM are not being found +if (CLR_CMAKE_TARGET_ANDROID) + set(WITH_ARMV6 OFF CACHE BOOL "with armv6" FORCE) +endif() + +set(BUILD_SHARED_LIBS OFF) # Shared libraries aren't supported in wasm set(SKIP_INSTALL_ALL ON) FetchContent_MakeAvailable(fetchzlibng) set(SKIP_INSTALL_ALL OFF) set_property(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/zlib-ng PROPERTY MSVC_WARNING_LEVEL 3) # Set the MSVC warning level for all zlib-ng targets to 3. +target_compile_options(zlib PRIVATE $<$:-Wno-unused-command-line-argument>) # Make sure MacOS respects ignoring unused CLI arguments +target_compile_options(zlib PRIVATE $<$:-Wno-logical-op-parentheses>) # place parentheses around the '&&' expression to silence this warning +target_compile_options(zlib PRIVATE $<$:/guard:cf>) # Enable CFG always for zlib-ng so we don't need to build two flavors. -target_compile_options(zlibstatic PRIVATE $<$:-Wno-error=unused-command-line-argument>) # Make sure MacOS respects ignoring unused CLI arguments -target_compile_options(zlibstatic PRIVATE $<$:/guard:cf>) # Enable CFG always for zlib-ng so we don't need to build two flavors. +set_target_properties(zlib PROPERTIES DEBUG_POSTFIX "") # Workaround: zlib's debug lib name is zlibd.lib diff --git a/src/native/external/zlib-ng/CMakeLists.txt b/src/native/external/zlib-ng/CMakeLists.txt index 590e43208f1858..8bcfaf7ea23e4e 100644 --- a/src/native/external/zlib-ng/CMakeLists.txt +++ b/src/native/external/zlib-ng/CMakeLists.txt @@ -462,7 +462,6 @@ endif() # # check for ptrdiff_t support # - check_c_source_compiles( "#include int main() { diff --git a/src/native/external/zlib.cmake b/src/native/external/zlib.cmake deleted file mode 100644 index fc3f7873a70e51..00000000000000 --- a/src/native/external/zlib.cmake +++ /dev/null @@ -1,41 +0,0 @@ -# # IMPORTANT: do not use add_compile_options(), add_definitions() or similar functions here since it will leak to the including projects - -# set(ZLIB_SOURCES_BASE -# adler32.c -# compress.c -# crc32.c -# uncompr.c -# deflate.c -# gzguts.h -# trees.c -# zutil.c -# inflate.c -# infback.c -# inftrees.c -# inffast.c -# crc32.h -# deflate.h -# inffast.h -# inffixed.h -# inflate.h -# inftrees.h -# trees.h -# zconf.h -# zlib.h -# zutil.h -# ) - -# if(HOST_WIN32 OR CLR_CMAKE_TARGET_WIN32) -# set(ZLIB_SOURCES_BASE ${ZLIB_SOURCES_BASE} ../../libs/System.IO.Compression.Native/zlib_allocator_win.c) -# else() -# set(ZLIB_SOURCES_BASE ${ZLIB_SOURCES_BASE} ../../libs/System.IO.Compression.Native/zlib_allocator_unix.c) -# endif() - -# addprefix(ZLIB_SOURCES "${CMAKE_CURRENT_LIST_DIR}/zlib" "${ZLIB_SOURCES_BASE}") - -# # enable custom zlib allocator -# set(ZLIB_COMPILE_DEFINITIONS "MY_ZCALLOC") - -# if(HOST_WIN32 OR CLR_CMAKE_TARGET_WIN32) -# set(ZLIB_COMPILE_OPTIONS "/wd4127;/wd4131") -# endif() diff --git a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt index d93dcc51168e5c..384747eddc7a2b 100644 --- a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt +++ b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt @@ -1,9 +1,10 @@ project(System.IO.Compression.Native C) -include(FetchContent) include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake) include(${CLR_SRC_NATIVE_DIR}/external/zlib-ng.cmake) +add_compile_definitions(ZLIB_COMPAT) + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/../Common/pal_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/pal_config.h) @@ -43,7 +44,6 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) if (CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) set(NATIVECOMPRESSION_SOURCES ${NATIVECOMPRESSION_SOURCES}) - list(APPEND NATIVE_LIBS_EXTRA zlibstatic) endif() # Disable implicit fallthrough warning for Zlib and Brotli @@ -73,7 +73,6 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) target_link_libraries(System.IO.Compression.Native PRIVATE ${NATIVE_LIBS_EXTRA} - zlibstatic ) if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_USE_SYSTEM_BROTLI) @@ -127,7 +126,7 @@ else () ) target_link_libraries(System.IO.Compression.Native PRIVATE - zlibstatic + zlib ) endif () @@ -180,7 +179,7 @@ else () endif () if(STATIC_LIBS_ONLY) - install_static_library(zlibstatic aotsdk nativeaot) + install_static_library(zlib aotsdk nativeaot) install_static_library(System.IO.Compression.Native.Aot aotsdk nativeaot) install_static_library(System.IO.Compression.Native.Aot.GuardCF aotsdk nativeaot) endif() diff --git a/src/native/libs/System.IO.Compression.Native/extra_libs.cmake b/src/native/libs/System.IO.Compression.Native/extra_libs.cmake index cab0e5756a741a..d5a6042a8981d6 100644 --- a/src/native/libs/System.IO.Compression.Native/extra_libs.cmake +++ b/src/native/libs/System.IO.Compression.Native/extra_libs.cmake @@ -1,5 +1,5 @@ - macro(append_extra_compression_libs NativeLibsExtra) + list(APPEND ${NativeLibsExtra} zlib) if (CLR_CMAKE_USE_SYSTEM_BROTLI) find_library(BROTLIDEC brotlidec REQUIRED) find_library(BROTLIENC brotlienc REQUIRED) diff --git a/src/native/libs/System.IO.Compression.Native/zlib_allocator_unix.c b/src/native/libs/System.IO.Compression.Native/zlib_allocator_unix.c index 84572466d39955..52c0cfeb83a2a2 100644 --- a/src/native/libs/System.IO.Compression.Native/zlib_allocator_unix.c +++ b/src/native/libs/System.IO.Compression.Native/zlib_allocator_unix.c @@ -1,8 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#define ZLIB_COMPAT 1 - #include #include #include diff --git a/src/native/libs/System.IO.Compression.Native/zlib_allocator_win.c b/src/native/libs/System.IO.Compression.Native/zlib_allocator_win.c index 1e766e7b2bdc0f..b89d5d9b298d14 100644 --- a/src/native/libs/System.IO.Compression.Native/zlib_allocator_win.c +++ b/src/native/libs/System.IO.Compression.Native/zlib_allocator_win.c @@ -1,8 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#define ZLIB_COMPAT 1 - #include #include #include From 76a47b5bb5dbff44ec4923f675fd129dbe354b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Tue, 18 Jun 2024 11:28:39 -0700 Subject: [PATCH 11/39] remove zlib from mono metadata target_link_library calls --- src/mono/mono/metadata/CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mono/mono/metadata/CMakeLists.txt b/src/mono/mono/metadata/CMakeLists.txt index 1c5bd232466a6e..773381d6c1c9ad 100644 --- a/src/mono/mono/metadata/CMakeLists.txt +++ b/src/mono/mono/metadata/CMakeLists.txt @@ -5,7 +5,7 @@ project(metadata C) # if(DISABLE_ICALL_TABLES) add_library(mono-icall-table STATIC "icall-table.c") -target_link_libraries(mono-icall-table PRIVATE monoapi eglib_api zlib) +target_link_libraries(mono-icall-table PRIVATE monoapi eglib_api) target_include_directories(mono-icall-table PRIVATE ${PROJECT_BINARY_DIR}/../.. ${PROJECT_SOURCE_DIR}/../.. ${PROJECT_SOURCE_DIR}/..) @@ -200,10 +200,10 @@ set(metadata_sources "${metadata_platform_sources};${metadata_common_sources};${ if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS) add_library(metadata_objects_shared OBJECT ${metadata_sources}) target_compile_definitions(metadata_objects_shared PRIVATE ${metadata_compile_definitions}) - target_link_libraries(metadata_objects_shared PRIVATE monoapi eglib_api utils_objects_shared zlib) + target_link_libraries(metadata_objects_shared PRIVATE monoapi eglib_api utils_objects_shared) # note: metadata_objects is an object library, so this doesn't force linking with sgen, # it just adds the relevant include directories - which we need even with Boehm - target_link_libraries(metadata_objects_shared PRIVATE sgen_objects_shared zlib) + target_link_libraries(metadata_objects_shared PRIVATE sgen_objects_shared) target_compile_definitions(metadata_objects_shared PRIVATE -DMONO_DLL_EXPORT) target_include_directories(metadata_objects_shared PRIVATE ${PROJECT_BINARY_DIR}/../.. ${PROJECT_SOURCE_DIR}/../.. @@ -212,10 +212,10 @@ endif() add_library(metadata_objects OBJECT ${metadata_sources}) target_compile_definitions(metadata_objects PRIVATE ${metadata_compile_definitions}) -target_link_libraries(metadata_objects PRIVATE monoapi eglib_api utils_objects zlib) +target_link_libraries(metadata_objects PRIVATE monoapi eglib_api utils_objects) # note: metadata_objects is an object library, so this doesn't force linking with sgen, # it just adds the relevant include directories - which we need even with Boehm -target_link_libraries(metadata_objects PRIVATE sgen_objects zlib) +target_link_libraries(metadata_objects PRIVATE sgen_objects) if(NOT HOST_WIN32) target_compile_definitions(metadata_objects PRIVATE -DMONO_DLL_EXPORT) endif() From e0bbfcb7582aa9e9e8c1d8c340fa27e29bdea3f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Tue, 18 Jun 2024 11:30:09 -0700 Subject: [PATCH 12/39] Only keep zlib in mono mini in two places --- src/mono/mono/mini/CMakeLists.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 059533084cb201..00eae821c539ab 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -264,7 +264,7 @@ endif() if(ENABLE_INTERP_LIB) add_library(mono-ee-interp STATIC "${interp_sources}") -target_link_libraries(mono-ee-interp PRIVATE monoapi eglib_api zlib) +target_link_libraries(mono-ee-interp PRIVATE monoapi eglib_api) target_include_directories(mono-ee-interp PRIVATE ${PROJECT_BINARY_DIR}/../.. ${PROJECT_SOURCE_DIR}/../.. ${PROJECT_SOURCE_DIR}/..) @@ -319,11 +319,11 @@ set(monosgen-sources "${mini_sources}") if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS) add_library(monosgen-objects_shared OBJECT "${monosgen-sources}") target_compile_definitions(monosgen-objects_shared PRIVATE -DMONO_DLL_EXPORT) - target_link_libraries (monosgen-objects_shared PRIVATE monoapi eglib_api utils_objects_shared sgen_objects_shared metadata_objects_shared zlib) + target_link_libraries (monosgen-objects_shared PRIVATE monoapi eglib_api utils_objects_shared sgen_objects_shared metadata_objects_shared) endif() add_library(monosgen-objects OBJECT "${monosgen-sources}") -target_link_libraries (monosgen-objects PRIVATE monoapi eglib_api utils_objects sgen_objects metadata_objects zlib) +target_link_libraries (monosgen-objects PRIVATE monoapi eglib_api utils_objects sgen_objects metadata_objects) if(NOT HOST_WIN32) target_compile_definitions(monosgen-objects PRIVATE -DMONO_DLL_EXPORT) endif() @@ -392,7 +392,7 @@ if(NOT DISABLE_SHARED_LIBS) install_with_stripped_symbols(monosgen-shared TARGETS lib) if(HOST_WIN32 AND TARGET_AMD64) add_library(monosgen-shared-dac SHARED "mini-windows-dlldac.c") - target_link_libraries(monosgen-shared-dac PRIVATE monoapi eglib_api zlib) + target_link_libraries(monosgen-shared-dac PRIVATE monoapi eglib_api) set_target_properties(monosgen-shared-dac PROPERTIES OUTPUT_NAME ${MONO_SHARED_LIB_NAME}-dac) endif() @@ -415,7 +415,7 @@ if(NOT DISABLE_SHARED_LIBS) add_library(${frameworkconfig} SHARED $) target_compile_definitions(${frameworkconfig} PRIVATE -DMONO_DLL_EXPORT) target_link_libraries(${frameworkconfig} PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers zlib) - target_link_libraries(${frameworkconfig} PRIVATE ${OS_LIBS} ${LLVM_LIBS} ${Z_LIBS}) + target_link_libraries(${frameworkconfig} PRIVATE ${OS_LIBS} ${LLVM_LIBS} zlib) set_property(TARGET ${frameworkconfig} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-compatibility_version -Wl,2.0 -Wl,-current_version -Wl,2.0") string(REPLACE "*" ";" componentsobjects-whitespace "${componentsobjects}") @@ -533,9 +533,9 @@ if(NOT DISABLE_EXECUTABLES) endif() target_link_libraries(mono-sgen PRIVATE monoapi eglib_api monosgen-static dn-containers zlib) if (HOST_WASM) - target_link_libraries(mono-sgen PRIVATE mono-wasm-nosimd zlib) + target_link_libraries(mono-sgen PRIVATE mono-wasm-nosimd) endif() - target_link_libraries(mono-sgen PRIVATE ${OS_LIBS} ${LLVM_LIBS} zlib) + target_link_libraries(mono-sgen PRIVATE ${OS_LIBS} ${LLVM_LIBS}) # musl-libc implements ucontext in a different library on s390x if(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) target_link_libraries(mono-sgen PRIVATE ucontext) From f4a2802f340ae85a78852e22d8117c48411f4b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Tue, 18 Jun 2024 11:30:56 -0700 Subject: [PATCH 13/39] Keep only one zlib in mono profiler --- src/mono/mono/profiler/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/profiler/CMakeLists.txt b/src/mono/mono/profiler/CMakeLists.txt index 6b84015950b83e..fc18e2f7e3665b 100644 --- a/src/mono/mono/profiler/CMakeLists.txt +++ b/src/mono/mono/profiler/CMakeLists.txt @@ -14,7 +14,7 @@ if(NOT DISABLE_LIBS) # Build the logging profiler only for certain platforms add_library(mono-profiler-log SHARED helper.c log.c log-args.c) target_compile_definitions(mono-profiler-log PRIVATE -DMONO_DLL_EXPORT) - target_link_libraries(mono-profiler-log PRIVATE monosgen-shared monoapi eglib_objects zlib) + target_link_libraries(mono-profiler-log PRIVATE monosgen-shared monoapi eglib_objects) if(HOST_ANDROID) target_link_libraries(mono-profiler-log PRIVATE log) endif() From 40c43b6afa7c8d74c1b3adc9902fcbe553566925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Tue, 18 Jun 2024 22:22:15 -0700 Subject: [PATCH 14/39] fix wasi and browser build --- src/mono/browser/runtime/CMakeLists.txt | 1 + src/mono/mono.proj | 3 +++ src/mono/mono/metadata/CMakeLists.txt | 2 +- src/mono/mono/mini/CMakeLists.txt | 2 +- src/mono/wasi/runtime/CMakeLists.txt | 1 + 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/mono/browser/runtime/CMakeLists.txt b/src/mono/browser/runtime/CMakeLists.txt index 8b7939330f8c3a..f707431fc38d55 100644 --- a/src/mono/browser/runtime/CMakeLists.txt +++ b/src/mono/browser/runtime/CMakeLists.txt @@ -28,6 +28,7 @@ target_link_libraries(dotnet.native ${MONO_ARTIFACTS_DIR}/libmono-wasm-${CONFIGURATION_INTERPSIMDTABLES_LIB}.a ${MONO_ARTIFACTS_DIR}/libmono-profiler-aot.a ${MONO_ARTIFACTS_DIR}/libmono-profiler-browser.a + ${MONO_ARTIFACTS_DIR}/libz.a ${NATIVE_BIN_DIR}/wasm-bundled-timezones.a ${NATIVE_BIN_DIR}/libSystem.Native.a ${NATIVE_BIN_DIR}/libSystem.Globalization.Native.a diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 14056eb3a7e24e..ceb783599086e5 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -1189,6 +1189,9 @@ JS_ENGINES = [NODE_JS] <_MonoRuntimeArtifacts Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)out\lib\libmono-wasm-nosimd.a"> $(RuntimeBinDir)libmono-wasm-nosimd.a + <_MonoRuntimeArtifacts Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)_deps\fetchzlibng-build\libz.a"> + $(RuntimeBinDir)libz.a + <_MonoICorDebugArtifacts Condition="'$(MonoMsCorDbi)' == 'true'" Include="$(MonoObjDir)out\lib\$(LibPrefix)mscordbi$(LibSuffix)"> $(RuntimeBinDir)$(LibPrefix)mscordbi$(LibSuffix) diff --git a/src/mono/mono/metadata/CMakeLists.txt b/src/mono/mono/metadata/CMakeLists.txt index 773381d6c1c9ad..e5c2459ccbacf7 100644 --- a/src/mono/mono/metadata/CMakeLists.txt +++ b/src/mono/mono/metadata/CMakeLists.txt @@ -212,7 +212,7 @@ endif() add_library(metadata_objects OBJECT ${metadata_sources}) target_compile_definitions(metadata_objects PRIVATE ${metadata_compile_definitions}) -target_link_libraries(metadata_objects PRIVATE monoapi eglib_api utils_objects) +target_link_libraries(metadata_objects PRIVATE monoapi eglib_api utils_objects zlib) # note: metadata_objects is an object library, so this doesn't force linking with sgen, # it just adds the relevant include directories - which we need even with Boehm target_link_libraries(metadata_objects PRIVATE sgen_objects) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 00eae821c539ab..db864d05f0512e 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -535,7 +535,7 @@ if(NOT DISABLE_EXECUTABLES) if (HOST_WASM) target_link_libraries(mono-sgen PRIVATE mono-wasm-nosimd) endif() - target_link_libraries(mono-sgen PRIVATE ${OS_LIBS} ${LLVM_LIBS}) + target_link_libraries(mono-sgen PRIVATE ${OS_LIBS} ${LLVM_LIBS} zlib) # musl-libc implements ucontext in a different library on s390x if(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) target_link_libraries(mono-sgen PRIVATE ucontext) diff --git a/src/mono/wasi/runtime/CMakeLists.txt b/src/mono/wasi/runtime/CMakeLists.txt index 1d2a220494779a..ec45f3aa2e488e 100644 --- a/src/mono/wasi/runtime/CMakeLists.txt +++ b/src/mono/wasi/runtime/CMakeLists.txt @@ -27,6 +27,7 @@ target_link_libraries(dotnet ${MONO_ARTIFACTS_DIR}/libmonosgen-2.0.a ${MONO_ARTIFACTS_DIR}/libmono-icall-table.a ${MONO_ARTIFACTS_DIR}/libmono-wasm-${CONFIGURATION_INTERPSIMDTABLES_LIB}.a + ${MONO_ARTIFACTS_DIR}/libz.a ${NATIVE_BIN_DIR}/wasm-bundled-timezones.a ${NATIVE_BIN_DIR}/libSystem.Native.a ${NATIVE_BIN_DIR}/libSystem.Globalization.Native.a From 03de95be051cc9762e4336c971212195a75a33d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Tue, 18 Jun 2024 23:34:38 -0700 Subject: [PATCH 15/39] Fix aot build --- .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets | 2 +- src/native/libs/System.IO.Compression.Native/CMakeLists.txt | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index c0bcb767740d20..301b2baed03d80 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -129,7 +129,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + diff --git a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt index 384747eddc7a2b..47143a2332d242 100644 --- a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt +++ b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt @@ -179,11 +179,14 @@ else () endif () if(STATIC_LIBS_ONLY) - install_static_library(zlib aotsdk nativeaot) install_static_library(System.IO.Compression.Native.Aot aotsdk nativeaot) install_static_library(System.IO.Compression.Native.Aot.GuardCF aotsdk nativeaot) endif() endif () +if(STATIC_LIBS_ONLY) + install_static_library(zlib aotsdk nativeaot) +endif() + install (TARGETS System.IO.Compression.Native-Static DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs) From a1fd8899b2872b560d218b71fef302c291040b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 19 Jun 2024 00:23:45 -0700 Subject: [PATCH 16/39] Add libz.a to PlatformManifestFileEntry --- .../pkg/sfx/Microsoft.NETCore.App/Directory.Build.props | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props index 0de334e7ff2113..70c526efac38cc 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props @@ -277,6 +277,8 @@ + + From ccbdbcae8ddd5f3f740bf66c7bc2ac5f8cbd3a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 19 Jun 2024 00:31:03 -0700 Subject: [PATCH 17/39] Fix mono windows build --- src/mono/mono/metadata/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/metadata/CMakeLists.txt b/src/mono/mono/metadata/CMakeLists.txt index e5c2459ccbacf7..170c89f7270467 100644 --- a/src/mono/mono/metadata/CMakeLists.txt +++ b/src/mono/mono/metadata/CMakeLists.txt @@ -200,7 +200,7 @@ set(metadata_sources "${metadata_platform_sources};${metadata_common_sources};${ if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS) add_library(metadata_objects_shared OBJECT ${metadata_sources}) target_compile_definitions(metadata_objects_shared PRIVATE ${metadata_compile_definitions}) - target_link_libraries(metadata_objects_shared PRIVATE monoapi eglib_api utils_objects_shared) + target_link_libraries(metadata_objects_shared PRIVATE monoapi eglib_api utils_objects_shared zlib) # note: metadata_objects is an object library, so this doesn't force linking with sgen, # it just adds the relevant include directories - which we need even with Boehm target_link_libraries(metadata_objects_shared PRIVATE sgen_objects_shared) From 523577b48df96acfd8d9fc650f5dfda2812dd250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 19 Jun 2024 00:31:51 -0700 Subject: [PATCH 18/39] Replace "-lz" with "libz.a" in apple app builder templates --- .../Templates/CMakeLists-librarymode.txt.template | 3 ++- src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template b/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template index 2b40c6dd1b4efc..41e837e2ca6adf 100644 --- a/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template +++ b/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template @@ -63,10 +63,11 @@ target_link_libraries( "-framework Foundation" "-framework Security" "-framework UIKit" - "-lz" + "libz.a" "-lc++" "-liconv" "-licucore" + "libz.a" %NativeLibrariesToLink% %APP_LINK_LIBRARIES% ) diff --git a/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template b/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template index 614d9a7cf64fbe..d04d2d3593e852 100644 --- a/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template +++ b/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template @@ -72,10 +72,10 @@ target_link_libraries( "-framework Foundation" "-framework Security" "-framework UIKit" - "-lz" "-lc++" "-liconv" "-licucore" + "libz.a" %NativeLibrariesToLink% %APP_LINK_LIBRARIES% ) From aa4cc3448ad8bfcaa995bcc1dead0cd18fcc4ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 19 Jun 2024 11:22:03 -0700 Subject: [PATCH 19/39] Remove dup libz.a --- .../Templates/CMakeLists-librarymode.txt.template | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template b/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template index 41e837e2ca6adf..2bb015a7fea3e0 100644 --- a/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template +++ b/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template @@ -63,7 +63,6 @@ target_link_libraries( "-framework Foundation" "-framework Security" "-framework UIKit" - "libz.a" "-lc++" "-liconv" "-licucore" From a5a756588cbbb90cc61e706d5556e624f20e5f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 19 Jun 2024 11:22:16 -0700 Subject: [PATCH 20/39] Add missing libz.a for AppleBuild.targets --- src/mono/msbuild/apple/build/AppleBuild.targets | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mono/msbuild/apple/build/AppleBuild.targets b/src/mono/msbuild/apple/build/AppleBuild.targets index 343ab6072e83a2..8cc1effd1a6bfb 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.targets +++ b/src/mono/msbuild/apple/build/AppleBuild.targets @@ -76,6 +76,7 @@ <_CommonLinkerArgs Include="-framework Foundation" /> <_CommonLinkerArgs Include="-framework Security" /> <_CommonLinkerArgs Include="-framework UIKit" /> + <_CommonLinkerArgs Include="libz.a" /> From a5d1835cc8d56dbabf4b581c6402306046f8715c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 19 Jun 2024 11:23:34 -0700 Subject: [PATCH 21/39] Replace -lz with libz.a in tasks LibraryBuilder CMakeLists template --- src/tasks/LibraryBuilder/Templates/CMakeLists.txt.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tasks/LibraryBuilder/Templates/CMakeLists.txt.template b/src/tasks/LibraryBuilder/Templates/CMakeLists.txt.template index 51c00ad72a9164..89d987aa570a1d 100644 --- a/src/tasks/LibraryBuilder/Templates/CMakeLists.txt.template +++ b/src/tasks/LibraryBuilder/Templates/CMakeLists.txt.template @@ -44,10 +44,10 @@ elseif(TARGETS_APPLE_MOBILE) "-framework Foundation" "-framework Security" "-framework UIKit" - "-lz" "-lc++" "-licucore" "-liconv" + "libz.a" ) add_definitions(-DHOST_APPLE_MOBILE=1) add_definitions(-fPIC) From 15e4d7a29b49be5383246a361107bea5276bd49b Mon Sep 17 00:00:00 2001 From: carlossanlop <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 19 Jun 2024 19:27:30 -0700 Subject: [PATCH 22/39] AppleBuild.targets should pass libz.a through the Bundle items --- eng/testing/tests.ioslike.targets | 1 + src/mono/msbuild/apple/build/AppleBuild.targets | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/testing/tests.ioslike.targets b/eng/testing/tests.ioslike.targets index dde49575d7ae44..2c6d58574f05f8 100644 --- a/eng/testing/tests.ioslike.targets +++ b/eng/testing/tests.ioslike.targets @@ -214,6 +214,7 @@ + diff --git a/src/mono/msbuild/apple/build/AppleBuild.targets b/src/mono/msbuild/apple/build/AppleBuild.targets index 8cc1effd1a6bfb..343ab6072e83a2 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.targets +++ b/src/mono/msbuild/apple/build/AppleBuild.targets @@ -76,7 +76,6 @@ <_CommonLinkerArgs Include="-framework Foundation" /> <_CommonLinkerArgs Include="-framework Security" /> <_CommonLinkerArgs Include="-framework UIKit" /> - <_CommonLinkerArgs Include="libz.a" /> From 32d4d15dcfcd233689d514ec1661eb8f01b010d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 20 Jun 2024 22:30:35 -0700 Subject: [PATCH 23/39] Use system zlib for mobile. Use this copy of zlib-ng for everything else. --- eng/testing/tests.ioslike.targets | 1 - .../android/build/AndroidBuild.targets | 2 +- .../msbuild/apple/build/AppleBuild.targets | 1 + src/native/external/zlib-ng.cmake | 9 +-- .../CMakeLists.txt | 62 +++++++++++-------- .../extra_libs.cmake | 12 +++- .../CMakeLists-librarymode.txt.template | 2 +- .../Templates/CMakeLists.txt.template | 2 +- .../Templates/CMakeLists.txt.template | 2 +- 9 files changed, 55 insertions(+), 38 deletions(-) diff --git a/eng/testing/tests.ioslike.targets b/eng/testing/tests.ioslike.targets index 2c6d58574f05f8..dde49575d7ae44 100644 --- a/eng/testing/tests.ioslike.targets +++ b/eng/testing/tests.ioslike.targets @@ -214,7 +214,6 @@ - diff --git a/src/mono/msbuild/android/build/AndroidBuild.targets b/src/mono/msbuild/android/build/AndroidBuild.targets index 743084d18cdd5f..917aed88506697 100644 --- a/src/mono/msbuild/android/build/AndroidBuild.targets +++ b/src/mono/msbuild/android/build/AndroidBuild.targets @@ -48,6 +48,7 @@ + <_CommonLinkerArgs Include="-l:libz.so" /> <_CommonLinkerArgs Include="-l:liblog.so" /> <_CommonLinkerArgs Include="-l:libc.so" /> <_CommonLinkerArgs Include="-l:libm.so" /> @@ -210,7 +211,6 @@ - diff --git a/src/mono/msbuild/apple/build/AppleBuild.targets b/src/mono/msbuild/apple/build/AppleBuild.targets index 343ab6072e83a2..35d0f16c35b4b8 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.targets +++ b/src/mono/msbuild/apple/build/AppleBuild.targets @@ -70,6 +70,7 @@ + <_CommonLinkerArgs Include="-lz" /> <_CommonLinkerArgs Include="-lc++" /> <_CommonLinkerArgs Include="-liconv" /> <_CommonLinkerArgs Include="-licucore" /> diff --git a/src/native/external/zlib-ng.cmake b/src/native/external/zlib-ng.cmake index dc2ee1c3acf6d4..3f005eaa54f3d3 100644 --- a/src/native/external/zlib-ng.cmake +++ b/src/native/external/zlib-ng.cmake @@ -15,16 +15,11 @@ add_compile_options($<$:/wd4127>) # warning C4127: c add_compile_options($<$:/wd4242>) # 'function': conversion from 'unsigned int' to 'Pos', possible loss of data, in various deflate_*.c files add_compile_options($<$:/wd4244>) # 'function': conversion from 'unsigned int' to 'Pos', possible loss of data, in various deflate_*.c files -# 'aligned_alloc' is only available on iOS 13.0 or newer and in some cases it is not available on Android, yet it is set by zlib-ng/CMakeLists.txt. -if (CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS OR CLR_CMAKE_TARGET_ANDROID OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) +# 'aligned_alloc' is not available in browser/wasi, yet it is set by zlib-ng/CMakeLists.txt. +if (CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) set(HAVE_ALIGNED_ALLOC FALSE CACHE BOOL "have aligned_alloc" FORCE) endif() -# Workaround: Some SIMD types for ARM are not being found -if (CLR_CMAKE_TARGET_ANDROID) - set(WITH_ARMV6 OFF CACHE BOOL "with armv6" FORCE) -endif() - set(BUILD_SHARED_LIBS OFF) # Shared libraries aren't supported in wasm set(SKIP_INSTALL_ALL ON) FetchContent_MakeAvailable(fetchzlibng) diff --git a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt index 47143a2332d242..7b2b2bb7ecff07 100644 --- a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt +++ b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt @@ -1,16 +1,23 @@ project(System.IO.Compression.Native C) include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake) -include(${CLR_SRC_NATIVE_DIR}/external/zlib-ng.cmake) -add_compile_definitions(ZLIB_COMPAT) +set(IS_ZLIBNG_ENABLED TRUE) +if (CLR_CMAKE_TARGET_ANDROID OR HOST_ANDROID OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) + set(IS_ZLIBNG_ENABLED FALSE) +endif() + +if (IS_ZLIBNG_ENABLED) + include(${CLR_SRC_NATIVE_DIR}/external/zlib-ng.cmake) + add_compile_definitions(ZLIB_COMPAT) +endif() configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/../Common/pal_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/pal_config.h) set(NATIVECOMPRESSION_SOURCES - pal_zlib.c + pal_zlib.c ) if (HOST_WIN32 OR CLR_CMAKE_TARGET_WIN32) @@ -42,10 +49,6 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) set(NATIVE_LIBS_EXTRA) append_extra_compression_libs(NATIVE_LIBS_EXTRA) - if (CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) - set(NATIVECOMPRESSION_SOURCES ${NATIVECOMPRESSION_SOURCES}) - endif() - # Disable implicit fallthrough warning for Zlib and Brotli set(FLAGS -Wno-implicit-fallthrough) @@ -104,17 +107,18 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) STATIC ${NATIVECOMPRESSION_SOURCES} ) - target_link_libraries(System.IO.Compression.Native-Static - PRIVATE - zlibstatic - ) + + if (IS_ZLIBNG_ENABLED) + target_link_libraries(System.IO.Compression.Native-Static + PRIVATE + zlibstatic) + endif() set_target_properties(System.IO.Compression.Native-Static PROPERTIES OUTPUT_NAME System.IO.Compression.Native CLEAN_DIRECT_OUTPUT 1) else () if (GEN_SHARED_LIB) include (GenerateExportHeader) endif () - set(NATIVECOMPRESSION_SOURCES ${NATIVECOMPRESSION_SOURCES}) if (GEN_SHARED_LIB) add_definitions(-DVER_FILEDESCRIPTION_STR="System.IO.Compression.Native") @@ -124,10 +128,11 @@ else () System.IO.Compression.Native.def ${VERSION_FILE_RC_PATH} ) - target_link_libraries(System.IO.Compression.Native - PRIVATE - zlib - ) + if (IS_ZLIBNG_ENABLED) + target_link_libraries(System.IO.Compression.Native + PRIVATE + zlib) + endif() endif () if (NOT GEN_SHARED_LIB AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) @@ -138,20 +143,24 @@ else () STATIC ${NATIVECOMPRESSION_SOURCES} ) + if (IS_ZLIBNG_ENABLED) target_link_libraries(System.IO.Compression.Native-Static PRIVATE - zlibstatic - ) + zlibstatic) + endif() if(STATIC_LIBS_ONLY) add_library(System.IO.Compression.Native.Aot STATIC ${NATIVECOMPRESSION_SOURCES} ) + + if (IS_ZLIBNG_ENABLED) target_link_libraries(System.IO.Compression.Native.Aot PRIVATE - zlibstatic - ) + zlibstatic) + endif() + set_target_properties(System.IO.Compression.Native.Aot PROPERTIES CLR_CONTROL_FLOW_GUARD OFF) set_target_properties(System.IO.Compression.Native.Aot PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) @@ -159,10 +168,13 @@ else () STATIC ${NATIVECOMPRESSION_SOURCES} ) - target_link_libraries(System.IO.Compression.Native.Aot.GuardCF - PRIVATE - zlibstatic - ) + + if (IS_ZLIBNG_ENABLED) + target_link_libraries(System.IO.Compression.Native.Aot.GuardCF + PRIVATE + zlibstatic) + endif() + set_target_properties(System.IO.Compression.Native.Aot.GuardCF PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) endif() @@ -185,7 +197,7 @@ else () endif () -if(STATIC_LIBS_ONLY) +if(IS_ZLIBNG_ENABLED AND STATIC_LIBS_ONLY) install_static_library(zlib aotsdk nativeaot) endif() diff --git a/src/native/libs/System.IO.Compression.Native/extra_libs.cmake b/src/native/libs/System.IO.Compression.Native/extra_libs.cmake index d5a6042a8981d6..e29dd64bde494e 100644 --- a/src/native/libs/System.IO.Compression.Native/extra_libs.cmake +++ b/src/native/libs/System.IO.Compression.Native/extra_libs.cmake @@ -1,8 +1,18 @@ macro(append_extra_compression_libs NativeLibsExtra) - list(APPEND ${NativeLibsExtra} zlib) + if (CLR_CMAKE_TARGET_ANDROID OR HOST_ANDROID) + # need special case here since we want to link against libz.so but find_package() would resolve libz.a + set(ZLIB_LIBRARIES z) + elseif (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) + find_package(ZLIB REQUIRED) + set(ZLIB_LIBRARIES ${ZLIB_LIBRARIES} m) + else() + list(APPEND ${NativeLibsExtra} zlib) + endif () + if (CLR_CMAKE_USE_SYSTEM_BROTLI) find_library(BROTLIDEC brotlidec REQUIRED) find_library(BROTLIENC brotlienc REQUIRED) + list(APPEND ${NativeLibsExtra} ${BROTLIDEC} ${BROTLIENC}) endif () endmacro() diff --git a/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template b/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template index 2bb015a7fea3e0..2b40c6dd1b4efc 100644 --- a/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template +++ b/src/tasks/AppleAppBuilder/Templates/CMakeLists-librarymode.txt.template @@ -63,10 +63,10 @@ target_link_libraries( "-framework Foundation" "-framework Security" "-framework UIKit" + "-lz" "-lc++" "-liconv" "-licucore" - "libz.a" %NativeLibrariesToLink% %APP_LINK_LIBRARIES% ) diff --git a/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template b/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template index d04d2d3593e852..614d9a7cf64fbe 100644 --- a/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template +++ b/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template @@ -72,10 +72,10 @@ target_link_libraries( "-framework Foundation" "-framework Security" "-framework UIKit" + "-lz" "-lc++" "-liconv" "-licucore" - "libz.a" %NativeLibrariesToLink% %APP_LINK_LIBRARIES% ) diff --git a/src/tasks/LibraryBuilder/Templates/CMakeLists.txt.template b/src/tasks/LibraryBuilder/Templates/CMakeLists.txt.template index 89d987aa570a1d..51c00ad72a9164 100644 --- a/src/tasks/LibraryBuilder/Templates/CMakeLists.txt.template +++ b/src/tasks/LibraryBuilder/Templates/CMakeLists.txt.template @@ -44,10 +44,10 @@ elseif(TARGETS_APPLE_MOBILE) "-framework Foundation" "-framework Security" "-framework UIKit" + "-lz" "-lc++" "-licucore" "-liconv" - "libz.a" ) add_definitions(-DHOST_APPLE_MOBILE=1) add_definitions(-fPIC) From c0e7fa548ecf764349eb2cb1b1d3444d99c51fcf Mon Sep 17 00:00:00 2001 From: carlossanlop <1175054+carlossanlop@users.noreply.github.com> Date: Mon, 24 Jun 2024 16:25:51 -0700 Subject: [PATCH 24/39] Split build for mobile --- Directory.Build.props | 1 + eng/native/configurecompiler.cmake | 5 ++ eng/native/configureplatform.cmake | 6 +++ .../Microsoft.NETCore.Native.Unix.targets | 3 +- src/mono/CMakeLists.txt | 21 ++++++++- src/mono/mono/eventpipe/test/CMakeLists.txt | 11 ++++- src/mono/mono/metadata/CMakeLists.txt | 18 +++++++- src/mono/mono/metadata/debug-mono-ppdb.c | 2 +- src/mono/mono/mini/CMakeLists.txt | 32 +++++++++++-- src/mono/mono/profiler/CMakeLists.txt | 6 ++- src/mono/mono/profiler/log.c | 6 ++- src/mono/mono/profiler/mprof-report.c | 6 ++- .../msbuild/apple/build/AppleBuild.targets | 2 +- .../CMakeLists.txt | 46 +++++++------------ .../extra_libs.cmake | 13 ++++-- .../zlib_allocator_unix.c | 4 +- .../zlib_allocator_win.c | 4 +- 17 files changed, 135 insertions(+), 51 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 3e494e19c3d9e5..c8105e8d424b62 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -324,6 +324,7 @@ true ClrFullNativeBuild;ClrRuntimeSubset;ClrJitSubset;ClrPalTestsSubset;ClrAllJitsSubset;ClrILToolsSubset;ClrNativeAotSubset;ClrSpmiSubset;ClrCrossComponentsSubset;ClrDebugSubset;HostArchitecture;PgoInstrument;NativeOptimizationDataSupported;CMakeArgs;CxxStandardLibrary;CxxStandardLibraryStatic;CxxAbiLibrary + true diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index aedc4825273003..a124523bb1561b 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -1034,3 +1034,8 @@ elseif (NOT CLR_CMAKE_HOST_BROWSER AND NOT CLR_CMAKE_HOST_WASI) enable_language(ASM) endif(CLR_CMAKE_HOST_WIN32) + +if (INTERNAL_ZLIB_NG) + add_definitions(-DINTERNAL_ZLIB_NG) + add_definitions(-DZLIB_COMPAT) +endif() \ No newline at end of file diff --git a/eng/native/configureplatform.cmake b/eng/native/configureplatform.cmake index 20851f8617423d..b9905b02f76ba6 100644 --- a/eng/native/configureplatform.cmake +++ b/eng/native/configureplatform.cmake @@ -500,3 +500,9 @@ if(LOWERCASE_CMAKE_BUILD_TYPE STREQUAL debug) string(REPLACE "-D_FORTIFY_SOURCE=2 " "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REPLACE "-D_FORTIFY_SOURCE=2 " "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") endif() + +if (NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) + # Our zlib-ng copy should only be used in non-mobile platforms only. + # In mobile platforms we should use the zlib package provided by the system. + set(INTERNAL_ZLIB_NG 1) +endif() diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 301b2baed03d80..7269b4a6a4dd29 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -129,7 +129,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + @@ -189,6 +189,7 @@ The .NET Foundation licenses this file to you under the MIT license. + diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index 6c13615187f112..ff5dca68fa2887 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -508,9 +508,21 @@ if ((HOST_MACCAT AND HOST_ARM64) OR (TARGET_MACCAT AND TARGET_ARM64)) set(TARGET_APPLE_MOBILE 1) endif() +if (INTERNAL_ZLIB_NG) + add_definitions(-DINTERNAL_ZLIB_NG) + add_definitions(-DZLIB_COMPAT) +endif() + # Decide if we need zlib-ng. if(NOT DISABLE_EMBEDDED_PDB OR NOT DISABLE_LOG_PROFILER_GZ) + if (INTERNAL_ZLIB_NG) include(${CLR_SRC_NATIVE_DIR}/external/zlib-ng.cmake) + else() + # if we're not on a platform where we use the in-tree zlib, require system zlib + include(${CLR_SRC_NATIVE_DIR}/libs/System.IO.Compression.Native/extra_libs.cmake) + set(Z_LIBS) + append_extra_compression_libs(Z_LIBS) + endif() endif() ###################################### @@ -653,12 +665,17 @@ if(LLVM_PREFIX) endif() set(llvm_includedir "${LLVM_PREFIX}/include") + set(llvm_system_libs "") if(HOST_LINUX) # llvm-config --system-libs - set(llvm_system_libs ${MONO_cxx_lib} "-lrt" "-ldl" "-lpthread" "-lm") + list(APPEND llvm_system_libs ${MONO_cxx_lib} "-lrt" "-ldl" "-lpthread" "-lm") elseif(HOST_OSX) # llvm-config --system-libs - set(llvm_system_libs "-lm") + list(APPEND llvm_system_libs "-lm") + endif() + + if (NOT INTERNAL_ZLIB_NG AND (HOST_LINUX OR HOST_OSX)) + list(APPEND llvm_system_libs "-lz") endif() # llvm-config --libs analysis core bitwriter mcjit orcjit diff --git a/src/mono/mono/eventpipe/test/CMakeLists.txt b/src/mono/mono/eventpipe/test/CMakeLists.txt index 11f37a3720af7b..08fd7209beed11 100644 --- a/src/mono/mono/eventpipe/test/CMakeLists.txt +++ b/src/mono/mono/eventpipe/test/CMakeLists.txt @@ -39,7 +39,16 @@ if(ENABLE_PERFTRACING) set(CMAKE_SKIP_RPATH 1) add_executable(ep-test ${EVENTPIPE_TEST_SOURCES} ${EVENTPIPE_TEST_HEADERS}) target_sources(ep-test PRIVATE "${mono-components-objects}") - target_link_libraries(ep-test PRIVATE eglib_api monosgen-static ${OS_LIBS} ${LLVM_LIBS} zlib monoapi) + + set(EPTEST_LINKABLE_LIBS "") + list(APPEND EPTEST_LINKABLE_LIBS eglib_api monosgen-static ${OS_LIBS} ${LLVM_LIBS} monoapi) + if (INTERNAL_ZLIB_NG) + list(APPEND EPTEST_LINKABLE_LIBS ${EPTEST_LINKABLE_LIBS} zlib) + else() + list(APPEND EPTEST_LINKABLE_LIBS ${EPTEST_LINKABLE_LIBS} ${Z_LIBS}) + endif() + target_link_libraries(ep-test PRIVATE ${EPTEST_LINKABLE_LIBS}) + install_with_stripped_symbols(ep-test TARGETS bin) else(ENABLE_EVENTPIPE_TEST AND STATIC_COMPONENTS AND (NOT DISABLE_COMPONENTS) AND (NOT DISABLE_LIBS) AND (NOT DISABLE_EXECUTABLES)) message(VERBOSE "Skip building native EventPipe library test runner.") diff --git a/src/mono/mono/metadata/CMakeLists.txt b/src/mono/mono/metadata/CMakeLists.txt index 170c89f7270467..5873805cbca91f 100644 --- a/src/mono/mono/metadata/CMakeLists.txt +++ b/src/mono/mono/metadata/CMakeLists.txt @@ -200,7 +200,14 @@ set(metadata_sources "${metadata_platform_sources};${metadata_common_sources};${ if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS) add_library(metadata_objects_shared OBJECT ${metadata_sources}) target_compile_definitions(metadata_objects_shared PRIVATE ${metadata_compile_definitions}) - target_link_libraries(metadata_objects_shared PRIVATE monoapi eglib_api utils_objects_shared zlib) + + set(METADATAOBJECTSSHARED_LINKABLE_LIBS "") + list(APPEND METADATAOBJECTSSHARED_LINKABLE_LIBS monoapi eglib_api utils_objects_shared) + if (INTERNAL_ZLIB_NG) + list(APPEND METADATAOBJECTSSHARED_LINKABLE_LIBS zlib) + endif() + target_link_libraries(metadata_objects_shared PRIVATE ${METADATAOBJECTSSHARED_LINKABLE_LIBS}) + # note: metadata_objects is an object library, so this doesn't force linking with sgen, # it just adds the relevant include directories - which we need even with Boehm target_link_libraries(metadata_objects_shared PRIVATE sgen_objects_shared) @@ -212,7 +219,14 @@ endif() add_library(metadata_objects OBJECT ${metadata_sources}) target_compile_definitions(metadata_objects PRIVATE ${metadata_compile_definitions}) -target_link_libraries(metadata_objects PRIVATE monoapi eglib_api utils_objects zlib) + +set(METADATAOBJECTS_LINKABLE_LIBS "") +list(APPEND METADATAOBJECTS_LINKABLE_LIBS monoapi eglib_api utils_objects) +if (INTERNAL_ZLIB_NG) + list(APPEND METADATAOBJECTS_LINKABLE_LIBS zlib) +endif() +target_link_libraries(metadata_objects PRIVATE ${METADATAOBJECTS_LINKABLE_LIBS}) + # note: metadata_objects is an object library, so this doesn't force linking with sgen, # it just adds the relevant include directories - which we need even with Boehm target_link_libraries(metadata_objects PRIVATE sgen_objects) diff --git a/src/mono/mono/metadata/debug-mono-ppdb.c b/src/mono/mono/metadata/debug-mono-ppdb.c index be4cb122e78389..3ed40e9243dad3 100644 --- a/src/mono/mono/metadata/debug-mono-ppdb.c +++ b/src/mono/mono/metadata/debug-mono-ppdb.c @@ -31,7 +31,7 @@ #ifndef DISABLE_EMBEDDED_PDB #include -#endif +#endif // DISABLE_EMBEDDED_PDB #include "debug-mono-ppdb.h" diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index db864d05f0512e..cb45af71004f93 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -366,11 +366,16 @@ if(NOT DISABLE_SHARED_LIBS) # to avoid a conflict we rename the import library with the .import.lib suffix set_target_properties(monosgen-shared PROPERTIES IMPORT_SUFFIX ".import.lib") endif() - if(CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) - target_link_libraries(monosgen-shared PRIVATE ${OS_LIBS} ${LLVM_LIBS} zlib) + + set(MONOSGENSHARED_LINKABLE_LIBS "") + list(APPEND MONOSGENSHARED_LINKABLE_LIBS ${OS_LIBS} ${LLVM_LIBS}) + if (INTERNAL_ZLIB_NG) + list(APPEND MONOSGENSHARED_LINKABLE_LIBS zlib) else() - target_link_libraries(monosgen-shared PRIVATE ${OS_LIBS} ${LLVM_LIBS} zlib) + list(APPEND MONOSGENSHARED_LINKABLE_LIBS ${Z_LIBS}) endif() + target_link_libraries(monosgen-shared PRIVATE ${MONOSGENSHARED_LINKABLE_LIBS}) + if(TARGET_DARWIN) set_property(TARGET monosgen-shared APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-compatibility_version -Wl,2.0 -Wl,-current_version -Wl,2.0") endif() @@ -415,7 +420,15 @@ if(NOT DISABLE_SHARED_LIBS) add_library(${frameworkconfig} SHARED $) target_compile_definitions(${frameworkconfig} PRIVATE -DMONO_DLL_EXPORT) target_link_libraries(${frameworkconfig} PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers zlib) - target_link_libraries(${frameworkconfig} PRIVATE ${OS_LIBS} ${LLVM_LIBS} zlib) + + set(FRAMEWORKCONFIG_LINKABLE_LIBS "") + list(APPEND FRAMEWORKCONFIG_LINKABLE_LIBS ${OS_LIBS} ${LLVM_LIBS}) + if (INTERNAL_ZLIB_NG) + list(APPEND FRAMEWORKCONFIG_LINKABLE_LIBS zlib) + else() + list(APPEND FRAMEWORKCONFIG_LINKABLE_LIBS ${Z_LIBS}) + endif() + target_link_libraries(${frameworkconfig} PRIVATE ${FRAMEWORKCONFIG_LINKABLE_LIBS}) set_property(TARGET ${frameworkconfig} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-compatibility_version -Wl,2.0 -Wl,-current_version -Wl,2.0") string(REPLACE "*" ";" componentsobjects-whitespace "${componentsobjects}") @@ -535,7 +548,16 @@ if(NOT DISABLE_EXECUTABLES) if (HOST_WASM) target_link_libraries(mono-sgen PRIVATE mono-wasm-nosimd) endif() - target_link_libraries(mono-sgen PRIVATE ${OS_LIBS} ${LLVM_LIBS} zlib) + + set(MONOSGEN_LINKABLE_LIBS "") + list(APPEND MONOSGEN_LINKABLE_LIBS ${OS_LIBS} ${LLVM_LIBS}) + if (INTERNAL_ZLIB_NG) + list(APPEND MONOSGEN_LINKABLE_LIBS zlib) + else() + list(APPEND MONOSGEN_LINKABLE_LIBS ${Z_LIBS}) + endif() + target_link_libraries(mono-sgen PRIVATE ${MONOSGEN_LINKABLE_LIBS}) + # musl-libc implements ucontext in a different library on s390x if(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) target_link_libraries(mono-sgen PRIVATE ucontext) diff --git a/src/mono/mono/profiler/CMakeLists.txt b/src/mono/mono/profiler/CMakeLists.txt index fc18e2f7e3665b..106e0b154cfd64 100644 --- a/src/mono/mono/profiler/CMakeLists.txt +++ b/src/mono/mono/profiler/CMakeLists.txt @@ -26,7 +26,11 @@ if(NOT DISABLE_LIBS) install(TARGETS mono-profiler-log-static LIBRARY) if(NOT DISABLE_LOG_PROFILER_GZ) - target_link_libraries(mono-profiler-log PRIVATE zlib) + if (INTERNAL_ZLIB_NG) + target_link_libraries(mono-profiler-log PRIVATE zlib) + else() + target_link_libraries(mono-profiler-log PRIVATE ${Z_LIBS}) + endif() endif() endif() diff --git a/src/mono/mono/profiler/log.c b/src/mono/mono/profiler/log.c index c02058402aeafc..95f411dfa0dab0 100644 --- a/src/mono/mono/profiler/log.c +++ b/src/mono/mono/profiler/log.c @@ -72,8 +72,12 @@ #include #endif #ifndef DISABLE_LOG_PROFILER_GZ +#ifdef INTERNAL_ZLIB_NG +#include +#else #include -#endif +#endif // INTERNAL_ZLIB_NG +#endif // DISABLE_LOG_PROFILER_GZ #ifdef HOST_WIN32 #include diff --git a/src/mono/mono/profiler/mprof-report.c b/src/mono/mono/profiler/mprof-report.c index c0db93ea0ca7cd..05b49621d4648d 100644 --- a/src/mono/mono/profiler/mprof-report.c +++ b/src/mono/mono/profiler/mprof-report.c @@ -23,8 +23,12 @@ #endif #include #ifndef DISABLE_LOG_PROFILER_GZ +#ifdef INTERNAL_ZLIB_NG +#include +#else #include -#endif +#endif // INTERNAL_ZLIB_NG +#endif // DISABLE_LOG_PROFILER_GZ #include #include #include diff --git a/src/mono/msbuild/apple/build/AppleBuild.targets b/src/mono/msbuild/apple/build/AppleBuild.targets index 35d0f16c35b4b8..99822cd79be46a 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.targets +++ b/src/mono/msbuild/apple/build/AppleBuild.targets @@ -70,7 +70,7 @@ - <_CommonLinkerArgs Include="-lz" /> + <_CommonLinkerArgs Include="-lz" Condition="'$(UseSystemZlib)' == 'true'" /> <_CommonLinkerArgs Include="-lc++" /> <_CommonLinkerArgs Include="-liconv" /> <_CommonLinkerArgs Include="-licucore" /> diff --git a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt index 7b2b2bb7ecff07..db6ec8c9a97bd0 100644 --- a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt +++ b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt @@ -2,14 +2,10 @@ project(System.IO.Compression.Native C) include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake) -set(IS_ZLIBNG_ENABLED TRUE) -if (CLR_CMAKE_TARGET_ANDROID OR HOST_ANDROID OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) - set(IS_ZLIBNG_ENABLED FALSE) -endif() - -if (IS_ZLIBNG_ENABLED) +if (INTERNAL_ZLIB_NG) include(${CLR_SRC_NATIVE_DIR}/external/zlib-ng.cmake) - add_compile_definitions(ZLIB_COMPAT) + add_definitions(-DINTERNAL_ZLIB_NG) + add_definitions(-DZLIB_COMPAT) endif() configure_file( @@ -108,18 +104,16 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) ${NATIVECOMPRESSION_SOURCES} ) - if (IS_ZLIBNG_ENABLED) - target_link_libraries(System.IO.Compression.Native-Static - PRIVATE - zlibstatic) + if (INTERNAL_ZLIB_NG) + target_link_libraries(System.IO.Compression.Native-Static PRIVATE zlibstatic) endif() + set_target_properties(System.IO.Compression.Native-Static PROPERTIES OUTPUT_NAME System.IO.Compression.Native CLEAN_DIRECT_OUTPUT 1) else () if (GEN_SHARED_LIB) include (GenerateExportHeader) endif () - if (GEN_SHARED_LIB) add_definitions(-DVER_FILEDESCRIPTION_STR="System.IO.Compression.Native") add_library(System.IO.Compression.Native @@ -128,10 +122,9 @@ else () System.IO.Compression.Native.def ${VERSION_FILE_RC_PATH} ) - if (IS_ZLIBNG_ENABLED) - target_link_libraries(System.IO.Compression.Native - PRIVATE - zlib) + + if (INTERNAL_ZLIB_NG) + target_link_libraries(System.IO.Compression.Native PRIVATE zlib) endif() endif () @@ -143,10 +136,9 @@ else () STATIC ${NATIVECOMPRESSION_SOURCES} ) - if (IS_ZLIBNG_ENABLED) - target_link_libraries(System.IO.Compression.Native-Static - PRIVATE - zlibstatic) + + if (INTERNAL_ZLIB_NG) + target_link_libraries(System.IO.Compression.Native-Static PRIVATE zlibstatic) endif() if(STATIC_LIBS_ONLY) @@ -155,10 +147,8 @@ else () ${NATIVECOMPRESSION_SOURCES} ) - if (IS_ZLIBNG_ENABLED) - target_link_libraries(System.IO.Compression.Native.Aot - PRIVATE - zlibstatic) + if (INTERNAL_ZLIB_NG) + target_link_libraries(System.IO.Compression.Native.Aot PRIVATE zlibstatic) endif() set_target_properties(System.IO.Compression.Native.Aot PROPERTIES CLR_CONTROL_FLOW_GUARD OFF) @@ -169,10 +159,8 @@ else () ${NATIVECOMPRESSION_SOURCES} ) - if (IS_ZLIBNG_ENABLED) - target_link_libraries(System.IO.Compression.Native.Aot.GuardCF - PRIVATE - zlibstatic) + if (INTERNAL_ZLIB_NG) + target_link_libraries(System.IO.Compression.Native.Aot.GuardCF PRIVATE zlibstatic) endif() set_target_properties(System.IO.Compression.Native.Aot.GuardCF PROPERTIES INTERPROCEDURAL_OPTIMIZATION OFF) @@ -197,7 +185,7 @@ else () endif () -if(IS_ZLIBNG_ENABLED AND STATIC_LIBS_ONLY) +if(INTERNAL_ZLIB_NG AND STATIC_LIBS_ONLY) install_static_library(zlib aotsdk nativeaot) endif() diff --git a/src/native/libs/System.IO.Compression.Native/extra_libs.cmake b/src/native/libs/System.IO.Compression.Native/extra_libs.cmake index e29dd64bde494e..34db178303ceb4 100644 --- a/src/native/libs/System.IO.Compression.Native/extra_libs.cmake +++ b/src/native/libs/System.IO.Compression.Native/extra_libs.cmake @@ -1,13 +1,18 @@ macro(append_extra_compression_libs NativeLibsExtra) - if (CLR_CMAKE_TARGET_ANDROID OR HOST_ANDROID) + set(ZLIB_LIBRARIES "") + # TODO: remove the mono-style HOST_ variable checks once Mono is using eng/native/configureplatform.cmake to define the CLR_CMAKE_TARGET_ defines + if (CLR_CMAKE_TARGET_BROWSER OR HOST_BROWSER OR CLR_CMAKE_TARGET_WASI OR HOST_WASI) + # nothing special to link + elseif (CLR_CMAKE_TARGET_ANDROID OR HOST_ANDROID) # need special case here since we want to link against libz.so but find_package() would resolve libz.a - set(ZLIB_LIBRARIES z) + list(APPEND ZLIB_LIBRARIES z) elseif (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) find_package(ZLIB REQUIRED) - set(ZLIB_LIBRARIES ${ZLIB_LIBRARIES} m) + list(APPEND ZLIB_LIBRARIES m) else() - list(APPEND ${NativeLibsExtra} zlib) + list(APPEND ZLIB_LIBRARIES zlib) endif () + list(APPEND ${NativeLibsExtra} ${ZLIB_LIBRARIES}) if (CLR_CMAKE_USE_SYSTEM_BROTLI) find_library(BROTLIDEC brotlidec REQUIRED) diff --git a/src/native/libs/System.IO.Compression.Native/zlib_allocator_unix.c b/src/native/libs/System.IO.Compression.Native/zlib_allocator_unix.c index 52c0cfeb83a2a2..b2c898f70a4e36 100644 --- a/src/native/libs/System.IO.Compression.Native/zlib_allocator_unix.c +++ b/src/native/libs/System.IO.Compression.Native/zlib_allocator_unix.c @@ -3,7 +3,9 @@ #include #include -#include +#include +#include +#include #include /* A custom allocator for zlib that provides some defense-in-depth over standard malloc / free. diff --git a/src/native/libs/System.IO.Compression.Native/zlib_allocator_win.c b/src/native/libs/System.IO.Compression.Native/zlib_allocator_win.c index b89d5d9b298d14..fefba550c16ed5 100644 --- a/src/native/libs/System.IO.Compression.Native/zlib_allocator_win.c +++ b/src/native/libs/System.IO.Compression.Native/zlib_allocator_win.c @@ -7,7 +7,9 @@ #include #include /* _ASSERTE */ -#include +#include +#include +#include #include /* A custom allocator for zlib that provides some defense-in-depth over standard malloc / free. From e840a5d1d5efd4b39afa00de3a9e29d7294e35e3 Mon Sep 17 00:00:00 2001 From: carlossanlop <1175054+carlossanlop@users.noreply.github.com> Date: Mon, 24 Jun 2024 22:30:20 -0700 Subject: [PATCH 25/39] Redefine UseSystemZlib property for NativeAOT --- .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 7269b4a6a4dd29..7b25caf6d51fef 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -24,6 +24,7 @@ The .NET Foundation licenses this file to you under the MIT license. lld bfd 1572864 + true From 07b9c984003cf02eac2865d3104e0a27c8a8b4a9 Mon Sep 17 00:00:00 2001 From: carlossanlop <1175054+carlossanlop@users.noreply.github.com> Date: Tue, 25 Jun 2024 14:49:49 -0700 Subject: [PATCH 26/39] Define UseSystemZlib in AppleBuild.targets again --- src/mono/msbuild/apple/build/AppleBuild.targets | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mono/msbuild/apple/build/AppleBuild.targets b/src/mono/msbuild/apple/build/AppleBuild.targets index 99822cd79be46a..bec6aac5643e83 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.targets +++ b/src/mono/msbuild/apple/build/AppleBuild.targets @@ -6,6 +6,7 @@ false <_ProcessRuntimeComponentsForLibraryMode Condition="'$(_IsLibraryMode)' == 'true' and '$(UseNativeAOTRuntime)' != 'true'">_ProcessRuntimeComponentsForLibraryMode false + true Date: Thu, 27 Jun 2024 11:56:09 -0700 Subject: [PATCH 27/39] Use apple pre-existing property for native.unix.targets. --- .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 7b25caf6d51fef..3295208f1b0a6a 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -24,7 +24,7 @@ The .NET Foundation licenses this file to you under the MIT license. lld bfd 1572864 - true + true From 6837be2fa026cc349eba702271da15ea375c984c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 27 Jun 2024 11:56:24 -0700 Subject: [PATCH 28/39] Use directly in log.c and mprof-report.c --- src/mono/mono/profiler/log.c | 4 ---- src/mono/mono/profiler/mprof-report.c | 4 ---- 2 files changed, 8 deletions(-) diff --git a/src/mono/mono/profiler/log.c b/src/mono/mono/profiler/log.c index 95f411dfa0dab0..abe5f3f479f578 100644 --- a/src/mono/mono/profiler/log.c +++ b/src/mono/mono/profiler/log.c @@ -72,11 +72,7 @@ #include #endif #ifndef DISABLE_LOG_PROFILER_GZ -#ifdef INTERNAL_ZLIB_NG -#include -#else #include -#endif // INTERNAL_ZLIB_NG #endif // DISABLE_LOG_PROFILER_GZ #ifdef HOST_WIN32 diff --git a/src/mono/mono/profiler/mprof-report.c b/src/mono/mono/profiler/mprof-report.c index 05b49621d4648d..5e2cc5ad7a20e1 100644 --- a/src/mono/mono/profiler/mprof-report.c +++ b/src/mono/mono/profiler/mprof-report.c @@ -23,11 +23,7 @@ #endif #include #ifndef DISABLE_LOG_PROFILER_GZ -#ifdef INTERNAL_ZLIB_NG -#include -#else #include -#endif // INTERNAL_ZLIB_NG #endif // DISABLE_LOG_PROFILER_GZ #include #include From 1643a1f5ca767165a0932db82174ee221251a05f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 27 Jun 2024 12:51:57 -0700 Subject: [PATCH 29/39] Use Exists to condfition UseSystemZlib --- .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 3295208f1b0a6a..2a1e8681550af4 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -24,7 +24,7 @@ The .NET Foundation licenses this file to you under the MIT license. lld bfd 1572864 - true + true From a6d84cc83ff899b22df6bd862c74b420af12804c Mon Sep 17 00:00:00 2001 From: carlossanlop <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:05:18 -0700 Subject: [PATCH 30/39] MIssing single quotes --- .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 2a1e8681550af4..3ff044e94d9d2a 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -24,7 +24,7 @@ The .NET Foundation licenses this file to you under the MIT license. lld bfd 1572864 - true + true From 9c1734928b46c3434835c00293bc8cee930385b5 Mon Sep 17 00:00:00 2001 From: carlossanlop <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:32:20 -0700 Subject: [PATCH 31/39] tabs->spaces --- src/native/libs/System.IO.Compression.Native/pal_zlib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/native/libs/System.IO.Compression.Native/pal_zlib.c b/src/native/libs/System.IO.Compression.Native/pal_zlib.c index c814e927d83d0a..87b7043ea20ffd 100644 --- a/src/native/libs/System.IO.Compression.Native/pal_zlib.c +++ b/src/native/libs/System.IO.Compression.Native/pal_zlib.c @@ -40,8 +40,8 @@ static int32_t Init(PAL_ZStream* stream) { z_stream* zStream = (z_stream*)calloc(1, sizeof(z_stream)); - zStream->zalloc = z_custom_calloc; - zStream->zfree = z_custom_cfree; + zStream->zalloc = z_custom_calloc; + zStream->zfree = z_custom_cfree; stream->internalState = zStream; From 5399b6f39cf4bc272f892c421e88daa48e2001b6 Mon Sep 17 00:00:00 2001 From: carlossanlop <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:42:05 -0700 Subject: [PATCH 32/39] Remove FUNCTIONEXPORT --- .../libs/System.IO.Compression.Native/zlib_allocator.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/native/libs/System.IO.Compression.Native/zlib_allocator.h b/src/native/libs/System.IO.Compression.Native/zlib_allocator.h index f174f5f3472b53..01a32d2c73e7cb 100644 --- a/src/native/libs/System.IO.Compression.Native/zlib_allocator.h +++ b/src/native/libs/System.IO.Compression.Native/zlib_allocator.h @@ -4,16 +4,14 @@ #ifdef _WIN32 #include #include - #define FUNCTIONEXPORT #define FUNCTIONCALLINGCONVENTION WINAPI #else #include "pal_types.h" #include "pal_compiler.h" - #define FUNCTIONEXPORT PALEXPORT #define FUNCTIONCALLINGCONVENTION #endif #include // voidpf -FUNCTIONEXPORT voidpf FUNCTIONCALLINGCONVENTION z_custom_calloc(voidpf opaque, unsigned items, unsigned size); +voidpf FUNCTIONCALLINGCONVENTION z_custom_calloc(voidpf opaque, unsigned items, unsigned size); -FUNCTIONEXPORT void FUNCTIONCALLINGCONVENTION z_custom_cfree(voidpf opaque, voidpf ptr); \ No newline at end of file +void FUNCTIONCALLINGCONVENTION z_custom_cfree(voidpf opaque, voidpf ptr); \ No newline at end of file From 24ebabaaa228c280e3d2f52a69266a9ca47f78c0 Mon Sep 17 00:00:00 2001 From: carlossanlop <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:42:26 -0700 Subject: [PATCH 33/39] Fix build failure in mobile due to recently added unconditioned zlib linked library --- src/mono/mono/mini/CMakeLists.txt | 55 +++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index cb45af71004f93..1c3e5197b8f2db 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -355,10 +355,18 @@ if(NOT DISABLE_SHARED_LIBS) if(MONO_SET_RPATH_ORIGIN) set_target_properties(monosgen-shared PROPERTIES INSTALL_RPATH "$ORIGIN") endif() + + set(MONOSGENSHARED_LINKABLE_LIBS "") + list(APPEND MONOSGENSHARED_LINKABLE_LIBS monoapi eglib_objects dn-containers) + if (INTERNAL_ZLIB_NG) + list(APPEND MONOSGENSHARED_LINKABLE_LIBS zlib) + endif() if(HOST_WIN32) - target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects_shared sgen_objects_shared metadata_objects_shared dn-containers zlib) + list(APPEND MONOSGENSHARED_LINKABLE_LIBS utils_objects_shared sgen_objects_shared metadata_objects_shared) + target_link_libraries(monosgen-shared PRIVATE ${MONOSGENSHARED_LINKABLE_LIBS}) else() - target_link_libraries(monosgen-shared PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers zlib) + list(APPEND MONOSGENSHARED_LINKABLE_LIBS utils_objects sgen_objects metadata_objects) + target_link_libraries(monosgen-shared PRIVATE monoapi ${MONOSGENSHARED_LINKABLE_LIBS}) endif() target_include_directories (monosgen-shared PRIVATE monoapi) if(TARGET_WIN32) @@ -367,14 +375,14 @@ if(NOT DISABLE_SHARED_LIBS) set_target_properties(monosgen-shared PROPERTIES IMPORT_SUFFIX ".import.lib") endif() - set(MONOSGENSHARED_LINKABLE_LIBS "") - list(APPEND MONOSGENSHARED_LINKABLE_LIBS ${OS_LIBS} ${LLVM_LIBS}) + set(MONOSGENSHARED_LINKABLE_EXTRALIBS "") + list(APPEND MONOSGENSHARED_LINKABLE_EXTRALIBS ${OS_LIBS} ${LLVM_LIBS}) if (INTERNAL_ZLIB_NG) - list(APPEND MONOSGENSHARED_LINKABLE_LIBS zlib) + list(APPEND MONOSGENSHARED_LINKABLE_EXTRALIBS zlib) else() - list(APPEND MONOSGENSHARED_LINKABLE_LIBS ${Z_LIBS}) + list(APPEND MONOSGENSHARED_LINKABLE_EXTRALIBS ${Z_LIBS}) endif() - target_link_libraries(monosgen-shared PRIVATE ${MONOSGENSHARED_LINKABLE_LIBS}) + target_link_libraries(monosgen-shared PRIVATE ${MONOSGENSHARED_LINKABLE_EXTRALIBS}) if(TARGET_DARWIN) set_property(TARGET monosgen-shared APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-compatibility_version -Wl,2.0 -Wl,-current_version -Wl,2.0") @@ -419,17 +427,23 @@ if(NOT DISABLE_SHARED_LIBS) endif() add_library(${frameworkconfig} SHARED $) target_compile_definitions(${frameworkconfig} PRIVATE -DMONO_DLL_EXPORT) - target_link_libraries(${frameworkconfig} PRIVATE monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers zlib) set(FRAMEWORKCONFIG_LINKABLE_LIBS "") - list(APPEND FRAMEWORKCONFIG_LINKABLE_LIBS ${OS_LIBS} ${LLVM_LIBS}) + list(APPEND FRAMEWORKCONFIG_LINKABLE_LIBS monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers) if (INTERNAL_ZLIB_NG) list(APPEND FRAMEWORKCONFIG_LINKABLE_LIBS zlib) - else() - list(APPEND FRAMEWORKCONFIG_LINKABLE_LIBS ${Z_LIBS}) endif() target_link_libraries(${frameworkconfig} PRIVATE ${FRAMEWORKCONFIG_LINKABLE_LIBS}) + set(FRAMEWORKCONFIG_LINKABLE_EXTRALIBS "") + list(APPEND FRAMEWORKCONFIG_LINKABLE_EXTRALIBS ${OS_LIBS} ${LLVM_LIBS}) + if (INTERNAL_ZLIB_NG) + list(APPEND FRAMEWORKCONFIG_LINKABLE_EXTRALIBS zlib) + else() + list(APPEND FRAMEWORKCONFIG_LINKABLE_EXTRALIBS ${Z_LIBS}) + endif() + target_link_libraries(${frameworkconfig} PRIVATE ${FRAMEWORKCONFIG_LINKABLE_EXTRALIBS}) + set_property(TARGET ${frameworkconfig} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-compatibility_version -Wl,2.0 -Wl,-current_version -Wl,2.0") string(REPLACE "*" ";" componentsobjects-whitespace "${componentsobjects}") target_sources(${frameworkconfig} PRIVATE "${componentsobjects-whitespace}") @@ -544,19 +558,26 @@ if(NOT DISABLE_EXECUTABLES) set_target_properties(mono-sgen PROPERTIES INSTALL_RPATH "$ORIGIN") endif() endif() - target_link_libraries(mono-sgen PRIVATE monoapi eglib_api monosgen-static dn-containers zlib) + + set(MONOSGEN_LINKABLE_LIBS "") + list(APPEND MONOSGEN_LINKABLE_LIBS monoapi eglib_api monosgen-static dn-containers) + if (INTERNAL_ZLIB_NG) + list(APPEND MONOSGEN_LINKABLE_LIBS zlib) + endif() + target_link_libraries(mono-sgen PRIVATE ${MONOSGEN_LINKABLE_LIBS}) + if (HOST_WASM) target_link_libraries(mono-sgen PRIVATE mono-wasm-nosimd) endif() - set(MONOSGEN_LINKABLE_LIBS "") - list(APPEND MONOSGEN_LINKABLE_LIBS ${OS_LIBS} ${LLVM_LIBS}) + set(MONOSGEN_LINKABLE_EXTRALIBS "") + list(APPEND MONOSGEN_LINKABLE_EXTRALIBS ${OS_LIBS} ${LLVM_LIBS}) if (INTERNAL_ZLIB_NG) - list(APPEND MONOSGEN_LINKABLE_LIBS zlib) + list(APPEND MONOSGEN_LINKABLE_EXTRALIBS zlib) else() - list(APPEND MONOSGEN_LINKABLE_LIBS ${Z_LIBS}) + list(APPEND MONOSGEN_LINKABLE_EXTRALIBS ${Z_LIBS}) endif() - target_link_libraries(mono-sgen PRIVATE ${MONOSGEN_LINKABLE_LIBS}) + target_link_libraries(mono-sgen PRIVATE ${MONOSGEN_LINKABLE_EXTRALIBS}) # musl-libc implements ucontext in a different library on s390x if(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) From 13aeb0fde0aa5169066267e53c799d968ff653e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 27 Jun 2024 15:40:42 -0700 Subject: [PATCH 34/39] Simplify zlib_allocator.h --- .../System.IO.Compression.Native/zlib_allocator.h | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/native/libs/System.IO.Compression.Native/zlib_allocator.h b/src/native/libs/System.IO.Compression.Native/zlib_allocator.h index 01a32d2c73e7cb..cadd00bb5879c5 100644 --- a/src/native/libs/System.IO.Compression.Native/zlib_allocator.h +++ b/src/native/libs/System.IO.Compression.Native/zlib_allocator.h @@ -1,17 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#ifdef _WIN32 - #include - #include - #define FUNCTIONCALLINGCONVENTION WINAPI -#else - #include "pal_types.h" - #include "pal_compiler.h" - #define FUNCTIONCALLINGCONVENTION -#endif #include // voidpf -voidpf FUNCTIONCALLINGCONVENTION z_custom_calloc(voidpf opaque, unsigned items, unsigned size); +voidpf z_custom_calloc(voidpf opaque, unsigned items, unsigned size); -void FUNCTIONCALLINGCONVENTION z_custom_cfree(voidpf opaque, voidpf ptr); \ No newline at end of file +void z_custom_cfree(voidpf opaque, voidpf ptr); From f0e60d96b85579710e4aefdd55103db6f4ae777e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Mon, 1 Jul 2024 14:12:45 -0700 Subject: [PATCH 35/39] Fix build for linux-armv6 --- src/mono/mono/mini/CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 1c3e5197b8f2db..ca9d6d3ea260f7 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -323,7 +323,14 @@ if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS) endif() add_library(monosgen-objects OBJECT "${monosgen-sources}") -target_link_libraries (monosgen-objects PRIVATE monoapi eglib_api utils_objects sgen_objects metadata_objects) + +set(MONOSGEN_OBJECTS_LINKABLE_LIBS "") +list(APPEND MONOSGEN_OBJECTS_LINKABLE_LIBS monoapi eglib_api utils_objects sgen_objects metadata_objects) +if (INTERNAL_ZLIB_NG) + list(APPEND MONOSGEN_OBJECTS_LINKABLE_LIBS zlib) +endif() +target_link_libraries (monosgen-objects PRIVATE ${MONOSGEN_OBJECTS_LINKABLE_LIBS}) + if(NOT HOST_WIN32) target_compile_definitions(monosgen-objects PRIVATE -DMONO_DLL_EXPORT) endif() From c5f6798ed25567ee7ae1b04f04aebc0533af4086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:18:43 -0700 Subject: [PATCH 36/39] Remove unneeded definitions for ZLIB_COMPAT and INTERNAL_ZLIB_NG --- eng/native/configurecompiler.cmake | 5 ----- src/mono/CMakeLists.txt | 5 ----- src/native/libs/System.IO.Compression.Native/CMakeLists.txt | 2 -- 3 files changed, 12 deletions(-) diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index a124523bb1561b..aedc4825273003 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -1034,8 +1034,3 @@ elseif (NOT CLR_CMAKE_HOST_BROWSER AND NOT CLR_CMAKE_HOST_WASI) enable_language(ASM) endif(CLR_CMAKE_HOST_WIN32) - -if (INTERNAL_ZLIB_NG) - add_definitions(-DINTERNAL_ZLIB_NG) - add_definitions(-DZLIB_COMPAT) -endif() \ No newline at end of file diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index ff5dca68fa2887..e3140624431d12 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -508,11 +508,6 @@ if ((HOST_MACCAT AND HOST_ARM64) OR (TARGET_MACCAT AND TARGET_ARM64)) set(TARGET_APPLE_MOBILE 1) endif() -if (INTERNAL_ZLIB_NG) - add_definitions(-DINTERNAL_ZLIB_NG) - add_definitions(-DZLIB_COMPAT) -endif() - # Decide if we need zlib-ng. if(NOT DISABLE_EMBEDDED_PDB OR NOT DISABLE_LOG_PROFILER_GZ) if (INTERNAL_ZLIB_NG) diff --git a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt index db6ec8c9a97bd0..d20f3250790c1b 100644 --- a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt +++ b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt @@ -4,8 +4,6 @@ include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake) if (INTERNAL_ZLIB_NG) include(${CLR_SRC_NATIVE_DIR}/external/zlib-ng.cmake) - add_definitions(-DINTERNAL_ZLIB_NG) - add_definitions(-DZLIB_COMPAT) endif() configure_file( From e073b2040ba8bae59499cc58b3b0d8509f7e746c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:28:09 -0700 Subject: [PATCH 37/39] Remove unnecessary endif arguments and remove duplicate linked library --- src/mono/mono/mini/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index ca9d6d3ea260f7..209cd37be52b31 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -357,7 +357,7 @@ if(NOT DISABLE_SHARED_LIBS) # musl-libc implements ucontext in a different library on s390x if(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) target_link_libraries(monosgen-shared PRIVATE ucontext) - endif(CLR_CMAKE_TARGET_LINUX_MUSL AND TARGET_S390X) + endif() set_target_properties(monosgen-shared PROPERTIES OUTPUT_NAME ${MONO_SHARED_LIB_NAME}) if(MONO_SET_RPATH_ORIGIN) set_target_properties(monosgen-shared PROPERTIES INSTALL_RPATH "$ORIGIN") @@ -373,7 +373,7 @@ if(NOT DISABLE_SHARED_LIBS) target_link_libraries(monosgen-shared PRIVATE ${MONOSGENSHARED_LINKABLE_LIBS}) else() list(APPEND MONOSGENSHARED_LINKABLE_LIBS utils_objects sgen_objects metadata_objects) - target_link_libraries(monosgen-shared PRIVATE monoapi ${MONOSGENSHARED_LINKABLE_LIBS}) + target_link_libraries(monosgen-shared PRIVATE ${MONOSGENSHARED_LINKABLE_LIBS}) endif() target_include_directories (monosgen-shared PRIVATE monoapi) if(TARGET_WIN32) From 6e9a7c660e95233c281c520d7c16e2e4e7dd2d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:35:51 -0700 Subject: [PATCH 38/39] Rename INTERNAL_ZLIB_NG to CLR_CMAKE_USE_SYSTEM_ZLIB, fix some incorrect conditions --- eng/native/configureplatform.cmake | 4 ++-- src/mono/CMakeLists.txt | 10 ++++----- src/mono/mono/eventpipe/test/CMakeLists.txt | 6 ++--- src/mono/mono/metadata/CMakeLists.txt | 4 ++-- src/mono/mono/mini/CMakeLists.txt | 22 +++++++++---------- src/mono/mono/profiler/CMakeLists.txt | 6 ++--- .../CMakeLists.txt | 14 ++++++------ 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/eng/native/configureplatform.cmake b/eng/native/configureplatform.cmake index b9905b02f76ba6..e957a0837490b7 100644 --- a/eng/native/configureplatform.cmake +++ b/eng/native/configureplatform.cmake @@ -501,8 +501,8 @@ if(LOWERCASE_CMAKE_BUILD_TYPE STREQUAL debug) string(REPLACE "-D_FORTIFY_SOURCE=2 " "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") endif() -if (NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS) +if (CLR_CMAKE_TARGET_ANDROID OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) # Our zlib-ng copy should only be used in non-mobile platforms only. # In mobile platforms we should use the zlib package provided by the system. - set(INTERNAL_ZLIB_NG 1) + set(CLR_CMAKE_USE_SYSTEM_ZLIB 1) endif() diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index e3140624431d12..fac1d9fb0e33ca 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -510,13 +510,13 @@ endif() # Decide if we need zlib-ng. if(NOT DISABLE_EMBEDDED_PDB OR NOT DISABLE_LOG_PROFILER_GZ) - if (INTERNAL_ZLIB_NG) - include(${CLR_SRC_NATIVE_DIR}/external/zlib-ng.cmake) - else() - # if we're not on a platform where we use the in-tree zlib, require system zlib + if (CLR_CMAKE_USE_SYSTEM_ZLIB) + # if we're not on a platform where we use the in-tree zlib-ng, require system zlib include(${CLR_SRC_NATIVE_DIR}/libs/System.IO.Compression.Native/extra_libs.cmake) set(Z_LIBS) append_extra_compression_libs(Z_LIBS) + else() + include(${CLR_SRC_NATIVE_DIR}/external/zlib-ng.cmake) endif() endif() @@ -669,7 +669,7 @@ if(LLVM_PREFIX) list(APPEND llvm_system_libs "-lm") endif() - if (NOT INTERNAL_ZLIB_NG AND (HOST_LINUX OR HOST_OSX)) + if (CLR_CMAKE_USE_SYSTEM_ZLIB AND (HOST_LINUX OR HOST_OSX)) list(APPEND llvm_system_libs "-lz") endif() diff --git a/src/mono/mono/eventpipe/test/CMakeLists.txt b/src/mono/mono/eventpipe/test/CMakeLists.txt index 08fd7209beed11..92ddfb3ce17f96 100644 --- a/src/mono/mono/eventpipe/test/CMakeLists.txt +++ b/src/mono/mono/eventpipe/test/CMakeLists.txt @@ -42,10 +42,10 @@ if(ENABLE_PERFTRACING) set(EPTEST_LINKABLE_LIBS "") list(APPEND EPTEST_LINKABLE_LIBS eglib_api monosgen-static ${OS_LIBS} ${LLVM_LIBS} monoapi) - if (INTERNAL_ZLIB_NG) - list(APPEND EPTEST_LINKABLE_LIBS ${EPTEST_LINKABLE_LIBS} zlib) - else() + if (CLR_CMAKE_USE_SYSTEM_ZLIB) list(APPEND EPTEST_LINKABLE_LIBS ${EPTEST_LINKABLE_LIBS} ${Z_LIBS}) + else() + list(APPEND EPTEST_LINKABLE_LIBS ${EPTEST_LINKABLE_LIBS} zlib) endif() target_link_libraries(ep-test PRIVATE ${EPTEST_LINKABLE_LIBS}) diff --git a/src/mono/mono/metadata/CMakeLists.txt b/src/mono/mono/metadata/CMakeLists.txt index 5873805cbca91f..e3463b514d0c0f 100644 --- a/src/mono/mono/metadata/CMakeLists.txt +++ b/src/mono/mono/metadata/CMakeLists.txt @@ -203,7 +203,7 @@ if(HOST_WIN32 AND NOT DISABLE_SHARED_LIBS) set(METADATAOBJECTSSHARED_LINKABLE_LIBS "") list(APPEND METADATAOBJECTSSHARED_LINKABLE_LIBS monoapi eglib_api utils_objects_shared) - if (INTERNAL_ZLIB_NG) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) list(APPEND METADATAOBJECTSSHARED_LINKABLE_LIBS zlib) endif() target_link_libraries(metadata_objects_shared PRIVATE ${METADATAOBJECTSSHARED_LINKABLE_LIBS}) @@ -222,7 +222,7 @@ target_compile_definitions(metadata_objects PRIVATE ${metadata_compile_definitio set(METADATAOBJECTS_LINKABLE_LIBS "") list(APPEND METADATAOBJECTS_LINKABLE_LIBS monoapi eglib_api utils_objects) -if (INTERNAL_ZLIB_NG) +if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) list(APPEND METADATAOBJECTS_LINKABLE_LIBS zlib) endif() target_link_libraries(metadata_objects PRIVATE ${METADATAOBJECTS_LINKABLE_LIBS}) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 209cd37be52b31..8928037a3be55d 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -326,7 +326,7 @@ add_library(monosgen-objects OBJECT "${monosgen-sources}") set(MONOSGEN_OBJECTS_LINKABLE_LIBS "") list(APPEND MONOSGEN_OBJECTS_LINKABLE_LIBS monoapi eglib_api utils_objects sgen_objects metadata_objects) -if (INTERNAL_ZLIB_NG) +if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) list(APPEND MONOSGEN_OBJECTS_LINKABLE_LIBS zlib) endif() target_link_libraries (monosgen-objects PRIVATE ${MONOSGEN_OBJECTS_LINKABLE_LIBS}) @@ -365,7 +365,7 @@ if(NOT DISABLE_SHARED_LIBS) set(MONOSGENSHARED_LINKABLE_LIBS "") list(APPEND MONOSGENSHARED_LINKABLE_LIBS monoapi eglib_objects dn-containers) - if (INTERNAL_ZLIB_NG) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) list(APPEND MONOSGENSHARED_LINKABLE_LIBS zlib) endif() if(HOST_WIN32) @@ -384,10 +384,10 @@ if(NOT DISABLE_SHARED_LIBS) set(MONOSGENSHARED_LINKABLE_EXTRALIBS "") list(APPEND MONOSGENSHARED_LINKABLE_EXTRALIBS ${OS_LIBS} ${LLVM_LIBS}) - if (INTERNAL_ZLIB_NG) - list(APPEND MONOSGENSHARED_LINKABLE_EXTRALIBS zlib) - else() + if (CLR_CMAKE_USE_SYSTEM_ZLIB) list(APPEND MONOSGENSHARED_LINKABLE_EXTRALIBS ${Z_LIBS}) + else() + list(APPEND MONOSGENSHARED_LINKABLE_EXTRALIBS zlib) endif() target_link_libraries(monosgen-shared PRIVATE ${MONOSGENSHARED_LINKABLE_EXTRALIBS}) @@ -437,14 +437,14 @@ if(NOT DISABLE_SHARED_LIBS) set(FRAMEWORKCONFIG_LINKABLE_LIBS "") list(APPEND FRAMEWORKCONFIG_LINKABLE_LIBS monoapi eglib_objects utils_objects sgen_objects metadata_objects dn-containers) - if (INTERNAL_ZLIB_NG) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) list(APPEND FRAMEWORKCONFIG_LINKABLE_LIBS zlib) endif() target_link_libraries(${frameworkconfig} PRIVATE ${FRAMEWORKCONFIG_LINKABLE_LIBS}) set(FRAMEWORKCONFIG_LINKABLE_EXTRALIBS "") list(APPEND FRAMEWORKCONFIG_LINKABLE_EXTRALIBS ${OS_LIBS} ${LLVM_LIBS}) - if (INTERNAL_ZLIB_NG) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) list(APPEND FRAMEWORKCONFIG_LINKABLE_EXTRALIBS zlib) else() list(APPEND FRAMEWORKCONFIG_LINKABLE_EXTRALIBS ${Z_LIBS}) @@ -568,7 +568,7 @@ if(NOT DISABLE_EXECUTABLES) set(MONOSGEN_LINKABLE_LIBS "") list(APPEND MONOSGEN_LINKABLE_LIBS monoapi eglib_api monosgen-static dn-containers) - if (INTERNAL_ZLIB_NG) + if (CLR_CMAKE_USE_SYSTEM_ZLIB) list(APPEND MONOSGEN_LINKABLE_LIBS zlib) endif() target_link_libraries(mono-sgen PRIVATE ${MONOSGEN_LINKABLE_LIBS}) @@ -579,10 +579,10 @@ if(NOT DISABLE_EXECUTABLES) set(MONOSGEN_LINKABLE_EXTRALIBS "") list(APPEND MONOSGEN_LINKABLE_EXTRALIBS ${OS_LIBS} ${LLVM_LIBS}) - if (INTERNAL_ZLIB_NG) - list(APPEND MONOSGEN_LINKABLE_EXTRALIBS zlib) - else() + if (CLR_CMAKE_USE_SYSTEM_ZLIB) list(APPEND MONOSGEN_LINKABLE_EXTRALIBS ${Z_LIBS}) + else() + list(APPEND MONOSGEN_LINKABLE_EXTRALIBS zlib) endif() target_link_libraries(mono-sgen PRIVATE ${MONOSGEN_LINKABLE_EXTRALIBS}) diff --git a/src/mono/mono/profiler/CMakeLists.txt b/src/mono/mono/profiler/CMakeLists.txt index 106e0b154cfd64..e172774a6ebc5a 100644 --- a/src/mono/mono/profiler/CMakeLists.txt +++ b/src/mono/mono/profiler/CMakeLists.txt @@ -26,10 +26,10 @@ if(NOT DISABLE_LIBS) install(TARGETS mono-profiler-log-static LIBRARY) if(NOT DISABLE_LOG_PROFILER_GZ) - if (INTERNAL_ZLIB_NG) - target_link_libraries(mono-profiler-log PRIVATE zlib) - else() + if (CLR_CMAKE_USE_SYSTEM_ZLIB) target_link_libraries(mono-profiler-log PRIVATE ${Z_LIBS}) + else() + target_link_libraries(mono-profiler-log PRIVATE zlib) endif() endif() endif() diff --git a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt index d20f3250790c1b..69d333ae53f9c5 100644 --- a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt +++ b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt @@ -2,7 +2,7 @@ project(System.IO.Compression.Native C) include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake) -if (INTERNAL_ZLIB_NG) +if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) include(${CLR_SRC_NATIVE_DIR}/external/zlib-ng.cmake) endif() @@ -102,7 +102,7 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) ${NATIVECOMPRESSION_SOURCES} ) - if (INTERNAL_ZLIB_NG) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) target_link_libraries(System.IO.Compression.Native-Static PRIVATE zlibstatic) endif() @@ -121,7 +121,7 @@ else () ${VERSION_FILE_RC_PATH} ) - if (INTERNAL_ZLIB_NG) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) target_link_libraries(System.IO.Compression.Native PRIVATE zlib) endif() endif () @@ -135,7 +135,7 @@ else () ${NATIVECOMPRESSION_SOURCES} ) - if (INTERNAL_ZLIB_NG) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) target_link_libraries(System.IO.Compression.Native-Static PRIVATE zlibstatic) endif() @@ -145,7 +145,7 @@ else () ${NATIVECOMPRESSION_SOURCES} ) - if (INTERNAL_ZLIB_NG) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) target_link_libraries(System.IO.Compression.Native.Aot PRIVATE zlibstatic) endif() @@ -157,7 +157,7 @@ else () ${NATIVECOMPRESSION_SOURCES} ) - if (INTERNAL_ZLIB_NG) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) target_link_libraries(System.IO.Compression.Native.Aot.GuardCF PRIVATE zlibstatic) endif() @@ -183,7 +183,7 @@ else () endif () -if(INTERNAL_ZLIB_NG AND STATIC_LIBS_ONLY) +if((NOT CLR_CMAKE_USE_SYSTEM_ZLIB) AND STATIC_LIBS_ONLY) install_static_library(zlib aotsdk nativeaot) endif() From 417ea9f603325341a0f359af031d32ee3811a2e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20S=C3=A1nchez=20L=C3=B3pez?= <1175054+carlossanlop@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:29:14 -0700 Subject: [PATCH 39/39] Workaround: skip zlib-ng inclusion in armv6 --- Directory.Build.props | 2 +- eng/native/configureplatform.cmake | 2 +- src/mono/mono/mini/CMakeLists.txt | 2 +- src/mono/msbuild/apple/build/AppleBuild.targets | 2 +- src/native/libs/System.IO.Compression.Native/extra_libs.cmake | 3 +++ 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index c8105e8d424b62..61edda987ed6d5 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -324,7 +324,7 @@ true ClrFullNativeBuild;ClrRuntimeSubset;ClrJitSubset;ClrPalTestsSubset;ClrAllJitsSubset;ClrILToolsSubset;ClrNativeAotSubset;ClrSpmiSubset;ClrCrossComponentsSubset;ClrDebugSubset;HostArchitecture;PgoInstrument;NativeOptimizationDataSupported;CMakeArgs;CxxStandardLibrary;CxxStandardLibraryStatic;CxxAbiLibrary - true + true diff --git a/eng/native/configureplatform.cmake b/eng/native/configureplatform.cmake index e957a0837490b7..1dfc2458d11e8c 100644 --- a/eng/native/configureplatform.cmake +++ b/eng/native/configureplatform.cmake @@ -501,7 +501,7 @@ if(LOWERCASE_CMAKE_BUILD_TYPE STREQUAL debug) string(REPLACE "-D_FORTIFY_SOURCE=2 " "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") endif() -if (CLR_CMAKE_TARGET_ANDROID OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS) +if (CLR_CMAKE_TARGET_ANDROID OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS OR CLR_CMAKE_HOST_ARCH_ARMV6) # Our zlib-ng copy should only be used in non-mobile platforms only. # In mobile platforms we should use the zlib package provided by the system. set(CLR_CMAKE_USE_SYSTEM_ZLIB 1) diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 8928037a3be55d..af9987869f5ac2 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -568,7 +568,7 @@ if(NOT DISABLE_EXECUTABLES) set(MONOSGEN_LINKABLE_LIBS "") list(APPEND MONOSGEN_LINKABLE_LIBS monoapi eglib_api monosgen-static dn-containers) - if (CLR_CMAKE_USE_SYSTEM_ZLIB) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) list(APPEND MONOSGEN_LINKABLE_LIBS zlib) endif() target_link_libraries(mono-sgen PRIVATE ${MONOSGEN_LINKABLE_LIBS}) diff --git a/src/mono/msbuild/apple/build/AppleBuild.targets b/src/mono/msbuild/apple/build/AppleBuild.targets index bec6aac5643e83..483ae04924a728 100644 --- a/src/mono/msbuild/apple/build/AppleBuild.targets +++ b/src/mono/msbuild/apple/build/AppleBuild.targets @@ -6,7 +6,7 @@ false <_ProcessRuntimeComponentsForLibraryMode Condition="'$(_IsLibraryMode)' == 'true' and '$(UseNativeAOTRuntime)' != 'true'">_ProcessRuntimeComponentsForLibraryMode false - true + true