Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 5 additions & 18 deletions library/crypto-rand/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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 {
Expand All @@ -51,19 +52,5 @@ kmpConfiguration {
}
}
}

kotlin {
val cInteropDir = projectDir
.resolve("src")
.resolve("nativeInterop")
.resolve("cinterop")

targets.filterIsInstance<KotlinNativeTarget>().forEach target@ { target ->
if (target.konanTarget.family != Family.ANDROID) return@target
target.compilations["main"].cinterops.create("syscall") {
definitionFile.set(cInteropDir.resolve("$name.def"))
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions library/internal-cinterop/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
7 changes: 7 additions & 0 deletions library/internal-cinterop/README.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions library/internal-cinterop/api/internal-cinterop.klib.api
Original file line number Diff line number Diff line change
@@ -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: <org.kotlincrypto.random:internal-cinterop>
49 changes: 49 additions & 0 deletions library/internal-cinterop/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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<KotlinNativeTarget>().forEach target@ { target ->
if (target.konanTarget.family != Family.ANDROID) return@target
target.compilations["main"].cinterops.create("syscall") {
definitionFile.set(cInteropDir.resolve("$name.def"))
}
}
}
}
}
16 changes: 16 additions & 0 deletions library/internal-cinterop/gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 */ }
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# SYS_getrandom for AndroidNative targets
package = org.kotlincrypto.random.internal
package = org.kotlincrypto.random.internal.cinterop
headers = sys/syscall.h
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if (CHECK_PUBLICATION != null) {
} else {
listOf(
"crypto-rand",
"internal-cinterop",
).forEach { name ->
include(":library:$name")
}
Expand Down
10 changes: 10 additions & 0 deletions tools/check-publication/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,15 @@ kmpConfiguration {
}
}
}

kotlin {
with(sourceSets) {
findByName("androidNativeMain")?.apply {
dependencies {
implementation("$group:internal-cinterop:$version")
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down