From 5c06c38cca04e41b17279344c1515f126afdb0b2 Mon Sep 17 00:00:00 2001 From: poly-jeff Date: Tue, 21 Jul 2026 13:39:20 -0400 Subject: [PATCH] fix: guard gzip pool behind canImport(zlib) for non-Darwin host builds The non-Darwin Swift toolchain used for Android/Skip host builds (skip export's x86_64-unknown-linux-gnu pass) has no `zlib` module, so the unconditional `import zlib` broke compilation. Gate the import and the gzip compress/decompress bodies behind `canImport(zlib)`, throwing `GzipError.unsupportedPlatform` on platforms where zlib is unavailable. Apple platforms are unaffected. Co-authored-by: Cursor --- .../Compression/GzipCompressionPool.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Libraries/Connect/Public/Implementation/Compression/GzipCompressionPool.swift b/Libraries/Connect/Public/Implementation/Compression/GzipCompressionPool.swift index 7a523832..f15423d0 100644 --- a/Libraries/Connect/Public/Implementation/Compression/GzipCompressionPool.swift +++ b/Libraries/Connect/Public/Implementation/Compression/GzipCompressionPool.swift @@ -13,7 +13,9 @@ // limitations under the License. import Foundation +#if canImport(zlib) import zlib +#endif /// Compression pool that handles gzip compression/decompression. public struct GzipCompressionPool: Sendable { @@ -22,6 +24,10 @@ public struct GzipCompressionPool: Sendable { public enum GzipError: Error { case failedToInitialize case failedToFinish + /// Thrown on platforms where `zlib` is unavailable (e.g. the non-Darwin Swift + /// toolchain used for Android/Skip host builds), so gzip callers fail loudly + /// rather than the whole module failing to compile. + case unsupportedPlatform } } @@ -30,6 +36,7 @@ extension GzipCompressionPool: CompressionPool { return "gzip" } +#if canImport(zlib) public func compress(data: Data) throws -> Data { if data.isEmpty || data.isGzipped() { return data @@ -135,6 +142,15 @@ extension GzipCompressionPool: CompressionPool { output.count = Int(stream.total_out) return output } +#else + public func compress(data: Data) throws -> Data { + throw GzipError.unsupportedPlatform + } + + public func decompress(data: Data) throws -> Data { + throw GzipError.unsupportedPlatform + } +#endif } private extension Data {