Skip to content

Commit 2f81513

Browse files
authored
Install zlib in the IlcFrameworkNative folder instead of alongside the runtime (dotnet#110378)
* 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. * Fix check for UseSystemZlib * wasm and android fixes * Add support for pthreads when building zlib-ng in libraries partition for wasm.
1 parent 5a5ea3e commit 2f81513

File tree

6 files changed

+25
-19
lines changed

6 files changed

+25
-19
lines changed

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The .NET Foundation licenses this file to you under the MIT license.
2929
<Target Name="SetupOSSpecificProps" DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)">
3030

3131
<PropertyGroup>
32-
<UseSystemZlib Condition="'$(UseSystemZlib)' == '' and !Exists('$(IlcSdkPath)libz.a')">true</UseSystemZlib>
32+
<UseSystemZlib Condition="'$(UseSystemZlib)' == '' and !Exists('$(IlcFrameworkNativePath)libz.a')">true</UseSystemZlib>
3333
<FullRuntimeName>libRuntime.WorkstationGC</FullRuntimeName>
3434
<FullRuntimeName Condition="'$(ServerGarbageCollection)' == 'true' or '$(IlcLinkServerGC)' == 'true'">libRuntime.ServerGC</FullRuntimeName>
3535

@@ -166,7 +166,7 @@ The .NET Foundation licenses this file to you under the MIT license.
166166

167167
<ItemGroup>
168168
<!-- zlib must be added after System.IO.Compression.Native, order matters. -->
169-
<NativeLibrary Condition="'$(UseSystemZlib)' != 'true'" Include="$(IlcSdkPath)libz.a" />
169+
<NativeLibrary Condition="'$(UseSystemZlib)' != 'true'" Include="$(IlcFrameworkNativePath)libz.a" />
170170
</ItemGroup>
171171

172172
<ItemGroup Condition="'$(StaticICULinking)' == 'true' and '$(NativeLib)' != 'Static' and '$(InvariantGlobalization)' != 'true'">

src/mono/browser/runtime/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ target_link_libraries(dotnet.native
2929
${MONO_ARTIFACTS_DIR}/libmono-profiler-aot.a
3030
${MONO_ARTIFACTS_DIR}/libmono-profiler-browser.a
3131
${MONO_ARTIFACTS_DIR}/libmono-profiler-log.a
32-
${MONO_ARTIFACTS_DIR}/libz.a
3332
${NATIVE_BIN_DIR}/wasm-bundled-timezones.a
3433
${NATIVE_BIN_DIR}/libSystem.Native.a
3534
${NATIVE_BIN_DIR}/libSystem.Globalization.Native.a
36-
${NATIVE_BIN_DIR}/libSystem.IO.Compression.Native.a)
35+
${NATIVE_BIN_DIR}/libSystem.IO.Compression.Native.a
36+
${NATIVE_BIN_DIR}/libz.a)
3737

3838
set_target_properties(dotnet.native PROPERTIES
3939
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;"

src/mono/mono.proj

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ JS_ENGINES = [NODE_JS]
273273
</PropertyGroup>
274274

275275
<RemoveDir Directories="$(EMSDK_PATH)" />
276-
276+
277277
<ItemGroup>
278278
<EmsdkFiles Condition="'%(PackageReference.Identity)' != 'runtime.$(_portableHostOS)-$(BuildArchitecture).Microsoft.NETCore.Runtime.Wasm.Node.Transport' and '%(PackageReference.Identity)' != 'Microsoft.NET.Runtime.Emscripten.$(EmsdkVersion).Python.win-$(BuildArchitecture)'"
279279
Include="$(NuGetPackageRoot)\$([System.String]::Copy(%(PackageReference.Identity)).ToLowerInvariant())\%(PackageReference.Version)\tools\**" />
@@ -295,7 +295,7 @@ JS_ENGINES = [NODE_JS]
295295
<ReadLinesFromFile File="$(EMSDK_PATH)emsdk_env$(ScriptExt)">
296296
<Output TaskParameter="Lines" PropertyName="_EmsdkEnvFileText" />
297297
</ReadLinesFromFile>
298-
<WriteLinesToFile File="$(EMSDK_PATH)emsdk_env$(ScriptExt)"
298+
<WriteLinesToFile File="$(EMSDK_PATH)emsdk_env$(ScriptExt)"
299299
Overwrite="true"
300300
Lines="$(_EmsdkPaths);$(_EmsdkEnvFileText)" />
301301
<WriteLinesToFile File="$(EMSDK_PATH)emscripten/.emscripten"
@@ -313,7 +313,7 @@ JS_ENGINES = [NODE_JS]
313313

314314
<PropertyGroup>
315315
<ShouldProvisionEmscripten>false</ShouldProvisionEmscripten>
316-
</PropertyGroup>
316+
</PropertyGroup>
317317
</Target>
318318

319319
<!-- Sets up WASI SDK if you don't have the WASI_SDK_PATH env variable set -->
@@ -365,8 +365,8 @@ JS_ENGINES = [NODE_JS]
365365
See https://github.com/llvm/llvm-project/pull/98373
366366
See https://github.com/dotnet/runtime/issues/104773
367367
-->
368-
<Exec Command="wasm-opt --version" IgnoreExitCode="true"
369-
IgnoreStandardErrorWarningFormat="true"
368+
<Exec Command="wasm-opt --version" IgnoreExitCode="true"
369+
IgnoreStandardErrorWarningFormat="true"
370370
StandardErrorImportance="low"
371371
StandardOutputImportance="Low" >
372372
<Output TaskParameter="ExitCode" PropertyName="_WasmOptExitCode"/>
@@ -1208,9 +1208,6 @@ JS_ENGINES = [NODE_JS]
12081208
<_MonoRuntimeArtifacts Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)out\lib\libmono-wasm-nosimd.a">
12091209
<Destination>$(RuntimeBinDir)libmono-wasm-nosimd.a</Destination>
12101210
</_MonoRuntimeArtifacts>
1211-
<_MonoRuntimeArtifacts Condition="('$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true') and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)_deps\fetchzlibng-build\libz.a">
1212-
<Destination>$(RuntimeBinDir)libz.a</Destination>
1213-
</_MonoRuntimeArtifacts>
12141211
</ItemGroup>
12151212

