diff --git a/library/crypto-rand/build.gradle.kts b/library/crypto-rand/build.gradle.kts index b518f76..ac31ec5 100644 --- a/library/crypto-rand/build.gradle.kts +++ b/library/crypto-rand/build.gradle.kts @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.jetbrains.kotlin.konan.target.Family - plugins { id("configuration") } @@ -33,7 +30,11 @@ kmpConfiguration { kotlin { with(sourceSets) { val linuxMain = findByName("linuxMain") - val androidNativeMain = findByName("androidNativeMain") + val androidNativeMain = findByName("androidNativeMain")?.apply { + dependencies { + implementation(project(":library:internal-cinterop")) + } + } if (linuxMain != null || androidNativeMain != null) { val linuxAndroidMain = maybeCreate("linuxAndroidMain").apply { @@ -51,19 +52,5 @@ kmpConfiguration { } } } - - kotlin { - val cInteropDir = projectDir - .resolve("src") - .resolve("nativeInterop") - .resolve("cinterop") - - targets.filterIsInstance().forEach target@ { target -> - if (target.konanTarget.family != Family.ANDROID) return@target - target.compilations["main"].cinterops.create("syscall") { - definitionFile.set(cInteropDir.resolve("$name.def")) - } - } - } } } diff --git a/library/crypto-rand/src/androidNativeMain/kotlin/org/kotlincrypto/random/internal/AndroidNativePlatform.kt b/library/crypto-rand/src/androidNativeMain/kotlin/org/kotlincrypto/random/internal/AndroidNativePlatform.kt index beb2d8e..b665724 100644 --- a/library/crypto-rand/src/androidNativeMain/kotlin/org/kotlincrypto/random/internal/AndroidNativePlatform.kt +++ b/library/crypto-rand/src/androidNativeMain/kotlin/org/kotlincrypto/random/internal/AndroidNativePlatform.kt @@ -18,6 +18,7 @@ package org.kotlincrypto.random.internal import kotlinx.cinterop.ExperimentalForeignApi +import org.kotlincrypto.random.internal.cinterop.SYS_getrandom @OptIn(ExperimentalForeignApi::class) internal actual inline fun _SYS_getrandom(): Int = SYS_getrandom diff --git a/library/internal-cinterop/.gitignore b/library/internal-cinterop/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/library/internal-cinterop/.gitignore @@ -0,0 +1 @@ +/build diff --git a/library/internal-cinterop/README.md b/library/internal-cinterop/README.md new file mode 100644 index 0000000..f6975d1 --- /dev/null +++ b/library/internal-cinterop/README.md @@ -0,0 +1,7 @@ +# Module internal-cinterop + +An internal module for which `crypto-rand` depends on. This is to transparently "hide" cinterop from +`crypto-rand` consumers because Kotlin's generated `.knm` files are all `public` visibility. + +This publication SHOULD NOT BE USED and will go away when [KT-75722](https://youtrack.jetbrains.com/issue/KT-75722) +is resolved. diff --git a/library/internal-cinterop/api/internal-cinterop.klib.api b/library/internal-cinterop/api/internal-cinterop.klib.api new file mode 100644 index 0000000..9f3a608 --- /dev/null +++ b/library/internal-cinterop/api/internal-cinterop.klib.api @@ -0,0 +1,8 @@ +// Klib ABI Dump +// Targets: [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86] +// Rendering settings: +// - Signature version: 2 +// - Show manifest properties: true +// - Show declarations: true + +// Library unique name: diff --git a/library/internal-cinterop/build.gradle.kts b/library/internal-cinterop/build.gradle.kts new file mode 100644 index 0000000..150ee00 --- /dev/null +++ b/library/internal-cinterop/build.gradle.kts @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 KotlinCrypto + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.konan.target.Family + +plugins { + id("configuration") +} + +kmpConfiguration { + configure { + options { + useUniqueModuleNames = true + } + + androidNativeAll() + + common { pluginIds("publication") } + + kotlin { explicitApi() } + + kotlin { + val cInteropDir = projectDir + .resolve("src") + .resolve("nativeInterop") + .resolve("cinterop") + + targets.filterIsInstance().forEach target@ { target -> + if (target.konanTarget.family != Family.ANDROID) return@target + target.compilations["main"].cinterops.create("syscall") { + definitionFile.set(cInteropDir.resolve("$name.def")) + } + } + } + } +} diff --git a/library/internal-cinterop/gradle.properties b/library/internal-cinterop/gradle.properties new file mode 100644 index 0000000..048dacb --- /dev/null +++ b/library/internal-cinterop/gradle.properties @@ -0,0 +1,16 @@ +# Copyright (c) 2023 KotlinCrypto +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +POM_ARTIFACT_ID=internal-cinterop +POM_NAME=Internal Module. Do not use. +POM_DESCRIPTION=Module for crypto-rand to consume in order to not expose cinterop declarations publicly diff --git a/library/internal-cinterop/src/commonMain/kotlin/org/kotlincrypto/random/internal/cinterop/Stub.kt b/library/internal-cinterop/src/commonMain/kotlin/org/kotlincrypto/random/internal/cinterop/Stub.kt new file mode 100644 index 0000000..87c1bbe --- /dev/null +++ b/library/internal-cinterop/src/commonMain/kotlin/org/kotlincrypto/random/internal/cinterop/Stub.kt @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 KotlinCrypto + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ +package org.kotlincrypto.random.internal.cinterop + +@Suppress("unused") +internal fun stub() { /* no-op */ } diff --git a/library/crypto-rand/src/nativeInterop/cinterop/syscall.def b/library/internal-cinterop/src/nativeInterop/cinterop/syscall.def similarity index 55% rename from library/crypto-rand/src/nativeInterop/cinterop/syscall.def rename to library/internal-cinterop/src/nativeInterop/cinterop/syscall.def index e0c90af..6f1449d 100644 --- a/library/crypto-rand/src/nativeInterop/cinterop/syscall.def +++ b/library/internal-cinterop/src/nativeInterop/cinterop/syscall.def @@ -1,3 +1,3 @@ # SYS_getrandom for AndroidNative targets -package = org.kotlincrypto.random.internal +package = org.kotlincrypto.random.internal.cinterop headers = sys/syscall.h diff --git a/settings.gradle.kts b/settings.gradle.kts index 2a86410..e291db1 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -17,6 +17,7 @@ if (CHECK_PUBLICATION != null) { } else { listOf( "crypto-rand", + "internal-cinterop", ).forEach { name -> include(":library:$name") } diff --git a/tools/check-publication/build.gradle.kts b/tools/check-publication/build.gradle.kts index 849f78f..3065159 100644 --- a/tools/check-publication/build.gradle.kts +++ b/tools/check-publication/build.gradle.kts @@ -43,5 +43,15 @@ kmpConfiguration { } } } + + kotlin { + with(sourceSets) { + findByName("androidNativeMain")?.apply { + dependencies { + implementation("$group:internal-cinterop:$version") + } + } + } + } } } diff --git a/tools/check-publication/src/commonMain/kotlin/tools/check/publication/Stub.kt b/tools/check-publication/src/commonMain/kotlin/tools/check/publication/Stub.kt index 780ebf2..d7cb5db 100644 --- a/tools/check-publication/src/commonMain/kotlin/tools/check/publication/Stub.kt +++ b/tools/check-publication/src/commonMain/kotlin/tools/check/publication/Stub.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 KotlinCrypto + * Copyright (c) 2025 KotlinCrypto * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.