Skip to content

Fix visionOS build (Cocoa import + visionOS 2.0 availability) - #81

Open
LasCondes wants to merge 2 commits into
colinc86:mainfrom
LasCondes:fix/visionos-cocoa-import-previews
Open

Fix visionOS build (Cocoa import + visionOS 2.0 availability)#81
LasCondes wants to merge 2 commits into
colinc86:mainfrom
LasCondes:fix/visionos-cocoa-import-previews

Conversation

@LasCondes

@LasCondes LasCondes commented Jun 14, 2026

Copy link
Copy Markdown

Summary

LaTeXSwiftUI does not build for visionOS, which breaks any visionOS target that depends on it. There are two independent causes; this PR fixes both.

1. Unguarded import Cocoa in a previews file

Sources/LaTeXSwiftUI/Previews/LaTeX_Previews+Fonts.swift selected its font type with:

#if os(iOS)
import UIKit
typealias PlatformFont = UIFont
#else
import Cocoa            // visionOS lands here — Cocoa doesn't exist on visionOS
typealias PlatformFont = NSFont
#endif

On visionOS os(iOS) is false, so it falls into #else and tries import Cocoa:

error: Unable to resolve module dependency: 'Cocoa'

Fix: #if os(iOS) || os(visionOS). This was the only UIKit/Cocoa guard in the package missing || os(visionOS) — every other site (Font+Extensions.swift, Models/Renderer.swift, Models/Aliases.swift, Extensions/Image+Extensions.swift, LaTeX.swift) already uses it. UIFont is available on visionOS, so the UIKit branch is correct.

2. visionOS-2.0 text-attribute path not gated for visionOS

EquationMarker conforms to SwiftUI's TextAttribute, which — with Text.customAttribute — is available on iOS 18 / macOS 15 / visionOS 2.0. Five availability clauses spelled that generation as (iOS 18.0, macOS 15.0, *), omitting visionOS. Since the package's deployment floor is .visionOS(.v1), the * resolves to visionOS 1.0 and the compiler rejects the symbol:

error: 'EquationMarker' is only available in visionOS 2.0 or newer

Fix: add visionOS 2.0 to all five clauses:

  • Models/EquationMarker.swift (@available)
  • Views/LineSpacingNormalizer.swift (@available)
  • Views/ComponentBlocksViews.swift (#available)
  • Views/ComponentBlocksText.swift (#available)
  • Models/Component.swift (#available)

The existing else branches still cover visionOS 1.x, so the package keeps its visionOS 1.0 floor (no Package.swift platform bump needed).

Scope / impact

  • No behavior change on iOS or macOS.
  • Restores compilation on visionOS (verified building a visionOS app that depends on LaTeXSwiftUI with Xcode 27 / the visionOS 27 SDK).
  • Present on main, develop, and v2.1 at time of writing.

🤖 Generated with Claude Code

LasCondes and others added 2 commits June 14, 2026 10:14
The platform import in Previews/LaTeX_Previews+Fonts.swift used `#if os(iOS)`
with a `#else import Cocoa` fallback. On visionOS `os(iOS)` is false, so the
file falls into the `#else` branch and tries to `import Cocoa`, which does not
exist on visionOS:

    error: Unable to resolve module dependency: 'Cocoa'

This breaks any visionOS build that depends on LaTeXSwiftUI. Every other
UIKit/Cocoa guard in the package already uses `#if os(iOS) || os(visionOS)`
(e.g. Font+Extensions.swift, Models/Renderer.swift, Models/Aliases.swift,
Extensions/Image+Extensions.swift); this previews file was the lone exception.

Align it with the rest of the codebase so visionOS picks the UIKit branch
(UIFont is available on visionOS).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…OS 2.0

EquationMarker conforms to the SwiftUI TextAttribute protocol, which (together
with Text.customAttribute) is available on iOS 18 / macOS 15 / visionOS 2.0.
Five availability clauses spelled this generation as `(iOS 18.0, macOS 15.0, *)`,
omitting visionOS. Because the package's deployment floor is visionOS 1.0, the
`*` resolves to visionOS 1.0, so the compiler rejects EquationMarker on visionOS:

    error: 'EquationMarker' is only available in visionOS 2.0 or newer

Add `visionOS 2.0` to all five clauses (the EquationMarker and LineSpacingNormalizer
@available attributes, and the three #available runtime checks). The existing
`else` branches still provide the fallback for visionOS 1.x, so the package keeps
its visionOS 1.0 floor.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@LasCondes LasCondes changed the title Fix visionOS build: guard Cocoa import in LaTeX_Previews+Fonts.swift Fix visionOS build (Cocoa import + visionOS 2.0 availability) Jun 14, 2026
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