Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic XCFramework Support (SPM binary target support) #866

Closed
wants to merge 2 commits into from

Conversation

Kyle-Ye
Copy link

@Kyle-Ye Kyle-Ye commented Apr 10, 2022

Currently it is not easy to add source package for Swift Package Manager support.

But we can build and release it as a xcframework and use it as a binary target to support SPM.

Currently there are 2 ways to do it:

  1. Add the binaryTarget directly in the Package.swift
// MMKVDemo
let package = Package(
    name: "MMKVDemo",
    products: [
        .library(name: "MMKVDemo", targets: ["MMKVDemo"]),
    ],
    targets: [
        .binaryTarget(
            name: "MMKV",
            // Change to https://github.com/Tencent/MMKV/releases/download/v1.2.13/MMKV.xcframework.zip once the upstream merges it.
            url: "https://github.com/Kyle-Ye/MMKV/releases/download/v1.2.13/MMKV.xcframework.zip",
            checksum: "7782fbd6896d266d37c97ccb07cf1954de98e6c2a03fc6715cde48fa235151e7"
        )
        .target(
            name: "MMKVDemo",
            dependencies: [
                .product(name: "MMKV", package: "MMKV-XCFramework"),
            ]
        ),
    ]
)
  1. Add a new repo called MMKV-XCFramework(See https://github.com/Kyle-Ye/MMKV-XCFramework) and wraps the logic in it.

Then for the call site, it just use something like this.

// MMKVXCFramework
let package = Package(
    name: "MMKVXCFramework",
    products: [.library(name: "MMKV", targets: ["MMKV"])],
    targets: [
        .binaryTarget(
            name: "MMKV",
            url: "https://github.com/Kyle-Ye/MMKV/releases/download/v1.2.13/MMKV.xcframework.zip",
            checksum: "7782fbd6896d266d37c97ccb07cf1954de98e6c2a03fc6715cde48fa235151e7"
        )
    ]
)
// MMKVDemo
let package = Package(
    name: "MMKVDemo",
    products: [
        .library(name: "MMKVDemo", targets: ["MMKVDemo"]),
    ],
    dependencies: [
        .package(url: "https://github.com/Kyle-Ye/MMKV-XCFramework.git", from: "1.2.13"),
    ],
    targets: [
        .target(
            name: "MMKVDemo",
            dependencies: [
                .product(name: "MMKV", package: "MMKV-XCFramework"),
            ]
        ),
    ]
)

@Kyle-Ye
Copy link
Author

Kyle-Ye commented Apr 10, 2022

For anyone interested in integrating MMKV into SPM, you can add the dependency temporarily to do it.

dependencies: [
        .package(url: "https://github.com/Kyle-Ye/MMKV-XCFramework.git", from: "1.2.13"),
    ],
    targets: [
        .target(
            name: "XX",
            dependencies: [
                .product(name: "MMKV", package: "MMKV-XCFramework"),
            ]
        ),
    ]

@lingol
Copy link
Collaborator

lingol commented Apr 11, 2022

I'm not interested in releasing MMKV for iOS in a binary target.
Anyway, thanks for your input.

@lingol lingol closed this Apr 11, 2022
@Kyle-Ye
Copy link
Author

Kyle-Ye commented Apr 11, 2022

I'm not interested in releasing MMKV for iOS in a binary target. Anyway, thanks for your input.

Got it, thanks for your replying.

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.

None yet

2 participants