Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ abstract class ComposePlugin : Plugin<Project> {
project.configureWebCompatibility()

project.configureRuntimeLibrariesCompatibilityCheck()
project.configureSwiftCompatibilityLinking()

project.afterEvaluate {
configureDesktop(project, desktopExtension)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2026 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/

package org.jetbrains.compose

import org.gradle.api.Project
import org.jetbrains.compose.internal.KOTLIN_MPP_PLUGIN_ID
import org.jetbrains.compose.internal.mppExt
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBinary
import org.jetbrains.kotlin.konan.target.KonanTarget
import java.io.File

/** Configures iOS linker tasks to resolve the active Xcode's Swift compatibility-library path at link time. */
internal fun Project.configureSwiftCompatibilityLinking() {
plugins.withId(KOTLIN_MPP_PLUGIN_ID) {
mppExt.targets.withType(KotlinNativeTarget::class.java).all { target ->
target.configureSwiftCompatibilityLinking()
}
}
}

private fun KotlinNativeTarget.configureSwiftCompatibilityLinking() {
if (System.getProperty("os.name") != "Mac OS X") return
Comment on lines +25 to +26

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When Gradle caches the configuration phase, it must be aware of all environment variables and system properties that affect the build.

There is a proper API:
if (!OperatingSystem.current().isMacOsX) return


val sdkName =
when (konanTarget) {
KonanTarget.IOS_ARM64 -> "iphoneos"
KonanTarget.IOS_X64,
KonanTarget.IOS_SIMULATOR_ARM64 -> "iphonesimulator"
else -> return
}
val swiftCompatibilityLibraryDir =
project.providers
.exec { spec -> spec.commandLine("xcrun", "--find", "swiftc") }
.standardOutput
.asText
.map { swiftcPath ->
File(swiftcPath.trim())
.parentFile
.parentFile
.parentFile
.resolve("usr/lib/swift/$sdkName")
.absolutePath
Comment on lines +42 to +46

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract and add a comment with an explanation, please.

}

binaries.withType(NativeBinary::class.java).all { binary ->
binary.linkTaskProvider.configure { linkTask ->
linkTask.toolOptions.freeCompilerArgs.addAll(
swiftCompatibilityLibraryDir.map { libraryDir ->
listOf("-linker-option", "-L$libraryDir")
}
)
}
}
}
Loading