[KT-53340] Cocoapods fix: configure linker for default frameworks.
There was a hidden problem: linker options was applied only if `framework` dsl was used.
This commit is contained in:
committed by
Space
parent
b58d2d72e7
commit
96c0796296
+1
-31
@@ -244,37 +244,7 @@ abstract class CocoapodsExtension @Inject constructor(private val project: Proje
|
|||||||
project.multiplatformExtension.supportedTargets().all { target ->
|
project.multiplatformExtension.supportedTargets().all { target ->
|
||||||
target.binaries
|
target.binaries
|
||||||
.matching { it.name.startsWith(POD_FRAMEWORK_PREFIX) }
|
.matching { it.name.startsWith(POD_FRAMEWORK_PREFIX) }
|
||||||
.withType(Framework::class.java) {
|
.withType(Framework::class.java) { action.execute(it) }
|
||||||
action.execute(it)
|
|
||||||
if (!it.isStatic) {
|
|
||||||
configureLinkingOptions(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun configureLinkingOptions(binary: NativeBinary, setRPath: Boolean = false) {
|
|
||||||
pods.all { pod ->
|
|
||||||
binary.linkTaskProvider.configure { task ->
|
|
||||||
if (HostManager.hostIsMac) {
|
|
||||||
val podBuildTaskProvider = project.getPodBuildTaskProvider(binary.target, pod)
|
|
||||||
task.inputs.file(podBuildTaskProvider.map { it.buildSettingsFile })
|
|
||||||
task.dependsOn(podBuildTaskProvider)
|
|
||||||
}
|
|
||||||
|
|
||||||
task.doFirst { _ ->
|
|
||||||
val podBuildSettings = project.getPodBuildSettingsProperties(binary.target, pod)
|
|
||||||
val frameworkFileName = pod.moduleName + ".framework"
|
|
||||||
val frameworkSearchPaths = podBuildSettings.frameworkSearchPaths
|
|
||||||
|
|
||||||
val frameworkFileExists = frameworkSearchPaths.any { dir -> File(dir, frameworkFileName).exists() }
|
|
||||||
if (frameworkFileExists) binary.linkerOpts.addArg("-framework", pod.moduleName)
|
|
||||||
|
|
||||||
binary.linkerOpts.addAll(frameworkSearchPaths.map { "-F$it" })
|
|
||||||
|
|
||||||
if (setRPath) binary.linkerOpts.addArgs("-rpath", frameworkSearchPaths)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+38
-4
@@ -563,10 +563,44 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
|
|||||||
project.ideaImportDependsOn(podImportTaskProvider)
|
project.ideaImportDependsOn(podImportTaskProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun configureTestBinaries(project: Project, cocoapodsExtension: CocoapodsExtension) {
|
private fun configureLinkingOptions(project: Project, cocoapodsExtension: CocoapodsExtension) {
|
||||||
project.multiplatformExtension.supportedTargets().all { target ->
|
project.multiplatformExtension.supportedTargets().all { target ->
|
||||||
target.binaries.withType(TestExecutable::class.java) { testExecutable ->
|
target.binaries.all { binary ->
|
||||||
cocoapodsExtension.configureLinkingOptions(testExecutable, setRPath = true)
|
val testExecutable = binary is TestExecutable
|
||||||
|
val podFramework = binary is Framework && binary.name.startsWith(POD_FRAMEWORK_PREFIX)
|
||||||
|
if (testExecutable || podFramework) {
|
||||||
|
configureLinkingOptions(project, cocoapodsExtension, binary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun configureLinkingOptions(project: Project, cocoapodsExtension: CocoapodsExtension, nativeBinary: NativeBinary) {
|
||||||
|
cocoapodsExtension.pods.all { pod ->
|
||||||
|
nativeBinary.linkTaskProvider.configure { task ->
|
||||||
|
val binary = task.binary
|
||||||
|
if (HostManager.hostIsMac) {
|
||||||
|
val podBuildTaskProvider = project.getPodBuildTaskProvider(binary.target, pod)
|
||||||
|
task.inputs.file(podBuildTaskProvider.map { it.buildSettingsFile })
|
||||||
|
task.dependsOn(podBuildTaskProvider)
|
||||||
|
}
|
||||||
|
|
||||||
|
task.doFirst { _ ->
|
||||||
|
val isExecutable = binary is AbstractExecutable
|
||||||
|
val isDynamicFramework = (binary is Framework && !binary.isStatic)
|
||||||
|
|
||||||
|
val podBuildSettings = project.getPodBuildSettingsProperties(binary.target, pod)
|
||||||
|
val frameworkFileName = pod.moduleName + ".framework"
|
||||||
|
val frameworkSearchPaths = podBuildSettings.frameworkSearchPaths
|
||||||
|
|
||||||
|
if (isExecutable || isDynamicFramework) {
|
||||||
|
val frameworkFileExists = frameworkSearchPaths.any { dir -> File(dir, frameworkFileName).exists() }
|
||||||
|
if (frameworkFileExists) binary.linkerOpts.addArg("-framework", pod.moduleName)
|
||||||
|
binary.linkerOpts.addAll(frameworkSearchPaths.map { "-F$it" })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isExecutable) binary.linkerOpts.addArgs("-rpath", frameworkSearchPaths)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -702,7 +736,7 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
createInterops(project, kotlinExtension, cocoapodsExtension)
|
createInterops(project, kotlinExtension, cocoapodsExtension)
|
||||||
configureTestBinaries(project, cocoapodsExtension)
|
configureLinkingOptions(project, cocoapodsExtension)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user