Skip to content

vendor zlib instead of relying on system version#306

Merged
weissi merged 1 commit intoapple:mainfrom
weissi:jw-vendor-zlib
Feb 26, 2026
Merged

vendor zlib instead of relying on system version#306
weissi merged 1 commit intoapple:mainfrom
weissi:jw-vendor-zlib

Conversation

@weissi
Copy link
Copy Markdown
Member

@weissi weissi commented Feb 25, 2026

Motivation:

Relying on the system zlib causes issues if that library (or its headers) doesn't ship with the system.

Modifications:

Vendor it.

Result:

  • Fewer dependencies.
  • Binary size increase negligible. The sum of the debug builds of all .o files is less than 200kB. A linked release build will make this even smaller:
$ du -k .build/arm64-apple-macosx/debug/CNIOExtrasZlib.build/*.o
12	.build/arm64-apple-macosx/debug/CNIOExtrasZlib.build/adler32.c.o
12	.build/arm64-apple-macosx/debug/CNIOExtrasZlib.build/crc32.c.o
60	.build/arm64-apple-macosx/debug/CNIOExtrasZlib.build/deflate.c.o
16	.build/arm64-apple-macosx/debug/CNIOExtrasZlib.build/inffast.c.o
40	.build/arm64-apple-macosx/debug/CNIOExtrasZlib.build/inflate.c.o
16	.build/arm64-apple-macosx/debug/CNIOExtrasZlib.build/inftrees.c.o
40	.build/arm64-apple-macosx/debug/CNIOExtrasZlib.build/trees.c.o
8	.build/arm64-apple-macosx/debug/CNIOExtrasZlib.build/zutil.c.o

@weissi weissi added the 🆕 semver/minor Adds new public API. label Feb 25, 2026
@weissi weissi requested a review from Lukasa February 25, 2026 00:28
Comment thread dev/vendor-zlib.sh Outdated
@weissi weissi enabled auto-merge (squash) February 26, 2026 21:19
@weissi weissi merged commit fef304c into apple:main Feb 26, 2026
38 checks passed
@weissi weissi deleted the jw-vendor-zlib branch February 27, 2026 21:48

/// Data compression utility.
struct Compressor {
private var stream = z_stream()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

zlib depends on the address of the z_stream struct being unchanged between calls, so storing it directly is error prone. And although it might currently be working as expected, it relies on undefined behavior, see: https://github.com/swiftlang/swift/blob/af3e7e765549c0397288e60983c96d81639287ed/stdlib/public/core/UnsafePointer.swift#L197-L205

had a similar issue here: adam-fowler/compress-nio#12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants