Prefer FoundationEssentials over Foundation for the Data bridges#57
Open
lhoward wants to merge 1 commit into
Open
Prefer FoundationEssentials over Foundation for the Data bridges#57lhoward wants to merge 1 commit into
lhoward wants to merge 1 commit into
Conversation
The optional `Data` conveniences in `ParserSource.swift` and `Data.swift` used `public import Foundation` guarded on `canImport(Foundation)`. Because these are *public* (re-exported) imports, every downstream consumer of BinaryParsing inherits a link dependency on full Foundation — which on non-Darwin platforms pulls in FoundationInternationalization and the ICU data blob — even though the only symbol used is `Data`, which is available in FoundationEssentials. Prefer FoundationEssentials when available, falling back to Foundation, and de-qualify `Foundation.Data` to `Data` so it resolves from whichever module is imported. No API change: the `Data` initializers and `ParserSpanProvider` conformance are unchanged; this only narrows the transitive link dependency. On Linux this removes libFoundation, libFoundationInternationalization and the ICU data library from the link closure of any executable that uses BinaryParsing but not full Foundation. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The optional
Dataconveniences inParserSource.swiftandParsers/Data.swiftusepublic import Foundation, guarded only oncanImport(Foundation). Two consequences on non-Darwin (Linux) platforms:public(re-exported) imports, every downstream consumer ofBinaryParsinginherits a link dependency on fullFoundation— even modules that never touchData. The autolink propagates transitively.Foundationon Linux pulls inFoundationInternationalizationand the ICU data library (_FoundationICU, tens of MB), even though the only symbol used from Foundation here isData, which is available inFoundationEssentials.For size-sensitive / embedded-adjacent Linux deployments this drags the entire ICU blob into the link closure of any executable that uses
BinaryParsingbut not full Foundation. (Found while shrinking a Swift networking daemon for a 64 MB target —BinaryParsingwas the sole remaining anchor forcinglibFoundation+ ICU into an otherwiseFoundationEssentials-only binary.)Change
In both files, prefer
FoundationEssentialswhen available, falling back to fullFoundation:canImport(Foundation)guards around theDataextensions are widened to(canImport(FoundationEssentials) || canImport(Foundation)).Foundation.Datais de-qualified toDataso it resolves from whichever module was imported.$Embeddedhandling is unchanged.Effect
No API change — the
Datainitializers (init(parsingRemainingBytes:),init(parsing:byteCount:)) and theData: ParserSpanProviderconformance are identical. On Linux this removeslibFoundation,libFoundationInternationalization, and the ICU data library from the transitive link closure for consumers that don't otherwise use full Foundation. Verified end-to-end: a dynamically-linked executable depending onBinaryParsingdropped from needinglibFoundation+libFoundationInternationalization+_FoundationICUto needing onlylibFoundationEssentials.🤖 Generated with Claude Code