Skip to content

Fix symlinks in generated XCFramework #188

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

Merged
merged 1 commit into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ let packageName = "PowerSyncKotlin"
let package = Package(
name: packageName,
platforms: [
.iOS(.v13)
.iOS(.v13),
.macOS(.v10_15)
],
products: [
.library(
Expand Down
28 changes: 24 additions & 4 deletions PowerSyncKotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import co.touchlab.faktory.KmmBridgeExtension
import co.touchlab.faktory.artifactmanager.ArtifactManager
import co.touchlab.faktory.capitalized
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
Expand Down Expand Up @@ -107,15 +108,34 @@ class SonatypePortalPublishArtifactManager(
uploadTask: TaskProvider<Task>,
kmmPublishTask: TaskProvider<Task>
) {
val zipXCFramework = project.tasks.named<Zip>("zipXCFramework")
zipXCFramework.configure {
// KMMBridge uses the Gradle Zip tasks to create XCFramework archives, but Gradle
// doesn't support symlinks. XCFrameworks for macOS need to use symlinks though, so we
// patch the task to generate zip files properly.
doLast {
val bridge = project.extensions.getByName<KmmBridgeExtension>("kmmbridge")
val source = project.layout.buildDirectory.map { it.dir("XCFrameworks/${bridge.buildType.get().name}") }.get().asFile

val out = archiveFile.get().asFile
out.delete()

providers.exec {
executable = "zip"
args("-r", "--symlinks", out.absolutePath, "PowerSyncKotlin.xcframework")
workingDir(source)
}.result.get().assertNormalExitValue()
}
}

project.extensions.getByType<PublishingExtension>().publications.create(
publicationName,
MavenPublication::class.java,
) {
this.version = version
val archiveProvider =
project.tasks.named("zipXCFramework", Zip::class.java).flatMap {
it.archiveFile
}
val archiveProvider = zipXCFramework.flatMap {
it.archiveFile
}
artifact(archiveProvider) {
extension = "zip"
}
Expand Down