Skip to content
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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
fba095d
Upgrade brotli from v1.0.9 to v1.1.0 but do a full repo copy
jkoritzinsky May 29, 2024
75c20c1
Delete unused subfolders
jkoritzinsky May 29, 2024
c46e058
Integrate FetchContent-based discovery with system-brotli discovery v…
jkoritzinsky May 29, 2024
ff875b8
Update cg manifest
jkoritzinsky Aug 23, 2024
a8f604c
Hook up brotli linkage and NativeAOT targets
jkoritzinsky Aug 29, 2024
e1c1d10
Apply patch for MSVC warning
jkoritzinsky Aug 29, 2024
199888a
Merge branch 'main' of github.com:dotnet/runtime into brotli-upgrade
jkoritzinsky Aug 29, 2024
0f8202b
Link against brotli on non-Windows
jkoritzinsky Aug 30, 2024
d717e9d
Set the flags for brotli to allow exporting the brotli symbols from C…
jkoritzinsky Aug 30, 2024
72de3b8
Set export flags for brotlicommon and don't build the brotli target b…
jkoritzinsky Sep 3, 2024
72bc9f8
Try putting the brotli files eveywhere necessary for our various plat…
jkoritzinsky Sep 10, 2024
81e5520
Build brotlienc and brotlidec to expect to be statically linked again…
jkoritzinsky Sep 10, 2024
e9896c9
Try installing in the libs partition instead of pulling from the Nati…
jkoritzinsky Sep 10, 2024
599dc91
Revert "Use system brotli on Unix non-portable builds (#107225)"
jkoritzinsky Sep 11, 2024
a575d28
Merge commit '599dc9149e9' into brotli-upgrade
jkoritzinsky Sep 11, 2024
3bddbf5
Add to platform manifest
jkoritzinsky Sep 12, 2024
9087c81
Merge branch 'main' of https://github.com/dotnet/runtime into brotli-…
jkoritzinsky Sep 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and simple! 👍

</PropertyGroup>

<Target Name="SetupOSSpecificProps" DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)">
Expand Down Expand Up @@ -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. -->
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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 nonportable.txt. I didn't move it down when I merged in his changes as I just immediately reverted them (as my changes are a replacement for the nonportable.txt workflow).

<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" />
Expand Down Expand Up @@ -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'" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we build .NET with system brotli, we don't include broticommon:

if (CLR_CMAKE_USE_SYSTEM_BROTLI)
find_library(BROTLIDEC brotlidec REQUIRED)
find_library(BROTLIENC brotlienc REQUIRED)
list(APPEND ${NativeLibsExtra} ${BROTLIDEC} ${BROTLIENC})
endif ()

Copy link
Member Author

Choose a reason for hiding this comment

The 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>
Expand Down
4 changes: 4 additions & 0 deletions src/native/corehost/apphost/static/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ if(CLR_CMAKE_TARGET_WIN32)
delayimp.lib
)

# additional requirements for System.IO.Compression.Native
include(${CLR_SRC_NATIVE_DIR}/libs/System.IO.Compression.Native/extra_libs.cmake)
append_extra_compression_libs(NATIVE_LIBS)

set(RUNTIMEINFO_LIB runtimeinfo)

else()
Expand Down
5 changes: 2 additions & 3 deletions src/native/external/brotli-version.txt
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
48 changes: 12 additions & 36 deletions src/native/external/brotli.cmake
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})
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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>)
159 changes: 159 additions & 0 deletions src/native/external/brotli/BUILD.bazel
Copy link
Member

Choose a reason for hiding this comment

The 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).

Copy link
Member Author

Choose a reason for hiding this comment

The 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"],
)
Loading
Loading