Skip to content

Commit 4984d35

Browse files
Add stubs/no-op support for unsupported targets (#426)
* Update Kotlin and Compose version * Missing newline * Update * Update deprecations * Fix K2 compiler issue * Formatting * Fix test * Update * Update * Formatting * Formatting * Fix Java 11 config * Bump test lib versions * Versions * Java config * Update * Enable debug temporarily * Revert * Update * Update * Update * Line end * Formatting * Add toolchain to java block * Update CHANGELOG * Add JavaScript (JS) target support for Sentry Kotlin Multiplatform SDK Co-authored-by: giancarlo.buenaflor <[email protected]> * Update publication * Update * Update * Update * Update * Update * Let CI run for testing * Update * Update * Update * Update * Update * Clean up * Update publicatiojn * Add support for stub sourceSet * Add wasmJs support * Update * Update * Analyze * Fix analyze * Update CHANGELOG * Update SentryPlatformOptions.commonStub.kt * Update --------- Co-authored-by: Cursor Agent <[email protected]>
1 parent ab2b2a4 commit 4984d35

File tree

13 files changed

+219
-5
lines changed

13 files changed

+219
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Features
6+
7+
- Add stubs/no-op support for unsupported targets ([#426](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/426))
8+
39
## 0.16.0
410

511
Potentially breaking: this release bumps the used Kotlin version to `2.1.21`.

build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import com.diffplug.spotless.LineEnding
22
import com.vanniktech.maven.publish.MavenPublishPlugin
33
import com.vanniktech.maven.publish.MavenPublishPluginExtension
44
import io.gitlab.arturbosch.detekt.Detekt
5+
import org.jetbrains.dokka.gradle.DokkaTask
56
import java.util.zip.ZipFile
67

78
plugins {
@@ -161,6 +162,13 @@ private fun Project.validateKotlinMultiplatformCoreArtifacts() {
161162

162163
subprojects {
163164
if (project.name.contains("sentry-kotlin-multiplatform")) {
165+
tasks.withType<DokkaTask>().configureEach {
166+
dokkaSourceSets.configureEach {
167+
if (name.endsWith("Test")) {
168+
suppress.set(true)
169+
}
170+
}
171+
}
164172
apply(plugin = Config.dokka)
165173
}
166174
}

buildSrc/src/main/java/Publication.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ fun DistributionContainer.configureForMultiplatform(project: Project, buildPubli
2626
"watchosarm32" to "$projectName-watchosarm32",
2727
"watchosarm64" to "$projectName-watchosarm64",
2828
"watchossimulatorarm64" to "$projectName-watchossimulatorarm64",
29-
"watchosx64" to "$projectName-watchosx64"
29+
"watchosx64" to "$projectName-watchosx64",
30+
"js" to "$projectName-js",
31+
"wasm-js" to "$projectName-wasm-js",
32+
"mingwx64" to "$projectName-mingwx64",
33+
"linuxarm64" to "$projectName-linuxarm64",
34+
"linuxx64" to "$projectName-linuxx64"
3035
)
3136

3237
platforms.forEach { (distName, projectName) ->

sentry-kotlin-multiplatform/build.gradle.kts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
@file:OptIn(ExperimentalWasmDsl::class)
2+
13
import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING
24
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
5+
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
6+
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
37
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
48
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
59

@@ -63,6 +67,7 @@ kotlin {
6367
tvosX64()
6468
macosX64()
6569
macosArm64()
70+
addNoOpTargets()
6671

6772
sourceSets {
6873
@OptIn(ExperimentalKotlinGradlePluginApi::class)
@@ -185,8 +190,10 @@ kotlin {
185190

186191
// workaround for https://youtrack.jetbrains.com/issue/KT-41709 due to having "Meta" in the class name
187192
// if we need to use this class, we'd need to find a better way to work it out
188-
targets.withType<KotlinNativeTarget>().all {
189-
compilations["main"].cinterops["Sentry"].extraOpts(
193+
targets.withType<KotlinNativeTarget>().matching {
194+
it.konanTarget.family.isAppleFamily
195+
}.forEach { target ->
196+
target.compilations["main"].cinterops["Sentry"].extraOpts(
190197
"-compiler-option",
191198
"-DSentryMechanismMeta=SentryMechanismMetaUnavailable",
192199
"-compiler-option",
@@ -195,6 +202,14 @@ kotlin {
195202
"-DSentryMetricsAPIDelegate=SentryMetricsAPIDelegateUnavailable"
196203
)
197204
}
205+
206+
val commonStub by creating {
207+
dependsOn(commonMain.get())
208+
}
209+
jsMain.get().dependsOn(commonStub)
210+
wasmJsMain.get().dependsOn(commonStub)
211+
linuxMain.get().dependsOn(commonStub)
212+
mingwMain.get().dependsOn(commonStub)
198213
}
199214
}
200215

@@ -216,3 +231,25 @@ buildkonfig {
216231
buildConfigField(STRING, "SENTRY_COCOA_VERSION", Config.Libs.sentryCocoaVersion)
217232
}
218233
}
234+
235+
private fun KotlinMultiplatformExtension.addNoOpTargets() {
236+
js(IR) {
237+
browser()
238+
binaries.library()
239+
compilations.remove(compilations.getByName("test"))
240+
}
241+
wasmJs {
242+
browser()
243+
binaries.library()
244+
compilations.remove(compilations.getByName("test"))
245+
}
246+
mingwX64 {
247+
compilations.remove(compilations.getByName("test"))
248+
}
249+
linuxArm64 {
250+
compilations.remove(compilations.getByName("test"))
251+
}
252+
linuxX64 {
253+
compilations.remove(compilations.getByName("test"))
254+
}
255+
}

sentry-kotlin-multiplatform/sentry_kotlin_multiplatform.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ Pod::Spec.new do |spec|
5454
}
5555
]
5656

57-
end
57+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package io.sentry.kotlin.multiplatform
2+
3+
public actual class Attachment {
4+
5+
public actual val bytes: ByteArray?
6+
public actual val contentType: String?
7+
public actual val pathname: String?
8+
public actual val filename: String
9+
10+
public actual companion object {
11+
public actual fun fromScreenshot(screenshotBytes: ByteArray): Attachment =
12+
Attachment(screenshotBytes, "screenshot.png", "image/png")
13+
}
14+
15+
public actual constructor(bytes: ByteArray, filename: String) {
16+
this.bytes = null
17+
this.pathname = null
18+
this.filename = ""
19+
this.contentType = null
20+
}
21+
22+
public actual constructor(bytes: ByteArray, filename: String, contentType: String?) {
23+
this.bytes = null
24+
this.pathname = null
25+
this.filename = ""
26+
this.contentType = null
27+
}
28+
29+
public actual constructor(pathname: String) {
30+
this.bytes = null
31+
this.pathname = null
32+
this.filename = ""
33+
this.contentType = null
34+
}
35+
36+
public actual constructor(pathname: String, filename: String) {
37+
this.bytes = null
38+
this.pathname = null
39+
this.filename = ""
40+
this.contentType = null
41+
}
42+
43+
public actual constructor(pathname: String, filename: String, contentType: String?) {
44+
this.bytes = null
45+
this.pathname = null
46+
this.filename = ""
47+
this.contentType = null
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package io.sentry.kotlin.multiplatform
2+
3+
public actual abstract class Context
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package io.sentry.kotlin.multiplatform
2+
3+
import io.sentry.kotlin.multiplatform.protocol.Breadcrumb
4+
import io.sentry.kotlin.multiplatform.protocol.SentryId
5+
import io.sentry.kotlin.multiplatform.protocol.User
6+
import io.sentry.kotlin.multiplatform.protocol.UserFeedback
7+
8+
@Suppress("UnusedPrivateMember")
9+
internal actual class SentryBridge actual constructor(
10+
private val sentryInstance: SentryInstance
11+
) {
12+
actual fun init(context: Context, configuration: OptionsConfiguration) {
13+
// No-op
14+
}
15+
16+
actual fun init(configuration: OptionsConfiguration) {
17+
// No-op
18+
}
19+
20+
actual fun initWithPlatformOptions(configuration: PlatformOptionsConfiguration) {
21+
// No-op
22+
}
23+
24+
actual fun captureMessage(message: String): SentryId {
25+
return SentryId.EMPTY_ID
26+
}
27+
28+
actual fun captureMessage(message: String, scopeCallback: ScopeCallback): SentryId {
29+
return SentryId.EMPTY_ID
30+
}
31+
32+
actual fun captureException(throwable: Throwable): SentryId {
33+
return SentryId.EMPTY_ID
34+
}
35+
36+
actual fun captureException(throwable: Throwable, scopeCallback: ScopeCallback): SentryId {
37+
return SentryId.EMPTY_ID
38+
}
39+
40+
actual fun configureScope(scopeCallback: ScopeCallback) {
41+
// No-op
42+
}
43+
44+
actual fun captureUserFeedback(userFeedback: UserFeedback) {
45+
// No-op
46+
}
47+
48+
actual fun addBreadcrumb(breadcrumb: Breadcrumb) {
49+
// No-op
50+
}
51+
52+
actual fun setUser(user: User?) {
53+
// No-op
54+
}
55+
56+
actual fun isCrashedLastRun(): Boolean {
57+
return false
58+
}
59+
60+
actual fun isEnabled(): Boolean {
61+
return false
62+
}
63+
64+
actual fun close() {
65+
// No-op
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.sentry.kotlin.multiplatform
2+
3+
import io.sentry.kotlin.multiplatform.protocol.Message
4+
import io.sentry.kotlin.multiplatform.protocol.SentryException
5+
6+
public actual class SentryEvent actual constructor() : SentryBaseEvent() {
7+
public actual var message: Message? = null
8+
public actual var logger: String? = null
9+
public actual var level: SentryLevel? = null
10+
public actual var fingerprint: MutableList<String> = mutableListOf()
11+
public actual var exceptions: MutableList<SentryException> = mutableListOf()
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.sentry.kotlin.multiplatform
2+
3+
internal actual class SentryPlatformInstance : SentryInstance {
4+
actual override fun init(configuration: PlatformOptionsConfiguration) {
5+
// No-op
6+
}
7+
}

0 commit comments

Comments
 (0)