-
-
Notifications
You must be signed in to change notification settings - Fork 20
fix(gradle-plugin): architecture folder name missmatch when using SPM and framework path searching #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(gradle-plugin): architecture folder name missmatch when using SPM and framework path searching #320
Changes from 31 commits
f4187ef
6d6f6b2
03b12e8
a8dd89f
b2ba00f
6d90d3f
4afae70
e0f2e1b
9c82a2a
a63d95e
40dbe8a
2f5ea50
38db872
3be1bcc
c58f714
a74e90a
ca5cacc
c9bdd38
ae0e0ac
e551c09
7beec81
909fa95
0cf0e41
90dd2c0
af76fcb
e7f3958
4e73235
e1f05cc
abe48d9
524aef2
3b4d218
85a8b56
15f1eb7
c0fbf16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package io.sentry.kotlin.multiplatform.gradle | ||
|
|
||
| import org.gradle.api.GradleException | ||
| import org.gradle.api.logging.Logger | ||
| import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension | ||
| import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget | ||
|
|
||
| /** | ||
| * Configures Sentry Cocoa framework linking for Apple targets in Kotlin Multiplatform projects. | ||
| * | ||
| * Resolves framework paths and applies necessary linker options to both test and framework binaries. | ||
| */ | ||
| class CocoaFrameworkLinker( | ||
| private val logger: Logger, | ||
| private val pathResolver: FrameworkPathResolver, | ||
| private val binaryLinker: FrameworkLinker | ||
| ) { | ||
| fun configure(appleTargets: List<KotlinNativeTarget>) { | ||
| appleTargets.forEach { target -> | ||
| try { | ||
| logger.info( | ||
| "Start resolving Sentry Cocoa framework paths for target: ${target.name}" | ||
| ) | ||
| processTarget(target) | ||
| logger.lifecycle("Successfully configured Sentry Cocoa framework linking for target: ${target.name}") | ||
| } catch (e: FrameworkLinkingException) { | ||
| throw FrameworkLinkingException("Failed to configure ${target.name}: ${e.message}", e) | ||
|
Check warning on line 27 in sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoaFrameworkLinker.kt
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun processTarget(target: KotlinNativeTarget) { | ||
| val architectures = | ||
| target.toSentryFrameworkArchitecture().takeIf { it.isNotEmpty() } ?: run { | ||
| logger.warn("Skipping target ${target.name}: Unsupported architecture") | ||
|
Check warning on line 35 in sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/CocoaFrameworkLinker.kt
|
||
| return | ||
| } | ||
| val paths: FrameworkPaths = pathResolver.resolvePaths(architectures) | ||
| binaryLinker.configureBinaries(target.binaries, paths.dynamic, paths.static) | ||
| } | ||
| } | ||
|
|
||
| internal class FrameworkLinkingException( | ||
| message: String, | ||
| cause: Throwable? = null | ||
| ) : GradleException(message, cause) | ||
|
|
||
| /** | ||
| * Transforms a Kotlin Multiplatform target name to possible architecture names found inside | ||
| * Sentry's framework directory. | ||
| * | ||
| * Returns a set of possible architecture names because Sentry Cocoa SDK has changed folder naming | ||
| * across different versions. For example: | ||
| * - iosArm64 -> [SentryCocoaFrameworkArchitectures.IOS_ARM64] | ||
| * - macosArm64 -> [SentryCocoaFrameworkArchitectures.MACOS_ARM64_AND_X64] | ||
| * @return Set of possible architecture folder names for the given target. | ||
| * Returns empty set if target is not supported. | ||
| */ | ||
| internal fun KotlinNativeTarget.toSentryFrameworkArchitecture(): Set<String> = buildSet { | ||
| when (name) { | ||
| "iosSimulatorArm64", "iosX64" -> addAll(SentryCocoaFrameworkArchitectures.IOS_SIMULATOR_AND_X64) | ||
| "iosArm64" -> addAll(SentryCocoaFrameworkArchitectures.IOS_ARM64) | ||
| "macosArm64", "macosX64" -> addAll(SentryCocoaFrameworkArchitectures.MACOS_ARM64_AND_X64) | ||
| "tvosSimulatorArm64", "tvosX64" -> addAll(SentryCocoaFrameworkArchitectures.TVOS_SIMULATOR_AND_X64) | ||
| "tvosArm64" -> addAll(SentryCocoaFrameworkArchitectures.TVOS_ARM64) | ||
| "watchosArm32", "watchosArm64" -> addAll(SentryCocoaFrameworkArchitectures.WATCHOS_ARM) | ||
| "watchosSimulatorArm64", "watchosX64" -> addAll(SentryCocoaFrameworkArchitectures.WATCHOS_SIMULATOR_AND_X64) | ||
| } | ||
| } | ||
|
|
||
| internal object SentryCocoaFrameworkArchitectures { | ||
| val IOS_SIMULATOR_AND_X64 = setOf("ios-arm64_x86_64-simulator") | ||
| val IOS_ARM64 = setOf("ios-arm64", "ios-arm64_arm64e") | ||
| val MACOS_ARM64_AND_X64 = setOf("macos-arm64_x86_64", "macos-arm64_arm64e_x86_64") | ||
| val TVOS_SIMULATOR_AND_X64 = setOf("tvos-arm64_x86_64-simulator") | ||
| val TVOS_ARM64 = setOf("tvos-arm64", "tvos-arm64_arm64e") | ||
| val WATCHOS_ARM = setOf("watchos-arm64_arm64_32_armv7k", "watchos-arm64_arm64_32_arm64e_armv7k") | ||
| val WATCHOS_SIMULATOR_AND_X64 = setOf("watchos-arm64_i386_x86_64-simulator") | ||
|
|
||
| // Used for tests | ||
| val all = setOf( | ||
| IOS_SIMULATOR_AND_X64, | ||
| IOS_ARM64, | ||
| MACOS_ARM64_AND_X64, | ||
| TVOS_SIMULATOR_AND_X64, | ||
| TVOS_ARM64, | ||
| WATCHOS_ARM, | ||
| WATCHOS_SIMULATOR_AND_X64 | ||
| ) | ||
| } | ||
|
|
||
| internal fun KotlinMultiplatformExtension.appleTargets() = | ||
| targets.withType(KotlinNativeTarget::class.java).matching { | ||
| it.konanTarget.family.isAppleFamily | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package io.sentry.kotlin.multiplatform.gradle | ||
|
|
||
| import org.gradle.api.logging.Logger | ||
| import org.jetbrains.kotlin.gradle.dsl.KotlinNativeBinaryContainer | ||
| import org.jetbrains.kotlin.gradle.plugin.mpp.Framework | ||
| import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable | ||
|
|
||
| /** | ||
| * Responsible for executing the linking. | ||
| * This involves configuring and linking binaries to the Sentry Cocoa framework. | ||
| */ | ||
| class FrameworkLinker( | ||
| private val logger: Logger | ||
| ) { | ||
| fun configureBinaries( | ||
| binaries: KotlinNativeBinaryContainer, | ||
| dynamicPath: String?, | ||
| staticPath: String? | ||
| ) { | ||
| binaries.all { binary -> | ||
| when (binary) { | ||
| is TestExecutable -> linkTestBinary(binary, chooseTestPath(dynamicPath, staticPath)) | ||
| is Framework -> linkFrameworkBinary(binary, dynamicPath, staticPath) | ||
| else -> logger.info("Ignoring binary type: ${binary::class.java.simpleName}") | ||
|
Check warning on line 24 in sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/FrameworkLinker.kt
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun chooseTestPath(dynamic: String?, static: String?) = when { | ||
| dynamic != null && static != null -> { | ||
| logger.debug("Both framework types available, preferring dynamic for tests") | ||
| dynamic | ||
| } | ||
|
|
||
| dynamic != null -> dynamic | ||
| static != null -> static | ||
| else -> throw FrameworkLinkingException("No valid framework path found for tests") | ||
|
Check warning on line 37 in sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/FrameworkLinker.kt
|
||
| } | ||
|
|
||
| private fun linkTestBinary(binary: TestExecutable, path: String) { | ||
| // Linking in test binaries works with both dynamic and static framework | ||
| binary.linkerOpts("-rpath", path, "-F$path") | ||
| logger.info("Linked Sentry Cocoa framework to test binary ${binary.name}") | ||
| } | ||
|
|
||
| private fun linkFrameworkBinary(binary: Framework, dynamicPath: String?, staticPath: String?) { | ||
| val (path, type) = when { | ||
| binary.isStatic && staticPath != null -> staticPath to "static" | ||
| !binary.isStatic && dynamicPath != null -> dynamicPath to "dynamic" | ||
| else -> throw FrameworkLinkingException( | ||
| "Framework mismatch for ${binary.name}. " + | ||
|
Check warning on line 51 in sentry-kotlin-multiplatform-gradle-plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/FrameworkLinker.kt
|
||
| "Required ${if (binary.isStatic) "static" else "dynamic"} Sentry Cocoa framework not found." | ||
| ) | ||
| } | ||
|
|
||
| binary.linkerOpts("-F$path") | ||
| logger.info("Linked $type Sentry Cocoa framework to ${binary.name}") | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.