From 3fec31a52ad7288ab32e74ae929d8fbaa26fe8fb Mon Sep 17 00:00:00 2001 From: Tadeas Kriz Date: Fri, 3 Nov 2023 10:23:48 -0400 Subject: [PATCH] Fix XCFrameworks artifacts support and FatFrameworkTask modulemap file. --- .../coroutines/AddDependencyOnSkieRuntime.kt | 13 +++++--- .../fatframework/FatFrameworkConfigurator.kt | 17 +++++++--- .../touchlab/skie/plugin/util/SkieTarget.kt | 31 +++++++------------ .../skie/mac/framework/build.gradle.kts | 11 +++++++ 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/coroutines/AddDependencyOnSkieRuntime.kt b/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/coroutines/AddDependencyOnSkieRuntime.kt index 9c21aafe0..7c023b6d7 100644 --- a/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/coroutines/AddDependencyOnSkieRuntime.kt +++ b/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/coroutines/AddDependencyOnSkieRuntime.kt @@ -4,6 +4,7 @@ import co.touchlab.skie.gradle_plugin.BuildConfig import co.touchlab.skie.plugin.util.SkieTarget import co.touchlab.skie.plugin.skieInternal import co.touchlab.skie.plugin.util.lowerCamelCaseName +import org.jetbrains.kotlin.gradle.dsl.KotlinNativeXCFramework import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractNativeLibrary import org.jetbrains.kotlin.konan.target.KonanTarget import org.jetbrains.kotlin.konan.target.presetName @@ -14,10 +15,14 @@ internal fun SkieTarget.addDependencyOnSkieRuntime() { binary.compilation.apiConfigurationName, (binary as? AbstractNativeLibrary)?.exportConfigurationName, ) - is SkieTarget.Artifact -> listOf( - lowerCamelCaseName(konanTarget.presetName, artifact.artifactName, "linkLibrary"), - lowerCamelCaseName(konanTarget.presetName, artifact.artifactName, "linkExport"), - ) + + is SkieTarget.Artifact -> { + val nameSuffix = SkieTarget.Artifact.artifactNameSuffix(artifact) + listOf( + lowerCamelCaseName(konanTarget.presetName, artifact.artifactName + nameSuffix, "linkLibrary"), + lowerCamelCaseName(konanTarget.presetName, artifact.artifactName + nameSuffix, "linkExport"), + ) + } } val dependency = if (project.skieInternal.runtimeVariantFallback.get()) { diff --git a/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/fatframework/FatFrameworkConfigurator.kt b/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/fatframework/FatFrameworkConfigurator.kt index 11f9c7893..6388e7711 100644 --- a/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/fatframework/FatFrameworkConfigurator.kt +++ b/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/fatframework/FatFrameworkConfigurator.kt @@ -31,9 +31,16 @@ internal object FatFrameworkConfigurator { private fun Project.configureFatFrameworkPatching() { tasks.withType().configureEach { doLastOptimized { + // There shouldn't be any real difference between the frameworks except for architecture, so we consider the first one "primary" + val primaryFramework = frameworks.first() val target = FrameworkLayout( rootDir = fatFramework, - isMacosFramework = frameworks.first().target.family == Family.OSX, + isMacosFramework = primaryFramework.files.isMacosFramework, + ) + + // FatFramewrokTask writes its own + target.moduleFile.writeText( + primaryFramework.files.moduleFile.readText() ) val frameworksByArchs = frameworks.associateBy { it.target.architecture } @@ -56,10 +63,10 @@ internal object FatFrameworkConfigurator { } writer.appendLine( """ - #else - #error Unsupported platform - #endif - """.trimIndent(), + #else + #error Unsupported platform + #endif + """.trimIndent(), ) } } diff --git a/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/util/SkieTarget.kt b/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/util/SkieTarget.kt index d8926b7d2..3ca73a158 100644 --- a/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/util/SkieTarget.kt +++ b/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/util/SkieTarget.kt @@ -114,7 +114,9 @@ sealed interface SkieTarget { override fun addToCompilerClasspath(fileCollection: FileCollection) { task.configure { toolOptions.freeCompilerArgs.addAll( - fileCollection.files.map { it.canonicalPath }.sorted().map { "-Xplugin=$it" } + project.provider { + fileCollection.files.map { it.canonicalPath }.sorted().map { "-Xplugin=$it" } + } ) } } @@ -127,7 +129,13 @@ sealed interface SkieTarget { } } - private companion object { + companion object { + fun artifactNameSuffix(artifact: KotlinNativeArtifact): String = when (artifact) { + is KotlinNativeFatFramework -> "ForFat" + is KotlinNativeXCFramework -> "ForXCF" + else -> "" + } + fun linkTaskName(artifact: KotlinNativeArtifact, konanTarget: KonanTarget, buildType: NativeBuildType): String { return when (artifact) { is KotlinNativeLibrary -> { @@ -141,28 +149,13 @@ sealed interface SkieTarget { konanTarget.presetName, ) } - is KotlinNativeFramework -> lowerCamelCaseName( - "assemble", - artifact.artifactName, - buildType.visibleName, - NativeOutputKind.FRAMEWORK.taskNameClassifier, - konanTarget.presetName - ) - is KotlinNativeFatFramework -> lowerCamelCaseName( - "assemble", - artifact.artifactName, - buildType.visibleName, - NativeOutputKind.FRAMEWORK.taskNameClassifier, - konanTarget.presetName, - "ForFat", - ) - is KotlinNativeXCFramework -> lowerCamelCaseName( + is KotlinNativeFramework, is KotlinNativeFatFramework, is KotlinNativeXCFramework -> lowerCamelCaseName( "assemble", artifact.artifactName, buildType.visibleName, NativeOutputKind.FRAMEWORK.taskNameClassifier, konanTarget.presetName, - "ForXCF", + artifactNameSuffix(artifact), ) else -> error("Unknown KotlinNativeArtifact type: $this") } diff --git a/dev-support/skie/mac/framework/build.gradle.kts b/dev-support/skie/mac/framework/build.gradle.kts index 6dcf756a9..c3f7bd94b 100644 --- a/dev-support/skie/mac/framework/build.gradle.kts +++ b/dev-support/skie/mac/framework/build.gradle.kts @@ -108,6 +108,17 @@ kotlinArtifacts { freeCompilerArgs.add("-Xbinary=bundleId=Kotlin") } + exportedLibraries.forEach { + addModule(it) + } + } + Native.XCFramework("Kotlin") { + targets = setOf(macosArm64, macosX64) + isStatic = true + toolOptions { + freeCompilerArgs.add("-Xbinary=bundleId=Kotlin") + } + exportedLibraries.forEach { addModule(it) }