Skip to content

Commit ed63562

Browse files
committed
1 parent 392a364 commit ed63562

File tree

1 file changed

+6
-52
lines changed

1 file changed

+6
-52
lines changed

src/main/kotlin/com/chromaticnoise/multiplatformswiftpackage/task/CreateXCFrameworkTask.kt

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.chromaticnoise.multiplatformswiftpackage.task
22

33
import com.chromaticnoise.multiplatformswiftpackage.domain.*
4-
import com.chromaticnoise.multiplatformswiftpackage.domain.PluginConfiguration
5-
import com.chromaticnoise.multiplatformswiftpackage.domain.getConfigurationOrThrow
64
import org.gradle.api.Project
75
import org.gradle.api.tasks.Exec
86
import org.gradle.kotlin.dsl.task
@@ -41,62 +39,18 @@ internal fun getTvosSimulatorFrameworks(configuration: PluginConfiguration): Lis
4139
}
4240

4341
internal fun Project.registerCreateUniversalMacosFrameworkTask() =
44-
task("createUniversalMacosFramework") {
45-
// Can't use FatFrameworkTask 🙃
46-
// https://youtrack.jetbrains.com/issue/KT-47355/Support-macos-target-for-FatFramework-task
47-
// workaround:
48-
// https://gist.github.com/JUSTINMKAUFMAN/6627c3c8571563b36efc9c832f6fa2b1
42+
task<FatFrameworkTask>("createUniversalMacosSimulatorFramework") {
4943
group = "multiplatform-swift-package"
5044
description = "Creates a universal (fat) macos framework"
5145
val configuration = getConfigurationOrThrow()
5246
onlyIf { getMacosFrameworks(configuration).size > 1 }
5347
val targets = getMacosFrameworks(configuration)
5448
dependsOn(targets.map { it.linkTask.name })
55-
doLast {
56-
if (targets.isNotEmpty()) {
57-
delete(buildDir.resolve("bin/macosUniversal"))
58-
val buildType = if (targets[0].linkTask.name.contains("Release")) "release" else "debug"
59-
val frameworkName = targets[0].name.value
60-
val destinationDir = buildDir.resolve("bin/macosUniversal/${buildType}Framework")
61-
mkdir(destinationDir.parent)
62-
mkdir(destinationDir)
63-
val tempUniversalBinaryLocation = File(destinationDir, frameworkName)
64-
exec {
65-
commandLine(
66-
"lipo",
67-
"-create",
68-
"${targets[0].outputFile.path}/Versions/A/${frameworkName}",
69-
"${targets[1].outputFile.path}/Versions/A/${frameworkName}",
70-
"-output",
71-
tempUniversalBinaryLocation.path
72-
)
73-
}
74-
val aFramework = targets[0].outputFile.path
75-
copy {
76-
from(aFramework)
77-
into(File(destinationDir, "$frameworkName.framework"))
78-
}
79-
// delete the old mono framework binary we copied here
80-
val binaryFinalLocation = File(destinationDir, "${frameworkName}.framework/Versions/A/$frameworkName")
81-
val binaryFinalSymlinkLocation = File(destinationDir, "${frameworkName}.framework/$frameworkName")
82-
delete(binaryFinalLocation)
83-
delete(binaryFinalSymlinkLocation)
84-
// copy new universal binary to binaryFinalSymlinkLocation
85-
copy {
86-
from(tempUniversalBinaryLocation)
87-
into(File(destinationDir, "$frameworkName.framework/Versions/A"))
88-
}
89-
delete(tempUniversalBinaryLocation)
90-
exec {
91-
//recreate the symlink normally to the binary normally in framework folder
92-
commandLine(
93-
"ln",
94-
"-s",
95-
binaryFinalLocation.toPath(),
96-
binaryFinalSymlinkLocation.toPath()
97-
)
98-
}
99-
}
49+
if (targets.isNotEmpty()) {
50+
val buildType = if (targets[0].linkTask.name.contains("Release")) "release" else "debug"
51+
baseName = checkNotNull(targets.first().name.value)
52+
destinationDir = buildDir.resolve("bin/macosUniversal/${buildType}Framework")
53+
from(targets.mapNotNull { it.framework })
10054
}
10155
}
10256

0 commit comments

Comments
 (0)