Skip to content

Integrate Swift Binary Parsing#11

Merged
colemancda merged 2 commits into
masterfrom
feature/binary-parsing
Jul 18, 2026
Merged

Integrate Swift Binary Parsing#11
colemancda merged 2 commits into
masterfrom
feature/binary-parsing

Conversation

@colemancda

@colemancda colemancda commented Jul 18, 2026

Copy link
Copy Markdown
Member

Summary

Integrates apple/swift-binary-parsing for safe, bounds-checked TLV8 parsing on Swift 6.2+ toolchains.

  • TLVTypeCode, TLVItem, and TLVContainer conform to ExpressibleByParsing, adding throwing, span-based APIs: try TLVContainer(parsing: data) and incremental TLVItem(parsing: &input) consumption from a ParserSpan.
  • TLVContainer.init(data:) is now backed by the BinaryParsing parser when the module is available; the hand-rolled parser remains as the fallback, so the public API and wire format are unchanged.
  • The dependency follows the existing env-gate pattern: enabled by default on Swift 6.2+, disabled with SWIFTPM_ENABLE_BINARY_PARSING=0 (required for Embedded Swift builds, since the standard BinaryParsing product doesn't build for bare-metal triples).
  • The Android emulator unit-test job is replaced with an x86_64 cross-compile check: SwiftPM's index-store-based XCTest discovery fails when cross-compiling a package whose test target uses macros (Cross-compiling packages which contain macros doesn't work swiftlang/swift-package-manager#6950), which has broken that job for every commit since the macros merge in Embedded Swift support #9.

Notes

  • Apple deployment targets are raised to macOS 13 / iOS 16 / watchOS 9 / tvOS 16 when the dependency is enabled (its minimums).
  • swift-binary-parsing 0.0.2 pins swift-syntax 602.0.0..<603.0.0, so the macros' swift-syntax version is forced to 602.0.0 when the gate is on. Their main already relaxed this to from: "602.0.0", so the pin can be dropped with their next release.
  • All CI toolchains (macOS 26, Linux latest/nightly, Android 6.3.3, Windows 6.3.3) meet the Swift 6.2 requirement.

Test plan

  • swift test — 9 tests pass, including new testBinaryParsing (span parsing, equivalence with init(data:), truncation errors)
  • SWIFTPM_ENABLE_BINARY_PARSING=0 swift test — fallback parser path
  • SWIFTPM_ENABLE_MACROS=0 swift build
  • Embedded: SWIFTPM_ENABLE_MACROS=0 SWIFTPM_ENABLE_BINARY_PARSING=0 swift build --target TLVCoding --triple armv7em-none-none-eabi -Xswiftc -enable-experimental-feature -Xswiftc Embedded -Xswiftc -wmo

Add apple/swift-binary-parsing as a dependency on Swift 6.2+
toolchains. TLVTypeCode, TLVItem and TLVContainer now conform to
ExpressibleByParsing for throwing, span-based parsing, and
TLVContainer.init(data:) is backed by the safe bounds-checked parser
when the module is available.

The dependency raises Apple platform deployment targets to
macOS 13 / iOS 16 / watchOS 9 / tvOS 16 and can be disabled with
SWIFTPM_ENABLE_BINARY_PARSING=0 (required for Embedded Swift builds).
swift-syntax resolves to 602.x when enabled, matching the pin in
swift-binary-parsing 0.0.2.
@colemancda
colemancda force-pushed the feature/binary-parsing branch from 02bf6c6 to 79f272d Compare July 18, 2026 14:09
SwiftPM's index-store-based XCTest discovery fails when cross-compiling
a package whose test target uses macros ("error: index store path does
not exist", swiftlang/swift-package-manager#6950), breaking the
emulator job for every commit since the macro rewrite. Replace it with
an x86_64 cross-compile check until test discovery works for
macro-using packages.
@colemancda
colemancda merged commit 99fc31b into master Jul 18, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant