From cabb25d3e0d90fe03fc98140781cb564f10beb23 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Wed, 5 Jul 2023 15:49:55 +0200 Subject: [PATCH] Native: add -Xdisable-experimental-annotation flag to cinterop It disables adding `ExperimentalForeignApi` opt-in to declarations generated by cinterop. Main use case is platform libraries, which are not supposed to have this annotation. Applying the flag to user cinterop libraries is discouraged and effectively means opting in. ^KT-58362 --- .../org/jetbrains/kotlin/native/interop/gen/jvm/CommandLine.kt | 3 +++ .../kotlin/native/interop/gen/jvm/InteropConfiguration.kt | 1 + .../kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt | 1 + 3 files changed, 5 insertions(+) diff --git a/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/CommandLine.kt b/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/CommandLine.kt index 135eb91fc9a..e327384d630 100644 --- a/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/CommandLine.kt +++ b/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/CommandLine.kt @@ -136,6 +136,9 @@ open class CInteropArguments(argParser: ArgParser = val userSetupHint by argParser.option(ArgType.String, USER_SETUP_HINT, description = "A suggestion that is displayed to the user if produced lib fails to link") + + val disableExperimentalAnnotation by argParser.option(ArgType.Boolean, "Xdisable-experimental-annotation", + description = "Don't add @ExperimentalForeignApi to generated Kotlin declarations") } class JSInteropArguments(argParser: ArgParser = ArgParser("jsinterop", diff --git a/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/InteropConfiguration.kt b/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/InteropConfiguration.kt index e82e37083a2..1fd8416e1be 100644 --- a/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/InteropConfiguration.kt +++ b/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/InteropConfiguration.kt @@ -32,6 +32,7 @@ class InteropConfiguration( val noStringConversion: Set, val exportForwardDeclarations: List, val disableDesignatedInitializerChecks: Boolean, + val disableExperimentalAnnotation: Boolean, val target: KonanTarget ) diff --git a/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt b/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt index c0dc5d52bc9..ff7843c0633 100644 --- a/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt +++ b/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt @@ -326,6 +326,7 @@ private fun processCLib( noStringConversion = def.config.noStringConversion.toSet(), exportForwardDeclarations = def.config.exportForwardDeclarations, disableDesignatedInitializerChecks = def.config.disableDesignatedInitializerChecks, + disableExperimentalAnnotation = cinteropArguments.disableExperimentalAnnotation ?: false, target = target )