Skip to content

Commit

Permalink
Fix XCFrameworks artifacts support and FatFrameworkTask modulemap file.
Browse files Browse the repository at this point in the history
  • Loading branch information
TadeasKriz committed Nov 3, 2023
1 parent 6bea75b commit 3fec31a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ internal object FatFrameworkConfigurator {
private fun Project.configureFatFrameworkPatching() {
tasks.withType<FatFrameworkTask>().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 }
Expand All @@ -56,10 +63,10 @@ internal object FatFrameworkConfigurator {
}
writer.appendLine(
"""
#else
#error Unsupported platform
#endif
""".trimIndent(),
#else
#error Unsupported platform
#endif
""".trimIndent(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
}
)
}
}
Expand All @@ -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 -> {
Expand All @@ -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")
}
Expand Down
11 changes: 11 additions & 0 deletions dev-support/skie/mac/framework/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 3fec31a

Please sign in to comment.