From 1b03858175e371edfb01aebf2927949e62712b83 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 3 Dec 2024 14:36:10 -0800 Subject: [PATCH 1/4] Install zlib in the IlcFrameworkNative folder instead of alongside the runtime As the runtime doesn't use zlib, it makes more sense for NativeAOT for zlib to be shipped alongside the Compression.Native library. We don't have any shipping scenarios with Mono where we use the non-system zlib, so we should be able to figure something out for dev-innerloop-only scenarios if needed. --- .../Microsoft.NETCore.Native.Unix.targets | 2 +- .../libs/System.IO.Compression.Native/CMakeLists.txt | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 7bbf4e613e4975..387d735be5c1a8 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -166,7 +166,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 e13e1271809b17..540c19920843b2 100644 --- a/src/native/libs/System.IO.Compression.Native/CMakeLists.txt +++ b/src/native/libs/System.IO.Compression.Native/CMakeLists.txt @@ -91,6 +91,8 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) endif() set_target_properties(System.IO.Compression.Native-Static PROPERTIES OUTPUT_NAME System.IO.Compression.Native CLEAN_DIRECT_OUTPUT 1) + + install (TARGETS zlib DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs) else () if (GEN_SHARED_LIB) include (GenerateExportHeader) @@ -163,12 +165,11 @@ else () if(STATIC_LIBS_ONLY) install_static_library(System.IO.Compression.Native.Aot aotsdk nativeaot) install_static_library(System.IO.Compression.Native.Aot.GuardCF aotsdk nativeaot) + if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB) + install_static_library(zlib aotsdk nativeaot) + endif() endif() endif () -if((NOT CLR_CMAKE_USE_SYSTEM_ZLIB) AND STATIC_LIBS_ONLY) - install_static_library(zlib aotsdk nativeaot) -endif() - install (TARGETS System.IO.Compression.Native-Static DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs) From e82defd8b8a4d0d0a35f6074173d86b84fdc01e9 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 3 Dec 2024 15:01:40 -0800 Subject: [PATCH 2/4] Fix check for 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 387d735be5c1a8..55dedda8fdd16a 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -29,7 +29,7 @@ The .NET Foundation licenses this file to you under the MIT license. - true + true libRuntime.WorkstationGC libRuntime.ServerGC From 48fd70617ed014d4e84d9dcfc7a874ef8ba51aec Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 4 Dec 2024 11:07:51 -0800 Subject: [PATCH 3/4] wasm and android fixes --- src/mono/browser/runtime/CMakeLists.txt | 4 ++-- src/mono/mono.proj | 13 +++++-------- src/mono/wasi/runtime/CMakeLists.txt | 2 +- .../System.IO.Compression.Native/CMakeLists.txt | 4 +++- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/mono/browser/runtime/CMakeLists.txt b/src/mono/browser/runtime/CMakeLists.txt index 93be47d8d09fd9..95938c2e425100 100644 --- a/src/mono/browser/runtime/CMakeLists.txt +++ b/src/mono/browser/runtime/CMakeLists.txt @@ -29,11 +29,11 @@ target_link_libraries(dotnet.native ${MONO_ARTIFACTS_DIR}/libmono-profiler-aot.a ${MONO_ARTIFACTS_DIR}/libmono-profiler-browser.a ${MONO_ARTIFACTS_DIR}/libmono-profiler-log.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 - ${NATIVE_BIN_DIR}/libSystem.IO.Compression.Native.a) + ${NATIVE_BIN_DIR}/libSystem.IO.Compression.Native.a + ${NATIVE_BIN_DIR}/libz.a) set_target_properties(dotnet.native PROPERTIES LINK_DEPENDS "${NATIVE_BIN_DIR}/src/emcc-default.rsp;${NATIVE_BIN_DIR}/src/es6/dotnet.es6.pre.js;${NATIVE_BIN_DIR}/src/es6/dotnet.es6.lib.js;${NATIVE_BIN_DIR}/src/es6/dotnet.es6.extpost.js;" diff --git a/src/mono/mono.proj b/src/mono/mono.proj index a9bdbb62e0afa3..cc4d240fe835fb 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -273,7 +273,7 @@ JS_ENGINES = [NODE_JS] - + @@ -295,7 +295,7 @@ JS_ENGINES = [NODE_JS] - false - + @@ -365,8 +365,8 @@ JS_ENGINES = [NODE_JS] See https://github.com/llvm/llvm-project/pull/98373 See https://github.com/dotnet/runtime/issues/104773 --> - @@ -1208,9 +1208,6 @@ 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 - Date: Thu, 5 Dec 2024 09:55:25 -0800 Subject: [PATCH 4/4] Add support for pthreads when building zlib-ng in libraries partition for wasm. --- src/native/external/zlib-ng.cmake | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/native/external/zlib-ng.cmake b/src/native/external/zlib-ng.cmake index c77f8e214a0ab6..ed86660ea70e81 100644 --- a/src/native/external/zlib-ng.cmake +++ b/src/native/external/zlib-ng.cmake @@ -1,4 +1,4 @@ - # 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 include(FetchContent) @@ -16,9 +16,15 @@ set(WITH_RVV OFF) # We don't support ARMv6 and the check works incorrectly when compiling for ARMv7 w/ Thumb instruction set set(WITH_ARMV6 OFF) -# '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) + # 'aligned_alloc' is not available in browser/wasi, yet it is set by zlib-ng/CMakeLists.txt. set(HAVE_ALIGNED_ALLOC FALSE CACHE BOOL "have aligned_alloc" FORCE) + + # zlib-ng uses atomics, so we need to enable threads when requested for browser/wasi, otherwise the wasm target won't have thread support. + if (CMAKE_USE_PTHREADS) + add_compile_options(-pthread) + add_linker_flag(-pthread) + endif() endif() set(BUILD_SHARED_LIBS OFF) # Shared libraries aren't supported in wasm