Skip to content

Commit 5fe72c1

Browse files
authored
Put brotli on the FetchContent plan (Try 2) (dotnet#109707)
* Reapply "Put brotli on the FetchContent plan (dotnet#107166)" (dotnet#109108) This reverts commit b780069. * Don't double-install the brotli libs * Don't try looking up locations for system brotli. Rely on the distro maintainer to set the paths correctly. Fixes dotnet#109105 * Install brotli where we install the compression native lib so they're always side-by-side (and we don't need to add it to the Mono build) * Brotli should get pulled from the same place as Compression.Native * Fix looking for libbrotlicommon.a on disk to determine if we should use system brotli
1 parent 2c9aaaf commit 5fe72c1

File tree

124 files changed

+2927
-80
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+2927
-80
lines changed

eng/DotNetBuild.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898

9999
<!-- Handle system libraries -->
100100
<UseSystemLibs Condition="'$(UseSystemLibs)' != ''">+$(UseSystemLibs)+</UseSystemLibs>
101-
<InnerBuildArgs Condition="'$(PortableBuild)' != 'true'">$(InnerBuildArgs) --cmakeargs -DCLR_CMAKE_USE_SYSTEM_BROTLI=true</InnerBuildArgs>
101+
<InnerBuildArgs Condition="$(UseSystemLibs.Contains('+brotli+'))">$(InnerBuildArgs) --cmakeargs -DCLR_CMAKE_USE_SYSTEM_BROTLI=true</InnerBuildArgs>
102102
<InnerBuildArgs Condition="$(UseSystemLibs.Contains('+libunwind+'))">$(InnerBuildArgs) --cmakeargs -DCLR_CMAKE_USE_SYSTEM_LIBUNWIND=true</InnerBuildArgs>
103103
<!-- TODO: llvm-libunwind -->
104104
<!-- TODO: LinuxTracepoints -->

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ The .NET Foundation licenses this file to you under the MIT license.
3030

3131
<PropertyGroup>
3232
<UseSystemZlib Condition="'$(UseSystemZlib)' == '' and !Exists('$(IlcFrameworkNativePath)libz.a')">true</UseSystemZlib>
33+
<!-- Use libbrotlicommon.a as the sentinel for the three brotli libs. -->
34+
<UseSystemBrotli Condition="'$(UseSystemBrotli)' == '' and !Exists('$(IlcFrameworkNativePath)libbrotlicommon.a')">true</UseSystemBrotli>
35+
3336
<FullRuntimeName>libRuntime.WorkstationGC</FullRuntimeName>
3437
<FullRuntimeName Condition="'$(ServerGarbageCollection)' == 'true' or '$(IlcLinkServerGC)' == 'true'">libRuntime.ServerGC</FullRuntimeName>
3538

@@ -169,6 +172,14 @@ The .NET Foundation licenses this file to you under the MIT license.
169172
<NativeLibrary Condition="'$(UseSystemZlib)' != 'true'" Include="$(IlcFrameworkNativePath)libz.a" />
170173
</ItemGroup>
171174

175+
<!-- brotli must be added after System.IO.Compression.Native and brotlicommon must be added last, order matters. -->
176+
<ItemGroup Condition="'$(UseSystemBrotli)' != 'true'">
177+
<NativeLibrary Include="$(IlcFrameworkNativePath)libbrotlienc.a" />
178+
<NativeLibrary Include="$(IlcFrameworkNativePath)libbrotlidec.a" />
179+
<NativeLibrary Include="$(IlcFrameworkNativePath)libbrotlicommon.a" />
180+
</ItemGroup>
181+
182+
172183
<ItemGroup Condition="'$(StaticICULinking)' == 'true' and '$(NativeLib)' != 'Static' and '$(InvariantGlobalization)' != 'true'">
173184
<NativeLibrary Include="$(IntermediateOutputPath)libs/System.Globalization.Native/build/libSystem.Globalization.Native.a" />
174185
<DirectPInvoke Include="libSystem.Globalization.Native" />
@@ -182,11 +193,6 @@ The .NET Foundation licenses this file to you under the MIT license.
182193
<NativeSystemLibrary Include="crypto" />
183194
</ItemGroup>
184195

185-
<ItemGroup Condition="'$(UseSystemBrotli)' != 'false' and Exists('$(IlcSdkPath)nonportable.txt')">
186-
<NativeSystemLibrary Include="brotlienc" />
187-
<NativeSystemLibrary Include="brotlidec" />
188-
</ItemGroup>
189-
190196
<ItemGroup Condition="'$(StaticOpenSslLinking)' == 'true' and '$(NativeLib)' != 'Static'">
191197
<NativeLibrary Include="$(IntermediateOutputPath)libs/System.Security.Cryptography.Native/build/libSystem.Security.Cryptography.Native.OpenSsl.a" />
192198
<DirectPInvoke Include="libSystem.Security.Cryptography.Native.OpenSsl" />
@@ -211,6 +217,7 @@ The .NET Foundation licenses this file to you under the MIT license.
211217
<NativeSystemLibrary Include="swiftCore" Condition="'$(_IsApplePlatform)' == 'true'" />
212218
<NativeSystemLibrary Include="swiftFoundation" Condition="'$(_IsApplePlatform)' == 'true'" />
213219
<NativeSystemLibrary Include="z" Condition="'$(UseSystemZlib)' == 'true'" />
220+
<NativeSystemLibrary Include="brotlienc;brotlidec;brotlicommon" Condition="'$(UseSystemBrotli)' == 'true'" />
214221
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic'" />
215222
<NativeSystemLibrary Include="log" Condition="'$(_linuxLibcFlavor)' == 'bionic'" />
216223
<NativeSystemLibrary Include="icucore" Condition="'$(_IsApplePlatform)' == 'true'" />

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ The .NET Foundation licenses this file to you under the MIT license.
4949
<NativeLibrary Include="$(IlcSdkPath)$(StandaloneGCSupportName)$(LibrarySuffix)" />
5050
<NativeLibrary Include="$(IlcSdkPath)aotminipal$(LibFileExt)" />
5151
<NativeLibrary Include="$(IlcSdkPath)zlibstatic$(LibFileExt)" />
52+
<NativeLibrary Include="$(IlcSdkPath)brotlicommon$(LibFileExt)" />
53+
<NativeLibrary Include="$(IlcSdkPath)brotlienc$(LibFileExt)" />
54+
<NativeLibrary Include="$(IlcSdkPath)brotlidec$(LibFileExt)" />
5255
</ItemGroup>
5356

5457
<ItemGroup>

src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,13 @@
282282
<!-- zlib-specific files -->
283283
<PlatformManifestFileEntry Include="libz.a" IsNative="true" />
284284
<PlatformManifestFileEntry Include="zlibstatic.lib" IsNative="true" />
285+
<!-- brotli-specific files -->
286+
<PlatformManifestFileEntry Include="libbrotlienc.a" IsNative="true" />
287+
<PlatformManifestFileEntry Include="libbrotlidec.a" IsNative="true" />
288+
<PlatformManifestFileEntry Include="libbrotlicommon.a" IsNative="true" />
289+
<PlatformManifestFileEntry Include="brotlienc.lib" IsNative="true" />
290+
<PlatformManifestFileEntry Include="brotlidec.lib" IsNative="true" />
291+
<PlatformManifestFileEntry Include="brotlicommon.lib" IsNative="true" />
285292
</ItemGroup>
286293

287294
<ItemGroup>

src/mono/msbuild/android/build/AndroidBuild.targets

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,15 @@
203203
<ProfiledAOTProfilePaths Include="$(MibcFilePath)" />
204204
</ItemGroup>
205205

206-
<!--
207-
In order for the runtime to work when static linking, we must supply
206+
<!--
207+
In order for the runtime to work when static linking, we must supply
208208
a list of direct pinvokes otherwise the runtime will crash
209209
-->
210210
<ItemGroup Condition="'$(_IsLibraryMode)' == 'true'">
211211
<DirectPInvokes Include="libSystem.Native" />
212212
<DirectPInvokes Include="libSystem.IO.Compression.Native" />
213213
<DirectPInvokes Include="libSystem.Security.Cryptography.Native.Android" />
214+
<DirectPInvokes Include="libbrotlienc;libbrotlidec" />
214215
</ItemGroup>
215216

216217
<PropertyGroup>

src/mono/msbuild/apple/build/AppleBuild.targets

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
</PropertyGroup>
1111

1212
<UsingTask Condition="'$(AppleGenerateAppBundle)' == 'true'"
13-
TaskName="AppleAppBuilderTask"
13+
TaskName="AppleAppBuilderTask"
1414
AssemblyFile="$(AppleAppBuilderTasksAssemblyPath)" />
1515
<UsingTask Condition="'$(RunAOTCompilation)' == 'true'"
1616
TaskName="ILStrip"
1717
AssemblyFile="$(MonoTargetsTasksAssemblyPath)" />
18-
<UsingTask TaskName="MonoTargetsTasks.MarshalingPInvokeScanner"
18+
<UsingTask TaskName="MonoTargetsTasks.MarshalingPInvokeScanner"
1919
AssemblyFile="$(MonoTargetsTasksAssemblyPath)" />
2020

2121
<Import Condition="Exists('$(ILCompilerTargetsPath)') and '$(UseNativeAOTRuntime)' == 'true'"
2222
Project="$(ILCompilerTargetsPath)" />
2323
<Import Condition="Exists('$(ILLinkTargetsPath)') and '$(UseNativeAOTRuntime)' == 'true'"
2424
Project="$(ILLinkTargetsPath)" />
2525

26-
<Target Name="_CleanPublish"
26+
<Target Name="_CleanPublish"
2727
BeforeTargets="Build">
2828
<RemoveDir Directories="$(PublishDir)" />
2929
</Target>
@@ -196,7 +196,7 @@
196196
<_IsNative>false</_IsNative>
197197
</_AssembliesToBundleInternal>
198198

199-
<_AotInputAssemblies Include="@(_AssembliesToBundleInternal)"
199+
<_AotInputAssemblies Include="@(_AssembliesToBundleInternal)"
200200
Condition="'%(_AssembliesToBundleInternal._InternalForceInterpret)' != 'true'">
201201
<AotArguments>$(AotArguments)</AotArguments>
202202
<ProcessArguments>$(ProcessArguments)</ProcessArguments>
@@ -205,7 +205,7 @@
205205
<_AOT_InternalForceInterpretAssemblies Include="@(_AssembliesToBundleInternal->WithMetadataValue('_InternalForceInterpret', 'true'))" />
206206
<_AssembliesToBundleInternal Remove="@(_AssembliesToBundleInternal)" />
207207
</ItemGroup>
208-
208+
209209
<MakeDir Directories="$(_MobileIntermediateOutputPath)" />
210210

211211
<PropertyGroup Condition="'$(iOSLikeDedup)' == 'true'">
@@ -228,15 +228,16 @@
228228
<_ExcludeFromAppDir Include="$(_iOSLikeDedupAssembly)" />
229229
</ItemGroup>
230230

231-
<!--
232-
In order for the runtime to work when static linking, we must supply
231+
<!--
232+
In order for the runtime to work when static linking, we must supply
233233
a list of direct pinvokes otherwise the runtime will crash
234234
-->
235235
<ItemGroup Condition="'$(_IsLibraryMode)' == 'true'">
236236
<DirectPInvokes Include="libSystem.Native" />
237237
<DirectPInvokes Include="libSystem.IO.Compression.Native" />
238238
<DirectPInvokes Include="libSystem.Net.Security.Native" />
239239
<DirectPInvokes Include="libSystem.Security.Cryptography.Native.Apple" />
240+
<DirectPInvokes Include="libbrotlienc;libbrotlidec" />
240241
</ItemGroup>
241242

242243
<PropertyGroup>
@@ -274,7 +275,7 @@
274275
<Target Name="_AppleNativeAotCompile"
275276
DependsOnTargets="SetupProperties;ComputeIlcCompileInputs;IlcCompile;$(_IlcLibraryBuildDependsOn)" />
276277

277-
<Target Name="_AppleGenerateAppBundle"
278+
<Target Name="_AppleGenerateAppBundle"
278279
Condition="'$(AppleGenerateAppBundle)' == 'true'"
279280
DependsOnTargets="_AppleGenerateRuntimeConfig">
280281
<!-- Run App bundler, it uses AOT libs (if needed), link all native bits, compile simple UI (written in ObjC)
@@ -336,7 +337,7 @@
336337
</Target>
337338

338339
<Target Name="_AfterAppleBuild">
339-
340+
340341
</Target>
341342

342343
<Target Name="_AppleGenerateRuntimeConfig"
@@ -355,4 +356,4 @@
355356
RuntimeConfigReservedProperties="@(_RuntimeConfigReservedProperties)">
356357
</RuntimeConfigParserTask>
357358
</Target>
358-
</Project>
359+
</Project>

src/native/corehost/apphost/static/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ if(CLR_CMAKE_TARGET_WIN32)
153153
delayimp.lib
154154
)
155155

156+
# additional requirements for System.IO.Compression.Native
157+
include(${CLR_SRC_NATIVE_DIR}/libs/System.IO.Compression.Native/extra_libs.cmake)
158+
append_extra_compression_libs(NATIVE_LIBS)
159+
156160
set(RUNTIMEINFO_LIB runtimeinfo)
157161

158162
else()
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
1.1.0
22
https://github.com/google/brotli/releases/tag/v1.1.0
33

4-
Copy the c/dec, c/enc, c/common, and c/include folders into the root and remove all other files.
5-
6-
Apply https://github.com/google/brotli/commit/85d88cbfc2b742e0742286ec277b73bdbf7be433.patch
4+
Deleted tests, python, docs folders
5+
Apply https://github.com/google/brotli/commit/85d88cbfc2b742e0742286ec277b73bdbf7be433.patch

src/native/external/brotli.cmake

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

3-
include_directories(BEFORE "${CMAKE_CURRENT_LIST_DIR}/brotli/include")
3+
include(FetchContent)
44

5-
set (BROTLI_SOURCES_BASE
6-
common/constants.c
7-
common/context.c
8-
common/dictionary.c
9-
common/platform.c
10-
common/shared_dictionary.c
11-
common/transform.c
12-
dec/bit_reader.c
13-
dec/decode.c
14-
dec/huffman.c
15-
dec/state.c
16-
enc/backward_references.c
17-
enc/backward_references_hq.c
18-
enc/bit_cost.c
19-
enc/block_splitter.c
20-
enc/brotli_bit_stream.c
21-
enc/cluster.c
22-
enc/command.c
23-
enc/compound_dictionary.c
24-
enc/compress_fragment.c
25-
enc/compress_fragment_two_pass.c
26-
enc/dictionary_hash.c
27-
enc/encode.c
28-
enc/encoder_dict.c
29-
enc/entropy_encode.c
30-
enc/fast_log.c
31-
enc/histogram.c
32-
enc/literal_cost.c
33-
enc/memory.c
34-
enc/metablock.c
35-
enc/static_dict.c
36-
enc/utf8_util.c
5+
FetchContent_Declare(
6+
brotli
7+
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/brotli
378
)
389

39-
addprefix(BROTLI_SOURCES "${CMAKE_CURRENT_LIST_DIR}/brotli" "${BROTLI_SOURCES_BASE}")
10+
set(BROTLI_DISABLE_TESTS ON)
11+
set(__CURRENT_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
12+
set(BUILD_SHARED_LIBS OFF)
13+
FetchContent_MakeAvailable(brotli)
14+
set(BUILD_SHARED_LIBS ${__CURRENT_BUILD_SHARED_LIBS})
15+
16+
target_compile_options(brotlicommon PRIVATE $<$<COMPILE_LANG_AND_ID:C,MSVC>:/guard:cf>)
17+
target_compile_options(brotlienc PRIVATE $<$<COMPILE_LANG_AND_ID:C,MSVC>:/guard:cf>)
18+
target_compile_options(brotlidec PRIVATE $<$<COMPILE_LANG_AND_ID:C,MSVC>:/guard:cf>)
19+
target_compile_options(brotlienc PRIVATE $<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang,GNU>:-Wno-implicit-fallthrough>)
20+
target_compile_options(brotlidec PRIVATE $<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang,GNU>:-Wno-implicit-fallthrough>)
21+
22+
# Even though we aren't building brotli as shared libraries, we still need to be able to export the symbols
23+
# from the brotli libraries so that they can be used by System.IO.Compression.
24+
# Since we link all of the static libraries into a single shared library, we need to define BROTLICOMMON_SHARED_COMPILATION
25+
# for all targets so brotlienc and brotlidec don't expect to link against a separate brotlicommon shared library.
26+
target_compile_definitions(brotlienc PRIVATE BROTLI_SHARED_COMPILATION BROTLIENC_SHARED_COMPILATION BROTLICOMMON_SHARED_COMPILATION)
27+
target_compile_definitions(brotlidec PRIVATE BROTLI_SHARED_COMPILATION BROTLIDEC_SHARED_COMPILATION BROTLICOMMON_SHARED_COMPILATION)
28+
target_compile_definitions(brotlicommon PRIVATE BROTLI_SHARED_COMPILATION BROTLICOMMON_SHARED_COMPILATION)
29+
30+
# Don't build the brotli command line tool unless explicitly requested
31+
# (which we never do)
32+
set_target_properties(brotli PROPERTIES EXCLUDE_FROM_ALL ON)

0 commit comments

Comments
 (0)