Skip to content

Commit ed6ef79

Browse files
authored
Add brotli support to FoundationNetworking (#83441)
<!-- If this pull request is targeting a release branch, please fill out the following form: https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1 Otherwise, replace this comment with a description of your changes and rationale. Provide links to external references/discussions if appropriate. If this pull request resolves any GitHub issues, link them like so: Resolves <link to issue>, resolves <link to another issue>. For more information about linking a pull request to an issue, see: https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue --> <!-- Before merging this pull request, you must run the Swift continuous integration tests. For information about triggering CI builds via @swift-ci, see: https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci Thank you for your contribution to Swift! --> 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
1 parent db21bc2 commit ed6ef79

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

utils/build.ps1

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ enum Project {
861861
SourceKitLSP
862862
SymbolKit
863863
DocC
864+
brotli
864865

865866
LLVM
866867
Runtime
@@ -2474,6 +2475,21 @@ function Build-CompilerRuntime([Hashtable] $Platform) {
24742475
}
24752476
}
24762477

2478+
function Build-Brotli([Hashtable] $Platform) {
2479+
Build-CMakeProject `
2480+
-Src $SourceCache\brotli `
2481+
-Bin "$(Get-ProjectBinaryCache $Platform brotli)" `
2482+
-InstallTo "$BinaryCache\$($Platform.Triple)\usr" `
2483+
-Platform $Platform `
2484+
-UseMSVCCompilers C `
2485+
-Defines @{
2486+
BUILD_SHARED_LIBS = "NO";
2487+
CMAKE_POSITION_INDEPENDENT_CODE = "YES";
2488+
CMAKE_SYSTEM_NAME = $Platform.OS.ToString();
2489+
}
2490+
}
2491+
2492+
24772493
function Build-ZLib([Hashtable] $Platform) {
24782494
Build-CMakeProject `
24792495
-Src $SourceCache\zlib `
@@ -2562,7 +2578,7 @@ function Build-CURL([Hashtable] $Platform) {
25622578
CURL_CA_BUNDLE = "none";
25632579
CURL_CA_FALLBACK = "NO";
25642580
CURL_CA_PATH = "none";
2565-
CURL_BROTLI = "NO";
2581+
CURL_BROTLI = "YES";
25662582
CURL_DISABLE_ALTSVC = "NO";
25672583
CURL_DISABLE_AWS = "YES";
25682584
CURL_DISABLE_BASIC_AUTH = "NO";
@@ -2640,6 +2656,7 @@ function Build-CURL([Hashtable] $Platform) {
26402656
USE_WIN32_LDAP = "NO";
26412657
ZLIB_ROOT = "$BinaryCache\$($Platform.Triple)\usr";
26422658
ZLIB_LIBRARY = "$BinaryCache\$($Platform.Triple)\usr\lib\zlibstatic.lib";
2659+
BROTLI_DIR = "$BinaryCache\$($Platform.Triple)\usr";
26432660
})
26442661
}
26452662

@@ -3039,6 +3056,7 @@ function Build-Foundation([Hashtable] $Platform) {
30393056
};
30403057
ZLIB_INCLUDE_DIR = "$BinaryCache\$($Platform.Triple)\usr\include";
30413058
dispatch_DIR = (Get-ProjectCMakeModules $Platform Dispatch);
3059+
BROTLI_DIR = "$BinaryCache\$($Platform.Triple)\usr";
30423060
_SwiftFoundation_SourceDIR = "$SourceCache\swift-foundation";
30433061
_SwiftFoundationICU_SourceDIR = "$SourceCache\swift-foundation-icu";
30443062
_SwiftCollections_SourceDIR = "$SourceCache\swift-collections";
@@ -3063,6 +3081,7 @@ function Test-Foundation {
30633081
$env:LIBXML_LIBRARY_PATH="$BinaryCache/$($Platform.Triple)/usr/lib"
30643082
$env:LIBXML_INCLUDE_PATH="$BinaryCache/$($Platform.Triple)/usr/include/libxml2"
30653083
$env:ZLIB_LIBRARY_PATH="$BinaryCache/$($Platform.Triple)/usr/lib"
3084+
$env:BROTLI_LIBRARY_PATH="$BinaryCache/$($Platform.Triple)/usr/lib"
30663085
$env:CURL_LIBRARY_PATH="$BinaryCache/$($Platform.Triple)/usr/lib"
30673086
$env:CURL_INCLUDE_PATH="$BinaryCache/$($Platform.Triple)/usr/include"
30683087
Build-SPMProject `
@@ -4113,6 +4132,7 @@ if (-not $SkipBuild) {
41134132
}
41144133

41154134
Invoke-BuildStep Build-ZLib $Build
4135+
Invoke-BuildStep Build-Brotli $Build
41164136
Invoke-BuildStep Build-XML2 $Build
41174137
Invoke-BuildStep Build-CURL $Build
41184138
}

utils/swift_build_support/swift_build_support/products/curl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def build(self, host_target):
110110
self.cmake_options.define('CURL_DISABLE_SMTP', 'YES')
111111
self.cmake_options.define('CURL_DISABLE_GOPHER', 'YES')
112112
self.cmake_options.define('CURL_ZLIB', 'YES')
113+
self.cmake_options.define('CURL_BROTLI', 'YES')
113114
self.cmake_options.define('ENABLE_CURL_MANUAL', 'NO')
114115
self.cmake_options.define('ENABLE_UNIX_SOCKETS', 'NO')
115116
self.cmake_options.define('ENABLE_THREADED_RESOLVER', 'NO')

utils/update_checkout/update-checkout-config.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@
118118
"zlib": {
119119
"remote": { "id": "madler/zlib" }
120120
},
121+
"brotli": {
122+
"remote": { "id": "google/brotli" }
123+
},
121124
"mimalloc": {
122125
"remote": { "id": "microsoft/mimalloc" },
123126
"platforms": [ "Windows" ]
@@ -180,6 +183,7 @@
180183
"curl": "curl-8_9_1",
181184
"libxml2": "v2.11.5",
182185
"zlib": "v1.3.1",
186+
"brotli": "v1.1.0",
183187
"mimalloc": "v3.0.3",
184188
"swift-subprocess": "0.1"
185189
}
@@ -291,6 +295,7 @@
291295
"curl": "curl-8_9_1",
292296
"libxml2": "v2.11.5",
293297
"zlib": "v1.3.1",
298+
"brotli": "v1.1.0",
294299
"mimalloc": "v3.0.1"
295300
}
296301
},
@@ -608,6 +613,7 @@
608613
"curl": "curl-8_9_1",
609614
"libxml2": "v2.11.5",
610615
"zlib": "v1.3.1",
616+
"brotli": "v1.1.0",
611617
"mimalloc": "v3.0.3",
612618
"swift-subprocess": "0.1"
613619
}
@@ -666,6 +672,7 @@
666672
"curl": "curl-8_9_1",
667673
"libxml2": "v2.11.5",
668674
"zlib": "v1.3.1",
675+
"brotli": "v1.1.0",
669676
"mimalloc": "v3.0.3",
670677
"swift-subprocess": "0.1"
671678
}

0 commit comments

Comments
 (0)