From 300acafc6375cc2fdad2c8c113b674bde0711b76 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Thu, 21 Mar 2019 14:55:16 +0700 Subject: [PATCH] CocoaPods: Don't generate a fat framework for a single device target --- .../plugin/cocoapods/KotlinCocoapodsPlugin.kt | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/cocoapods/KotlinCocoapodsPlugin.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/cocoapods/KotlinCocoapodsPlugin.kt index 9204b132e05..d6a175bc4c0 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/cocoapods/KotlinCocoapodsPlugin.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/cocoapods/KotlinCocoapodsPlugin.kt @@ -85,11 +85,10 @@ open class KotlinCocoapodsPlugin: Plugin { private fun createSyncForFatFramework( project: Project, kotlinExtension: KotlinMultiplatformExtension, - requestedBuildType: String + requestedBuildType: String, + requestedPlatforms: List ) { - // We create a fat framework only for device platforms: iosArm64 and iosArm32. - val fatPlatforms = listOf(KonanTarget.IOS_ARM64, KonanTarget.IOS_ARM32) - val fatTargets = fatPlatforms.associate { it to kotlinExtension.targetsForPlatform(it) } + val fatTargets = requestedPlatforms.associate { it to kotlinExtension.targetsForPlatform(it) } check(fatTargets.values.any { it.isNotEmpty() }) { "The project doesn't contain a target for iOS device" } fatTargets.forEach { platform, targets -> @@ -117,12 +116,12 @@ open class KotlinCocoapodsPlugin: Plugin { project: Project, kotlinExtension: KotlinMultiplatformExtension, requestedBuildType: String, - requestedTarget: KonanTarget + requestedPlatform: KonanTarget ) { - val targets = kotlinExtension.targetsForPlatform(requestedTarget) + val targets = kotlinExtension.targetsForPlatform(requestedPlatform) - check(targets.isNotEmpty()) { "The project doesn't contain a target for the requested platform: `${requestedTarget.visibleName}`" } - check(targets.size == 1) { "The project has more than one target for the requested platform: `${requestedTarget.visibleName}`" } + check(targets.isNotEmpty()) { "The project doesn't contain a target for the requested platform: `${requestedPlatform.visibleName}`" } + check(targets.size == 1) { "The project has more than one target for the requested platform: `${requestedPlatform.visibleName}`" } val frameworkLinkTask = targets.single().binaries.getFramework(requestedBuildType).linkTask project.createSyncFrameworkTask(frameworkLinkTask.destinationDir, frameworkLinkTask) @@ -136,8 +135,17 @@ open class KotlinCocoapodsPlugin: Plugin { val requestedBuildType = project.findProperty(CONFIGURATION_PROPERTY)?.toString()?.toUpperCase() ?: return@whenEvaluated if (requestedTargetName == KOTLIN_TARGET_FOR_DEVICE) { - // A required target is a device and we need to build a fat framework. - createSyncForFatFramework(project, kotlinExtension, requestedBuildType) + // We create a fat framework only for device platforms: iosArm64 and iosArm32. + val devicePlatforms = listOf(KonanTarget.IOS_ARM64, KonanTarget.IOS_ARM32) + val deviceTargets = devicePlatforms.flatMap { kotlinExtension.targetsForPlatform(it) } + + if (deviceTargets.size == 1) { + // Fast path: there is only one device target. There is no need to build a fat framework. + createSyncForRegularFramework(project, kotlinExtension, requestedBuildType, deviceTargets.single().konanTarget) + } else { + // There are several device targets so we need to build a fat framework. + createSyncForFatFramework(project, kotlinExtension, requestedBuildType, devicePlatforms) + } } else { // A requested target doesn't require building a fat framework. createSyncForRegularFramework(project, kotlinExtension, requestedBuildType, HostManager().targetByName(requestedTargetName))