Skip to content

fix(SPI): three small SDK-compatibility fixes (IOSurface import, tokenizer header, UIColor init) - #1246

Draft
cristim wants to merge 4 commits into
OpenSwiftUIProject:mainfrom
cristim:rfc/sdk-compat-fixes
Draft

cristim wants to merge 4 commits into
OpenSwiftUIProject:mainfrom
cristim:rfc/sdk-compat-fixes

Conversation

@cristim

@cristim cristim commented Nov 4, 2026 •

Copy link
Copy Markdown

Summary

RFC, draft, unbuilt. Three small SDK-compatibility fixes found while building OpenSwiftUI against a non-Apple Darwin-compatible SDK. Each is independent and touches one file:

  • Localization.m: import CFStringTokenizer.h explicitly instead of relying on the CoreFoundation umbrella.
  • GraphicsImage.swift: import IOSurface and spell the case type IOSurface where the module exists; elsewhere keep IOSurfaceRef (follow-up commit, found in review). The old spelling is a typealias of the same type, so mangling is unchanged on Darwin.
  • OpenSwiftUICoreColor.m: describe UIColor's initWithRed:green:blue:alpha: with a local protocol and cast to it, instead of messaging an untyped id.

Verification

Run: each commit cherry-picks cleanly onto current main; a cold review read all call sites of the changed types. Not run: no Swift or Objective-C compiler was available, so nothing was compiled and the Linux and macOS CI jobs are the first real check.

CONTRIBUTING.md asks for an issue or discussion first for large work; this PR is deliberately small. Larger Darling-specific changes from my fork are held back.

Localization.m uses CFStringTokenizer but only imports the CoreFoundation
umbrella. Import CFStringTokenizer.h directly so the file does not depend on
what the umbrella happens to pull in on a given SDK.

(cherry picked from commit aedeae7)
GraphicsImage.Contents.ioSurface names IOSurfaceRef without importing
IOSurface, so the type does not resolve on SDKs where it is not re-exported.
Import the module and spell the type IOSurface; with the module imported and
the old spelling kept, Swift reports that IOSurfaceRef has been renamed to
IOSurface. The old spelling is a typealias of the same type, so the symbol
mangling is unchanged.

(cherry picked from commit ff285c4)
The macOS path can select UIColor dynamically, but AppKit headers do not
declare UIColor's initWithRed:green:blue:alpha:. Describe it with a local
protocol and cast to it, instead of messaging an untyped id.

(cherry picked from commit e493940)
…bsent

The previous commit spells the case type IOSurface unconditionally, but on
platforms without the IOSurface module (Linux) only OpenCoreGraphics'
IOSurfaceRef exists. Select the spelling with the same canImport guard as
the import.
@cristim cristim changed the title RFC: three small SDK-compatibility fixes (IOSurface import, tokenizer header, UIColor init) fix(SPI): three small SDK-compatibility fixes (IOSurface import, tokenizer header, UIColor init) Nov 4, 2026
@cristim

cristim commented Nov 4, 2026

Copy link
Copy Markdown
Author

Cold review of 11efd08/1c760d21/b067b39e: tokenizer import and UIColor protocol cast clean; the IOSurface spelling would have broken the Linux build (only IOSurfaceRef exists there). Fixed in 9c3b75b by keeping IOSurfaceRef under the non-canImport branch. PR title and body updated to the conventional format. Still not compiled: no Swift or ObjC compiler on the machine used; CI is the first real check.

package enum Contents: Equatable, @unchecked Sendable {
case cgImage(CGImage)
#if canImport(IOSurface)
case ioSurface(IOSurface)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why we need this?

This branch has not been deployed

No deployments
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.

2 participants