Skip to content

Add brotli support to FoundationNetworking #83441

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zhenchaoli
Copy link

@zhenchaoli zhenchaoli commented Jul 30, 2025

Add brotli as a dependency to enable brotli decoding for curl.

brotli is a general purpose compression algorithm used extensively on web. (https://datatracker.ietf.org/doc/html/rfc7932)

brotli support for curl is enabled by integrating the brotli compression library (https://github.com/google/brotli). I've also added some tests for FoundationNetworking in swiftlang/swift-corelibs-foundation#5251 which exercises this feature by

  • looking at the accept-encoding http header
  • decoding a brotli encoded payload

@zhenchaoli
Copy link
Author

swiftlang/swift-corelibs-foundation#5251

@swift-ci Please clean test

@zhenchaoli
Copy link
Author

Seems windows ci passed. Linux failed due to test compilation error. I've added one more commit to enable test on Linux for swiftlang/swift-corelibs-foundation#5251

@zhenchaoli
Copy link
Author

swiftlang/swift-corelibs-foundation#5251

@swift-ci Please clean test

1 similar comment
@zhenchaoli
Copy link
Author

swiftlang/swift-corelibs-foundation#5251

@swift-ci Please clean test

@zhenchaoli
Copy link
Author

Linux test failure should be fixed now on swiftlang/swift-corelibs-foundation#5251

@zhenchaoli
Copy link
Author

swiftlang/swift-corelibs-foundation#5251

@swift-ci Please clean test

@zhenchaoli
Copy link
Author

swiftlang/swift-corelibs-foundation#5251

@swift-ci Please clean test Linux platform

@zhenchaoli zhenchaoli force-pushed the zcli/brotli branch 3 times, most recently from cf08366 to 39f056b Compare August 2, 2025 02:21
@zhenchaoli
Copy link
Author

rebased.

swiftlang/swift-corelibs-foundation#5251

@swift-ci Please clean test

@zhenchaoli zhenchaoli changed the title Add brotli support to FoundationNetworking [WIP] Add brotli support to FoundationNetworking Aug 3, 2025
Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

It would be nice to get a bit more background on what is being done and why.

Build-CMakeProject `
-Src $SourceCache\brotli `
-Bin "$BinaryCache\$($Platform.Triple)\brotli" `
-InstallTo "$BinaryCache\$($Platform.Triple)\usr" `
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to install it? Can we not use it from the build tree?

Copy link
Author

Choose a reason for hiding this comment

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

I'm following the example of zlib here, and it feels cleaner to rely on build artifacts being in a consistent place for all dependency outputs. It seems all other dependencies already do this, so I think we should be consistent. (Maybe let's do these kind of changes in a separate PR for all dependencies if you feel strongly about it)

Copy link
Member

@compnerd compnerd Aug 6, 2025

Choose a reason for hiding this comment

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

zlib is the only one doing this because it cannot be used from the build tree (I would love to migrate to that model for zlib as well). We no longer install any library which is not being distributed as a DLL - but that requires switching to the master branch rather than a release.

Copy link
Author

@zhenchaoli zhenchaoli Aug 6, 2025

Choose a reason for hiding this comment

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

Just to be clear, by "use it from the build tree", we'll be referencing .lib object files in brotli build tree like brotli\out\Release\brotlicommon.lib, and header files in its source tree at paths like brotli\c\include\brotli\decode.h?
I could try but I doubt it'll play well with the goal in the other comment which is using Brotli_DIR.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, except, the idea with Brotli_DIR is that you tell CMake the directory to look into for BrotliConfig.cmake and it will wire up the headers and libraries appropriately. You don't need to pass flags or paths to the libraries or headers.

@@ -2334,6 +2349,8 @@ function Build-CURL([Hashtable] $Platform) {
USE_WIN32_LDAP = "NO";
ZLIB_ROOT = "$BinaryCache\$($Platform.Triple)\usr";
ZLIB_LIBRARY = "$BinaryCache\$($Platform.Triple)\usr\lib\zlibstatic.lib";
BROTLIDEC_LIBRARY = "$BinaryCache\$($Platform.Triple)\usr\lib\brotlidec.lib"
BROTLICOMMON_LIBRARY = "$BinaryCache\$($Platform.Triple)\usr\lib\brotlicommon.lib"
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to pass in the library paths or do they generate a config file that we can use with Brotli_DIR?

Copy link
Author

Choose a reason for hiding this comment

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

The build output of brotli does include 3 .pc files, but unsure how well curl supports BROTLI_DIR. The input variables for curl's brotli cmake are BROTLI_INCLUDE_DIR, BROTLICOMMON_LIBRARY, BROTLIDEC_LIBRARY according to https://github.com/curl/curl/blob/master/CMake/FindBrotli.cmake

Copy link
Member

Choose a reason for hiding this comment

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

The .pc files are for pkg-config, which we do not use or support as that is not something that is available on Windows by default. https://github.com/curl/curl/blob/master/CMake/FindBrotli.cmake#L62-L68 is the bit that matters - it should hopefully allow us to specify just the _DIR suffixed variable to find everything.

@compnerd compnerd added the Windows Platform: Windows label Aug 4, 2025
@zhenchaoli
Copy link
Author

It would be nice to get a bit more background on what is being done and why.

Updated the overview for this PR. Let me know if any details are missing.

@zhenchaoli
Copy link
Author

swiftlang/swift-corelibs-foundation#5251

@swift-ci Please clean test

@zhenchaoli zhenchaoli requested a review from compnerd August 6, 2025 18:14
@zhenchaoli
Copy link
Author

@compnerd is https://github.com/swiftlang/swift/blob/main/docs/WindowsBuild.md the best way to go about testing the build on Windows? So far I've been relying on the CI for the toolchain side of changes.

@compnerd
Copy link
Member

compnerd commented Aug 7, 2025

@compnerd is https://github.com/swiftlang/swift/blob/main/docs/WindowsBuild.md the best way to go about testing the build on Windows? So far I've been relying on the CI for the toolchain side of changes.

No, I would suggest that you reference https://github.com/compnerd/swift-build/blob/main/docs/WindowsQuickStart.md. It is much simpler and up-to-date. The use of repo is what keeps me from merging that into the tree.

@zhenchaoli
Copy link
Author

@compnerd is https://github.com/swiftlang/swift/blob/main/docs/WindowsBuild.md the best way to go about testing the build on Windows? So far I've been relying on the CI for the toolchain side of changes.

No, I would suggest that you reference https://github.com/compnerd/swift-build/blob/main/docs/WindowsQuickStart.md. It is much simpler and up-to-date. The use of repo is what keeps me from merging that into the tree.

unfortunately the build did not go very far for me while following the instructions:

-- The Swift compiler identification is unknown
CMake Error at S:/SourceCache/swift/CMakeLists.txt:108 (enable_language):
  The CMAKE_Swift_COMPILER:

    S:/b/toolchains/swift-6.1.2-RELEASE-windows10/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr/bin/swiftc.exe

  is not a full path to an existing compiler tool.

  Tell CMake where to find the compiler by setting either the environment
  variable "SWIFTC" or the CMake cache entry CMAKE_Swift_COMPILER to the full
  path to the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!

I looked at the path and don't see swiftc.exe there. Instead it's a nested folders S:\b\toolchains\swift-6.1.2-RELEASE-windows10\LocalApp\Programs\Swift\Runtimes\6.1.2\usr\bin that contains nothing.

Is there anything obvious I'm missing?

@compnerd
Copy link
Member

compnerd commented Aug 7, 2025

I think that a small optimization that matters for local development is biting you. We don't re-extract the toolchain, and I suspect that the extraction failed in the first run. Try again adding -Clean and if that run fails (i.e. the extraction fails) you might be missing the .NET runtime which is needed for the extraction.

@zhenchaoli
Copy link
Author

Very likely to be the case. I just installed the .NET runtime and retrying. Separately when you get a chance, would you also mind taking a look at my questions above: #83441 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Windows Platform: Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants