Skip to content

Commit 92e2231

Browse files
authored
Library evolution support (xcframework) (#816)
Resolves #731 Resolves #790 Fixes the library evolution build failure by replacing protocols with `Self` requirements (which cannot form a stable ABI) with protocol composition typealiases that provide a concrete existential type the compiler can support. Protocols with `Self` or associated type requirements cannot form a stable ABI because the compiler cannot create a generic, fixed-size storage container (an "existential") for them, as the concrete size and layout of the conforming type are unknown at the API boundary, making forward-compatible memory management and function dispatch impossible. This is a breaking change ⚠️ for anyone e.g. extending the current hierarchy: ```swift extension VideoTrack // vs extension VideoTrackProtocol where Self: Track ``` This should NOT be a breaking change for just consuming concrete types returned e.g. from factory methods in the SDK.
1 parent 29f16d8 commit 92e2231

File tree

20 files changed

+36
-17
lines changed

20 files changed

+36
-17
lines changed

.changes/xcframework

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
minor type="fixed" "Breaking change: Library evolution support (xcframework). May break existing `*Track` extensions."

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ jobs:
151151
-scheme LiveKit \
152152
-configuration Release \
153153
-destination 'platform=${{ matrix.platform }}' \
154+
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
154155
OTHER_SWIFT_FLAGS="-Xfrontend -emit-symbol-graph\
155156
-Xfrontend -emit-symbol-graph-dir\
156157
-Xfrontend \"${PWD}/symbol-graph\"" \

Sources/LiveKit/Broadcast/BroadcastScreenCapturer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class BroadcastScreenCapturer: BufferCapturer, @unchecked Sendable {
9797
public extension LocalVideoTrack {
9898
/// Creates a track that captures screen capture from a broadcast upload extension
9999
static func createBroadcastScreenCapturerTrack(name: String = Track.screenShareVideoName,
100-
source: VideoTrack.Source = .screenShareVideo,
100+
source: Track.Source = .screenShareVideo,
101101
options: ScreenShareCaptureOptions = ScreenShareCaptureOptions(),
102102
reportStatistics: Bool = false) -> LocalVideoTrack
103103
{

Sources/LiveKit/Core/Room.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import Combine
1718
import Foundation
1819

1920
#if canImport(Network)

Sources/LiveKit/E2EE/E2EEManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import Combine
1718
import Foundation
1819

1920
internal import LiveKitWebRTC

Sources/LiveKit/Extensions/Sendable.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,9 @@ extension NSMapTable: @unchecked Swift.Sendable {} // cannot specify Obj-C gener
5353
#if swift(<6.2)
5454
extension Dictionary: Swift.Sendable where Key: Sendable, Value: Sendable {}
5555
#endif
56+
57+
// MARK: AV
58+
59+
extension AVCaptureDevice: @unchecked Swift.Sendable {}
60+
extension AVCaptureDevice.Format: @unchecked Swift.Sendable {}
61+
extension CVPixelBuffer: @unchecked Swift.Sendable {}

Sources/LiveKit/Participant/Participant.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import Combine
1718
import Foundation
1819

1920
internal import LiveKitWebRTC

Sources/LiveKit/SwiftUI/TrackDelegateObserver.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import Combine
1718
import Foundation
1819

1920
/// Helper class to observer ``TrackDelegate`` from Swift UI.

Sources/LiveKit/Track/AudioTrack.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
import Foundation
1818

1919
@objc
20-
public protocol AudioTrack where Self: Track {
20+
public protocol AudioTrackProtocol: AnyObject, Sendable {
2121
@objc(addAudioRenderer:)
2222
func add(audioRenderer: AudioRenderer)
2323

2424
@objc(removeAudioRenderer:)
2525
func remove(audioRenderer: AudioRenderer)
2626
}
27+
28+
public typealias AudioTrack = AudioTrackProtocol & Track

Sources/LiveKit/Track/Capturers/ARCameraCapturer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public class ARCameraCapturer: VideoCapturer {
9494
public extension LocalVideoTrack {
9595
/// Creates a track that can directly capture `CVPixelBuffer` or `CMSampleBuffer` for convenience
9696
static func createARCameraTrack(name: String = Track.cameraName,
97-
source: VideoTrack.Source = .camera,
97+
source: Track.Source = .camera,
9898
options: ARCameraCaptureOptions = ARCameraCaptureOptions(),
9999
reportStatistics: Bool = false) -> LocalVideoTrack
100100
{

0 commit comments

Comments
 (0)