-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Put brotli on the FetchContent plan #107166
base: main
Are you sure you want to change the base?
Changes from 8 commits
fba095d
75c20c1
c46e058
ff875b8
a8f604c
e1c1d10
199888a
0f8202b
d717e9d
72de3b8
72bc9f8
81e5520
e9896c9
599dc91
a575d28
3bddbf5
9087c81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ The .NET Foundation licenses this file to you under the MIT license. | |
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'linux'">bfd</LinkerFlavor> | ||
<IlcDefaultStackSize Condition="'$(IlcDefaultStackSize)' == '' and '$(_linuxLibcFlavor)' == 'musl'">1572864</IlcDefaultStackSize> | ||
<UseSystemZlib Condition="'$(UseSystemZlib)' == '' and !Exists('$(IlcSdkPath)libz.a')">true</UseSystemZlib> | ||
<!-- Use libbrotlicommon.a as the sentinel for the three brotli libs. --> | ||
<UseSystemBrotli Condition="'$(UseSystemBrotli)' == '' and !Exists('$(IlcSdkPath)libbrotlicommon.a')">true</UseSystemBrotli> | ||
</PropertyGroup> | ||
|
||
<Target Name="SetupOSSpecificProps" DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)"> | ||
|
@@ -155,6 +157,14 @@ The .NET Foundation licenses this file to you under the MIT license. | |
<NativeLibrary Condition="'$(UseSystemZlib)' != 'true'" Include="$(IlcSdkPath)libz.a" /> | ||
</ItemGroup> | ||
|
||
<!-- brotli must be added after System.IO.Compression.Native and brotlicommon must be added last, order matters. --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was there a reason to move this ItemGroup from line 171 to here? I suspect something about the ItemGroup in line 168 was causing trouble. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had just added the itemgroup here initially before @agocke did the implementation that uses |
||
<ItemGroup Condition="'$(UseSystemBrotli)' != 'true'"> | ||
<NativeLibrary Include="$(IlcSdkPath)libbrotlienc.a" /> | ||
<NativeLibrary Include="$(IlcSdkPath)libbrotlidec.a" /> | ||
<NativeLibrary Include="$(IlcSdkPath)libbrotlicommon.a" /> | ||
</ItemGroup> | ||
|
||
|
||
<ItemGroup Condition="'$(StaticICULinking)' == 'true' and '$(NativeLib)' != 'Static' and '$(InvariantGlobalization)' != 'true'"> | ||
<NativeLibrary Include="$(IntermediateOutputPath)libs/System.Globalization.Native/build/libSystem.Globalization.Native.a" /> | ||
<DirectPInvoke Include="libSystem.Globalization.Native" /> | ||
|
@@ -192,6 +202,7 @@ The .NET Foundation licenses this file to you under the MIT license. | |
<NativeSystemLibrary Include="swiftCore" Condition="'$(_IsApplePlatform)' == 'true'" /> | ||
<NativeSystemLibrary Include="swiftFoundation" Condition="'$(_IsApplePlatform)' == 'true'" /> | ||
<NativeSystemLibrary Include="z" Condition="'$(UseSystemZlib)' == 'true'" /> | ||
<NativeSystemLibrary Include="brotlienc;brotlidec;brotlicommon" Condition="'$(UseSystemBrotli)' == 'true'" /> | ||
<NativeSystemLibrary Include="rt" Condition="'$(_IsApplePlatform)' != 'true' and '$(_linuxLibcFlavor)' != 'bionic'" /> | ||
<NativeSystemLibrary Include="log" Condition="'$(_linuxLibcFlavor)' == 'bionic'" /> | ||
<NativeSystemLibrary Include="icucore" Condition="'$(_IsApplePlatform)' == 'true'" /> | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -47,6 +47,9 @@ The .NET Foundation licenses this file to you under the MIT license. | |||||||||||||
<NativeLibrary Condition="'$(IlcMultiModule)' == 'true'" Include="$(SharedLibrary)" /> | ||||||||||||||
<NativeLibrary Include="$(IlcSdkPath)$(StandaloneGCSupportName)$(LibrarySuffix)" /> | ||||||||||||||
<NativeLibrary Include="$(IlcSdkPath)zlibstatic$(LibFileExt)" /> | ||||||||||||||
<NativeLibrary Include="$(IlcSdkPath)brotlicommon$(LibFileExt)" /> | ||||||||||||||
<NativeLibrary Include="$(IlcSdkPath)brotlienc$(LibFileExt)" /> | ||||||||||||||
<NativeLibrary Include="$(IlcSdkPath)brotlidec$(LibFileExt)" /> | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we build .NET with system brotli, we don't include broticommon: runtime/src/native/libs/System.IO.Compression.Native/extra_libs.cmake Lines 23 to 28 in f0405a9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When building against system brotli, brotlicommon is a private dependency of the brotlienc and brotlidec shared libraries, so it can be omitted. When statically linking, we need to specify all three. |
||||||||||||||
</ItemGroup> | ||||||||||||||
|
||||||||||||||
<ItemGroup> | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
1.1.0 | ||
https://github.com/google/brotli/releases/tag/v1.1.0 | ||
|
||
Copy the c/dec, c/enc, c/common, and c/include folders into the root and remove all other files. | ||
|
||
Apply https://github.com/google/brotli/commit/85d88cbfc2b742e0742286ec277b73bdbf7be433.patch | ||
Deleted tests, python, docs folders | ||
Apply https://github.com/google/brotli/commit/85d88cbfc2b742e0742286ec277b73bdbf7be433.patch |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,15 @@ | ||
# IMPORTANT: do not use add_compile_options(), add_definitions() or similar functions here since it will leak to the including projects | ||
include(FetchContent) | ||
|
||
include_directories(BEFORE "${CMAKE_CURRENT_LIST_DIR}/brotli/include") | ||
|
||
set (BROTLI_SOURCES_BASE | ||
common/constants.c | ||
common/context.c | ||
common/dictionary.c | ||
common/platform.c | ||
common/shared_dictionary.c | ||
common/transform.c | ||
dec/bit_reader.c | ||
dec/decode.c | ||
dec/huffman.c | ||
dec/state.c | ||
enc/backward_references.c | ||
enc/backward_references_hq.c | ||
enc/bit_cost.c | ||
enc/block_splitter.c | ||
enc/brotli_bit_stream.c | ||
enc/cluster.c | ||
enc/command.c | ||
enc/compound_dictionary.c | ||
enc/compress_fragment.c | ||
enc/compress_fragment_two_pass.c | ||
enc/dictionary_hash.c | ||
enc/encode.c | ||
enc/encoder_dict.c | ||
enc/entropy_encode.c | ||
enc/fast_log.c | ||
enc/histogram.c | ||
enc/literal_cost.c | ||
enc/memory.c | ||
enc/metablock.c | ||
enc/static_dict.c | ||
enc/utf8_util.c | ||
FetchContent_Declare( | ||
brotli | ||
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/brotli | ||
) | ||
|
||
addprefix(BROTLI_SOURCES "${CMAKE_CURRENT_LIST_DIR}/brotli" "${BROTLI_SOURCES_BASE}") | ||
set(BROTLI_DISABLE_TESTS ON) | ||
set(__CURRENT_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget to run all the exotic azp runs: runtime-community, runtime-extra-platforms, the nativeaot and wasm ones. They might capture some interesting error messages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once I have regular CI working I'll make sure to do so. |
||
set(BUILD_SHARED_LIBS OFF) | ||
FetchContent_MakeAvailable(brotli) | ||
set(BUILD_SHARED_LIBS ${__CURRENT_BUILD_SHARED_LIBS}) | ||
target_compile_options(brotlicommon PRIVATE $<$<COMPILE_LANG_AND_ID:C,MSVC>:/guard:cf>) | ||
target_compile_options(brotlienc PRIVATE $<$<COMPILE_LANG_AND_ID:C,MSVC>:/guard:cf>) | ||
target_compile_options(brotlidec PRIVATE $<$<COMPILE_LANG_AND_ID:C,MSVC>:/guard:cf>) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can keep custom code out of the vendor's directory (so it looks as close to the upstream as possible). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Bazel file is from upstream. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
# Description: | ||
# Brotli is a generic-purpose lossless compression algorithm. | ||
|
||
load(":compiler_config_setting.bzl", "create_msvc_config") | ||
|
||
package( | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
licenses(["notice"]) # MIT | ||
|
||
exports_files(["LICENSE"]) | ||
|
||
config_setting( | ||
name = "darwin", | ||
values = {"cpu": "darwin"}, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
config_setting( | ||
name = "darwin_x86_64", | ||
values = {"cpu": "darwin_x86_64"}, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
config_setting( | ||
name = "windows", | ||
values = {"cpu": "x64_windows"}, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
config_setting( | ||
name = "windows_msvc", | ||
values = {"cpu": "x64_windows_msvc"}, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
config_setting( | ||
name = "windows_msys", | ||
values = {"cpu": "x64_windows_msys"}, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
create_msvc_config() | ||
|
||
STRICT_C_OPTIONS = select({ | ||
":msvc": [], | ||
":clang-cl": [ | ||
"/W4", | ||
"-Wconversion", | ||
"-Wlong-long", | ||
"-Wmissing-declarations", | ||
"-Wmissing-prototypes", | ||
"-Wno-strict-aliasing", | ||
"-Wshadow", | ||
"-Wsign-compare", | ||
"-Wno-sign-conversion", | ||
], | ||
"//conditions:default": [ | ||
"--pedantic-errors", | ||
"-Wall", | ||
"-Wconversion", | ||
"-Werror", | ||
"-Wextra", | ||
"-Wlong-long", | ||
"-Wmissing-declarations", | ||
"-Wmissing-prototypes", | ||
"-Wno-strict-aliasing", | ||
"-Wshadow", | ||
"-Wsign-compare", | ||
], | ||
}) | ||
|
||
filegroup( | ||
name = "public_headers", | ||
srcs = glob(["c/include/brotli/*.h"]), | ||
) | ||
|
||
filegroup( | ||
name = "common_headers", | ||
srcs = glob(["c/common/*.h"]), | ||
) | ||
|
||
filegroup( | ||
name = "common_sources", | ||
srcs = glob(["c/common/*.c"]), | ||
) | ||
|
||
filegroup( | ||
name = "dec_headers", | ||
srcs = glob(["c/dec/*.h"]), | ||
) | ||
|
||
filegroup( | ||
name = "dec_sources", | ||
srcs = glob(["c/dec/*.c"]), | ||
) | ||
|
||
filegroup( | ||
name = "enc_headers", | ||
srcs = glob(["c/enc/*.h"]), | ||
) | ||
|
||
filegroup( | ||
name = "enc_sources", | ||
srcs = glob(["c/enc/*.c"]), | ||
) | ||
|
||
cc_library( | ||
name = "brotli_inc", | ||
hdrs = [":public_headers"], | ||
copts = STRICT_C_OPTIONS, | ||
strip_include_prefix = "c/include", | ||
) | ||
|
||
cc_library( | ||
name = "brotlicommon", | ||
srcs = [":common_sources"], | ||
hdrs = [":common_headers"], | ||
copts = STRICT_C_OPTIONS, | ||
deps = [":brotli_inc"], | ||
) | ||
|
||
cc_library( | ||
name = "brotlidec", | ||
srcs = [":dec_sources"], | ||
hdrs = [":dec_headers"], | ||
copts = STRICT_C_OPTIONS, | ||
deps = [":brotlicommon"], | ||
) | ||
|
||
cc_library( | ||
name = "brotlienc", | ||
srcs = [":enc_sources"], | ||
hdrs = [":enc_headers"], | ||
copts = STRICT_C_OPTIONS, | ||
linkopts = select({ | ||
":clang-cl": [], | ||
":msvc": [], | ||
"//conditions:default": ["-lm"], | ||
}), | ||
deps = [":brotlicommon"], | ||
) | ||
|
||
cc_binary( | ||
name = "brotli", | ||
srcs = ["c/tools/brotli.c"], | ||
copts = STRICT_C_OPTIONS, | ||
linkstatic = 1, | ||
deps = [ | ||
":brotlidec", | ||
":brotlienc", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "dictionary", | ||
srcs = ["c/common/dictionary.bin"], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and simple! 👍