Skip to content

Commit

Permalink
Fix Swift bundling issues for Kotlin 2.1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
TadeasKriz committed Nov 28, 2024
1 parent 1153e7a commit 7afb5e2
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import co.touchlab.skie.plugin.util.lowerCamelCaseName
import co.touchlab.skie.plugin.util.registerSkieTask
import co.touchlab.skie.plugin.util.writeToZip
import co.touchlab.skie.util.cache.syncDirectoryContentIfDifferent
import co.touchlab.skie.util.file.isKlib
import org.gradle.api.Project
import org.gradle.api.file.SourceDirectorySet
import org.gradle.api.provider.Provider
Expand Down Expand Up @@ -88,10 +89,14 @@ object SwiftBundlingConfigurator {
return
}

klib.writeToZip { fileSystem ->
val klibSwiftSourcesDirectory = fileSystem.getPath("/$KLIB_SKIE_SWIFT_DIRECTORY")
if (klib.isKlib) {
klib.writeToZip { fileSystem ->
val klibSwiftSourcesDirectory = fileSystem.getPath("/$KLIB_SKIE_SWIFT_DIRECTORY")

swiftSourcesDirectory.toPath().syncDirectoryContentIfDifferent(klibSwiftSourcesDirectory)
swiftSourcesDirectory.toPath().syncDirectoryContentIfDifferent(klibSwiftSourcesDirectory)
}
} else {
swiftSourcesDirectory.toPath().syncDirectoryContentIfDifferent(klib.toPath().resolve(KLIB_SKIE_SWIFT_DIRECTORY))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package co.touchlab.skie.plugin.switflink
import co.touchlab.skie.util.cache.syncDirectoryContentIfDifferent
import co.touchlab.skie.util.collisionFreeIdentifier
import co.touchlab.skie.util.file.deleteEmptyDirectoriesRecursively
import co.touchlab.skie.util.file.isKlib
import org.gradle.api.DefaultTask
import org.gradle.api.file.ArchiveOperations
import org.gradle.api.file.ConfigurableFileCollection
Expand Down Expand Up @@ -65,7 +66,12 @@ abstract class UnpackSwiftSourcesTask : DefaultTask() {
}

fileSystemOperations.copy {
from(archiveOperations.zipTree(klib)) {
val source = if (klib.isKlib) {
archiveOperations.zipTree(klib)
} else {
klib
}
from(source) {
include("${SwiftBundlingConfigurator.KLIB_SKIE_SWIFT_DIRECTORY}/**/*.swift")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal inline fun Project.withKotlinNativeCompilerEmbeddableDependency(kotlinV
if (isTarget) {
project.dependencies.create(
files(
kotlinNativeCompilerHome(kotlinVersion).resolve("konan/lib/kotlin-native.jar"),
kotlinNativeCompilerHome(kotlinVersion).resolve("konan/lib/kotlin-native-compiler-embeddable.jar"),
),
)
} else {
Expand Down
3 changes: 1 addition & 2 deletions common-gradle/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ kotlin.mpp.import.enableKgpDependencyResolution=true

pluginId=co.touchlab.skie

versionSupport.kotlinTooling=1.8.0(1.8.10), 1.8.20(1.8.21, 1.8.22), 1.9.0(1.9.10), 1.9.20(1.9.21, 1.9.22, 1.9.23, 1.9.24, 1.9.25), 2.0.0(2.0.10), 2.0.20(2.0.21), 2.1.0[2.1.0-RC2]
versionSupport.kotlinTooling=1.8.0(1.8.10), 1.8.20(1.8.21, 1.8.22), 1.9.0(1.9.10), 1.9.20(1.9.21, 1.9.22, 1.9.23, 1.9.24, 1.9.25), 2.0.0(2.0.10), 2.0.20(2.0.21), 2.1.0
versionSupport.gradleApi=7.3, 8.0, 8.1

touchlab.key=ABCDEFGHIJKLMNOPQRSTUVWXYZ
Expand All @@ -26,4 +26,3 @@ kotlinNativeCompilerEmbeddableFromHome=true
#kotlin.native.disableCompilerDaemon = true

kotlin.internal.compiler.arguments.log.level=info

Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,16 @@ abstract class BaseGradleTests: TestUtilsTrait, GradleBuildFileBuilderTrait {

fun copyToCommonMain(template: Template) {
template.files.forEach { file ->
val targetFile = testProjectDir
.resolve("src/commonMain/kotlin")
.resolve(file.relativePath)
val targetFile = when (file.kind) {
TemplateFile.Kind.Kotlin -> testProjectDir
.resolve("src/commonMain/kotlin")
.resolve(file.relativePath)
TemplateFile.Kind.BundledSwift -> testProjectDir
.resolve("src/commonMain/swift")
.resolve(file.relativePath)
TemplateFile.Kind.Swift -> return@forEach
}

targetFile.parentFile.mkdirs()
file.file.copyTo(targetFile)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object SkieTestRunnerConfiguration {
val configurations = list<BuildConfiguration>("matrix.configurations")
val linkModes = list<LinkMode>("matrix.linkModes")
// TODO Automatically derive from Build-setup
val kotlinVersions = list("matrix.kotlinVersions", ::KotlinVersion) ?: listOf("1.8.0", "1.8.20", "1.9.0", "1.9.20", "2.0.0").map(::KotlinVersion)
val kotlinVersions = list("matrix.kotlinVersions", ::KotlinVersion) ?: listOf("1.8.0", "1.8.20", "1.9.0", "1.9.20", "2.0.0", "2.0.20", "2.1.0").map(::KotlinVersion)
val gradleVersions = list("matrix.gradleVersions", ::GradleVersion) ?: listOf("8.6").map(::GradleVersion)

fun buildMatrixSource(): SkieTestMatrixSource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ interface TemplateBuilderScope {
fun kotlin(name: String)

fun swift(name: String)

fun bundledSwift(name: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data class TemplateFile(
) {
enum class Kind(val extension: String) {
Kotlin(".kt"),
BundledSwift(".swift"),
Swift(".swift"),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.io.File
object Templates {
val basic = buildTemplate("basic") {
kotlin("BasicSkieFeatures")
bundledSwift("BundledSwift")
swift("main")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fun buildTemplate(name: String, builder: TemplateBuilderScope.() -> Unit): Templ
val targetRelativePath = when (kind) {
TemplateFile.Kind.Kotlin -> sourceRelativePath
TemplateFile.Kind.Swift -> "templates.$name.$fileName${kind.extension}"
TemplateFile.Kind.BundledSwift -> "$fileName${kind.extension}"
}

files += TemplateFile(
Expand All @@ -27,6 +28,7 @@ fun buildTemplate(name: String, builder: TemplateBuilderScope.() -> Unit): Templ

override fun swift(name: String) = template(name, TemplateFile.Kind.Swift)

override fun bundledSwift(name: String) = template(name, TemplateFile.Kind.BundledSwift)
}

scope.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ val KotlinVersion.needsOldLinker: Boolean

val KotlinVersion.coroutinesVersion: String
get() = when {
value.startsWith("2.1.") -> "1.9.0"
value.startsWith("2.0.") -> "1.9.0-RC"
value.startsWith("1.9.2") -> "1.8.1"
value.startsWith("1.9.") || value.startsWith("1.8.2") -> "1.7.3"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public func thisIsAPublicDeclarationDoingNothing() {

}

0 comments on commit 7afb5e2

Please sign in to comment.