feat(darwin): add Swift Package Manager support by cherry-picking upstream SPM commits#30
Closed
0Chencc wants to merge 7 commits into
Closed
feat(darwin): add Swift Package Manager support by cherry-picking upstream SPM commits#300Chencc wants to merge 7 commits into
0Chencc wants to merge 7 commits into
Conversation
Revert the deployment target bumps (macOS 10.15→10.9, iOS 13.0→9.0). The lower values match the actual targets encoded in the xcframework binaries from media-kit/libmpv-darwin-build and should be preferred.
The minimum Flutter version was bumped to 3.27.4 to support Swift Package Manager, but CocoaPods is still supported. There is no reason to force developers onto a recent Flutter version until SPM becomes the only supported option.
Previously, the SPM manifests for iOS and macOS unconditionally declared
`media_kit_libs_{ios,macos}_video` as a required dependency, causing the
build to fail if the package was not included in the developer's
`pubspec.yaml`.
The dependency is now resolved dynamically at manifest evaluation time by
checking whether the sibling package directory exists in the SPM ephemeral
packages directory. If found, `media_kit_video` is linked against it as
before; otherwise it falls back to a stub implementation, mirroring the
existing CocoaPods behavior in `media_kit_utils.rb`.
Note: after adding or removing the libs package from `pubspec.yaml`,
the SPM cache must be cleared manually:
rm -rf ~/Library/Caches/org.swift.swiftpm/
Owner
|
这个PR现在没有指向我们的自定义 libmpv 二进制构建,我们需要自己的自定义构建来实现广告过滤等功能 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
上游 media-kit/media-kit 自 2026-05 起加入了 Swift Package Manager (SPM) 支持(#1412),让 `media_kit_video` 和 `media_kit_libs_{ios,macos}_video` 这几个 plugin package 可以被 Flutter 3.44+ 通过 SPM 而非 CocoaPods 集成。
本 fork (`Predidit/media-kit`) 目前 main HEAD 是 `21aacaf9`,stops at 2026 之前的状态,没有这部分上游改动,因此下游用户(如 Kazumi)的 macOS / iOS 集成仍只能走 CocoaPods 兜底。
改动内容
本 PR 把上游的 7 个 SPM 相关 commit 干净地 cherry-pick 到本 fork:
改动后的 4 个 Package.swift
上游设计的 `packageExists()` 函数被完整保留 —— 它在 manifest evaluation 时探测 sibling SPM package 是否存在,让 `media_kit_video` 即使 user 没装 libs 包也能编译(fallback 到 stub)。
设计要点(来自上游)
```swift
func packageExists(at relativePath: String) -> Bool {
let base = URL(fileURLWithPath: #file).deletingLastPathComponent()
let path = base.appendingPathComponent(relativePath).standardized.path
return FileManager.default.fileExists(atPath: path)
}
let libsPath = "../media_kit_libs_macos_video"
let hasLibs = packageExists(at: libsPath)
let package = Package(
...
dependencies: hasLibs ? [.package(...)] : [],
...
)
```
`rm -rf ~/Library/Caches/org.swift.swiftpm/`
不改的内容
验证情况
在下游 Kazumi (Flutter 3.44.0) 验证:
下游影响
合入后,Kazumi 等下游项目只需把 pubspec.yaml 里 `ref: 21aacaf...` 升到本 PR 的 merge commit SHA,即可让 `media_kit_video` / `media_kit_libs_{ios,macos}_video` 自动切到 SPM 集成,无需任何代码改动。