Skip to content

Add macOS and tvOS platform support#39

Open
benroeder wants to merge 10 commits into
alexiscn:masterfrom
benroeder:master
Open

Add macOS and tvOS platform support#39
benroeder wants to merge 10 commits into
alexiscn:masterfrom
benroeder:master

Conversation

@benroeder
Copy link
Copy Markdown

Summary

  • Add macOS 10.13+ and tvOS 14.0+ deployment targets to the podspec
  • Create MTTransitionsMacDemo SwiftUI app for macOS with sidebar effect list and preview
  • Create MTTransitionsTVDemo SwiftUI app for tvOS with focus-based navigation
  • Add platform conditionals for UIKit/AppKit differences (NSImage vs UIImage, CADisplayLink vs Timer)
  • Fix deprecated AVVideoCodecH264 warning (use AVVideoCodecType.h264)
  • Fix PI macro redefinition warning in MTStarWipeTransition.metal
  • Suppress unfixable Swift 6 Sendable warnings via compiler flag

Test plan

  • Build and run MTTransitionsMacDemo on macOS
  • Build and run MTTransitionsTVDemo on tvOS simulator or Apple TV
  • Verify all 76 transition effects work on both platforms
  • Verify no compiler warnings in MTTransitions source

- Add macOS 10.13+ and tvOS 14.0+ deployment targets
- Create MTTransitionsMacDemo SwiftUI app for macOS
- Create MTTransitionsTVDemo SwiftUI app for tvOS with focus navigation
- Add platform conditionals for UIKit/AppKit differences
- Replace CADisplayLink with Timer on macOS
- Fix deprecated AVVideoCodecH264 warning
- Fix PI macro redefinition warning in MTStarWipeTransition.metal
- Suppress unfixable Swift 6 Sendable warnings via compiler flag
benroeder and others added 9 commits January 1, 2026 19:46
- Restructure tvOS demo with tabbed interface (Image, UIView, ViewController)
- Add UIView transition demo with cycle through all 76 effects
- Add ViewController transition demo with push/present and cycle feature
- Update README with platform support for each feature
- Add post_install hook to remove duplicate -lc++ linker flags
- Disable App Intents metadata extraction (not used by library)
Fix Swift Package Manager warning about unhandled Assets.bundle file
by explicitly declaring it as a processed resource.
When used as an SPM dependency, Metal shaders cannot be compiled offline.
This adds runtime shader compilation using MetalPetal's library registration.

Changes:
- MTTransitionsSwiftPMSupport.mm: Embeds all 87 shader sources as strings
- MTTransitionsSwiftPMSupport.h: Header for the ObjC function
- MTTransition+SwiftPM.swift: Extension to use SPM library URL
- MTTransition.swift: Use swiftPMLibraryURL for shader loading
- Package.swift: Split into ObjC and Swift targets for mixed-language support

The shaders are embedded as raw strings and compiled at runtime when
SPM is detected via the SWIFT_PACKAGE preprocessor flag.
The previous approach used #include "MTIShaderLib.h" which doesn't work
when compiling shaders at runtime with MTILibrarySourceRegistration
because the Metal compiler can't find the header file.

This commit inlines the essential MTIShaderLib.h content directly into
the embedded shader source, including:
- MTIVertex struct
- metalpetal::VertexOut struct (required by all fragment shaders)
- Utility functions (mod, sRGBToLinear, linearToSRGB, blend modes, etc.)

This enables MTTransitions to work correctly when used as an SPM
dependency with runtime shader compilation.
These macros may not be defined during runtime Metal shader compilation
via MTILibrarySourceRegistration. Since we're always compiling for Metal,
the conditional is unnecessary and was preventing the metalpetal namespace
from being defined.
The .metal files were being compiled directly by xcodebuild for tvOS,
but they couldn't find MTIShaderLib.h from MetalPetal. These files
aren't needed for SPM builds since the shaders are embedded as strings
in MTTransitionsSwiftPMSupport.mm for runtime compilation.
`samplerImage(name:)` used `Bundle(for: MTTransition.self)` which
under SwiftPM returns the framework binary's enclosing bundle —
which carries no resources. `.process("Assets.bundle")` in
Package.swift (3155d82) correctly places the asset bundle into
`Bundle.module`, but the lookup never consulted it, so
transitions that declare auxiliary textures via `samplers`
silently lost those bindings.

Two transitions hit this: MTDisplacementTransition
(displacementMap.jpg) and MTLumaTransition (luma masks). Their
fragment shaders declare 3 textures; with the sampler image
missing, command.images.count == 2 and MetalPetal's
MTIRenderPipelineKernel.m:342 NSAsserts on "Failed to set
fragment textures" — DEBUG-only, but the NSException is
uncatchable from Swift and terminates the process via SIGABRT.

Branch on `#if SWIFT_PACKAGE` and read from `Bundle.module` —
parallel to the existing `MTTransition.swiftPMLibraryURL` shim
that handles shader-library URL resolution for SPM. Non-SPM
builds (CocoaPods / direct framework) keep the original
behaviour.

Reproducer: any host app that cycles through TransitionEffect
.allCases under SwiftPM crashes on the first .displacement
transition; same on simulator and on physical tvOS hardware.
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