12161213
<Copy SourceFiles="@(_MonoRuntimeArtifacts)"

src/mono/wasi/runtime/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ target_link_libraries(dotnet
2727
${MONO_ARTIFACTS_DIR}/libmonosgen-2.0.a
2828
${MONO_ARTIFACTS_DIR}/libmono-icall-table.a
2929
${MONO_ARTIFACTS_DIR}/libmono-wasm-${CONFIGURATION_INTERPSIMDTABLES_LIB}.a
30-
${MONO_ARTIFACTS_DIR}/libz.a
3130
${NATIVE_BIN_DIR}/wasm-bundled-timezones.a
3231
${NATIVE_BIN_DIR}/libSystem.Native.a
3332
${NATIVE_BIN_DIR}/libSystem.Globalization.Native.a
3433
${NATIVE_BIN_DIR}/libSystem.IO.Compression.Native.a
34+
${NATIVE_BIN_DIR}/libz.a
3535
)
3636

3737
set_target_properties(dotnet PROPERTIES

src/native/external/zlib-ng.cmake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# IMPORTANT: do not use add_compile_options(), add_definitions() or similar functions here since it will leak to the including projects
1+
# IMPORTANT: do not use add_compile_options(), add_definitions() or similar functions here since it will leak to the including projects
22

33
include(FetchContent)
44

@@ -16,9 +16,15 @@ set(WITH_RVV OFF)
1616
# We don't support ARMv6 and the check works incorrectly when compiling for ARMv7 w/ Thumb instruction set
1717
set(WITH_ARMV6 OFF)
1818

19-
# 'aligned_alloc' is not available in browser/wasi, yet it is set by zlib-ng/CMakeLists.txt.
2019
if (CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)
20+
# 'aligned_alloc' is not available in browser/wasi, yet it is set by zlib-ng/CMakeLists.txt.
2121
set(HAVE_ALIGNED_ALLOC FALSE CACHE BOOL "have aligned_alloc" FORCE)
22+
23+
# zlib-ng uses atomics, so we need to enable threads when requested for browser/wasi, otherwise the wasm target won't have thread support.
24+
if (CMAKE_USE_PTHREADS)
25+
add_compile_options(-pthread)
26+
add_linker_flag(-pthread)
27+
endif()
2228
endif()
2329

2430
set(BUILD_SHARED_LIBS OFF) # Shared libraries aren't supported in wasm

src/native/libs/System.IO.Compression.Native/CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)
9494
endif()
9595

9696
set_target_properties(System.IO.Compression.Native-Static PROPERTIES OUTPUT_NAME System.IO.Compression.Native CLEAN_DIRECT_OUTPUT 1)
97+
98+
if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB)
99+
install (TARGETS zlib DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs)
100+
endif()
97101
else ()
98102
if (GEN_SHARED_LIB)
99103
include (GenerateExportHeader)
@@ -166,12 +170,11 @@ else ()
166170
if(STATIC_LIBS_ONLY)
167171
install_static_library(System.IO.Compression.Native.Aot aotsdk nativeaot)
168172
install_static_library(System.IO.Compression.Native.Aot.GuardCF aotsdk nativeaot)
173+
if (NOT CLR_CMAKE_USE_SYSTEM_ZLIB)
174+
install_static_library(zlib aotsdk nativeaot)
175+
endif()
169176
endif()
170177

171178
endif ()
172179

173-
if((NOT CLR_CMAKE_USE_SYSTEM_ZLIB) AND STATIC_LIBS_ONLY)
174-
install_static_library(zlib aotsdk nativeaot)
175-
endif()
176-
177180
install (TARGETS System.IO.Compression.Native-Static DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs)

0 commit comments

Comments
 (0)