Skip to content

Commit 9336430

Browse files
authored
Move AndroidNative cinterop to separate module as to not expose definitions in crypto-rand public API (#38)
1 parent 735d05b commit 9336430

File tree

12 files changed

+119
-20
lines changed

12 files changed

+119
-20
lines changed

library/crypto-rand/build.gradle.kts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
**/
16-
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
17-
import org.jetbrains.kotlin.konan.target.Family
18-
1916
plugins {
2017
id("configuration")
2118
}
@@ -33,7 +30,11 @@ kmpConfiguration {
3330
kotlin {
3431
with(sourceSets) {
3532
val linuxMain = findByName("linuxMain")
36-
val androidNativeMain = findByName("androidNativeMain")
33+
val androidNativeMain = findByName("androidNativeMain")?.apply {
34+
dependencies {
35+
implementation(project(":library:internal-cinterop"))
36+
}
37+
}
3738

3839
if (linuxMain != null || androidNativeMain != null) {
3940
val linuxAndroidMain = maybeCreate("linuxAndroidMain").apply {
@@ -51,19 +52,5 @@ kmpConfiguration {
5152
}
5253
}
5354
}
54-
55-
kotlin {
56-
val cInteropDir = projectDir
57-
.resolve("src")
58-
.resolve("nativeInterop")
59-
.resolve("cinterop")
60-
61-
targets.filterIsInstance<KotlinNativeTarget>().forEach target@ { target ->
62-
if (target.konanTarget.family != Family.ANDROID) return@target
63-
target.compilations["main"].cinterops.create("syscall") {
64-
definitionFile.set(cInteropDir.resolve("$name.def"))
65-
}
66-
}
67-
}
6855
}
6956
}

library/crypto-rand/src/androidNativeMain/kotlin/org/kotlincrypto/random/internal/AndroidNativePlatform.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.kotlincrypto.random.internal
1919

2020
import kotlinx.cinterop.ExperimentalForeignApi
21+
import org.kotlincrypto.random.internal.cinterop.SYS_getrandom
2122

2223
@OptIn(ExperimentalForeignApi::class)
2324
internal actual inline fun _SYS_getrandom(): Int = SYS_getrandom
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Module internal-cinterop
2+
3+
An internal module for which `crypto-rand` depends on. This is to transparently "hide" cinterop from
4+
`crypto-rand` consumers because Kotlin's generated `.knm` files are all `public` visibility.
5+
6+
This publication SHOULD NOT BE USED and will go away when [KT-75722](https://youtrack.jetbrains.com/issue/KT-75722)
7+
is resolved.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Klib ABI Dump
2+
// Targets: [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86]
3+
// Rendering settings:
4+
// - Signature version: 2
5+
// - Show manifest properties: true
6+
// - Show declarations: true
7+
8+
// Library unique name: <org.kotlincrypto.random:internal-cinterop>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2025 KotlinCrypto
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
17+
import org.jetbrains.kotlin.konan.target.Family
18+
19+
plugins {
20+
id("configuration")
21+
}
22+
23+
kmpConfiguration {
24+
configure {
25+
options {
26+
useUniqueModuleNames = true
27+
}
28+
29+
androidNativeAll()
30+
31+
common { pluginIds("publication") }
32+
33+
kotlin { explicitApi() }
34+
35+
kotlin {
36+
val cInteropDir = projectDir
37+
.resolve("src")
38+
.resolve("nativeInterop")
39+
.resolve("cinterop")
40+
41+
targets.filterIsInstance<KotlinNativeTarget>().forEach target@ { target ->
42+
if (target.konanTarget.family != Family.ANDROID) return@target
43+
target.compilations["main"].cinterops.create("syscall") {
44+
definitionFile.set(cInteropDir.resolve("$name.def"))
45+
}
46+
}
47+
}
48+
}
49+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) 2023 KotlinCrypto
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
POM_ARTIFACT_ID=internal-cinterop
15+
POM_NAME=Internal Module. Do not use.
16+
POM_DESCRIPTION=Module for crypto-rand to consume in order to not expose cinterop declarations publicly
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2025 KotlinCrypto
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
package org.kotlincrypto.random.internal.cinterop
17+
18+
@Suppress("unused")
19+
internal fun stub() { /* no-op */ }
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# SYS_getrandom for AndroidNative targets
2-
package = org.kotlincrypto.random.internal
2+
package = org.kotlincrypto.random.internal.cinterop
33
headers = sys/syscall.h

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if (CHECK_PUBLICATION != null) {
1717
} else {
1818
listOf(
1919
"crypto-rand",
20+
"internal-cinterop",
2021
).forEach { name ->
2122
include(":library:$name")
2223
}

0 commit comments

Comments
 (0)