Sorted out native sourcesets, using intialization and sodium srng in js and native
This commit is contained in:
parent
ccbb8ebe5b
commit
63c5db199e
@ -17,30 +17,28 @@
|
||||
|
||||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
import com.moowork.gradle.node.task.NodeTask
|
||||
import org.gradle.api.tasks.testing.logging.TestLogging
|
||||
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||
import org.jetbrains.kotlin.konan.library.konanCommonLibraryPath
|
||||
|
||||
plugins {
|
||||
kotlin(PluginsDeps.multiplatform)
|
||||
id (PluginsDeps.mavenPublish)
|
||||
id (PluginsDeps.signing)
|
||||
id (PluginsDeps.node) version Versions.nodePlugin
|
||||
id (PluginsDeps.dokka) version Versions.dokkaPlugin
|
||||
id(PluginsDeps.mavenPublish)
|
||||
id(PluginsDeps.signing)
|
||||
id(PluginsDeps.node) version Versions.nodePlugin
|
||||
id(PluginsDeps.dokka) version Versions.dokkaPlugin
|
||||
}
|
||||
|
||||
val sonatypeStaging = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
|
||||
val sonatypeSnapshots = "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||
|
||||
val sonatypePassword : String? by project
|
||||
val sonatypePassword: String? by project
|
||||
|
||||
val sonatypeUsername : String? by project
|
||||
val sonatypeUsername: String? by project
|
||||
|
||||
val sonatypePasswordEnv : String? = System.getenv()["SONATYPE_PASSWORD"]
|
||||
val sonatypeUsernameEnv : String? = System.getenv()["SONATYPE_USERNAME"]
|
||||
val sonatypePasswordEnv: String? = System.getenv()["SONATYPE_PASSWORD"]
|
||||
val sonatypeUsernameEnv: String? = System.getenv()["SONATYPE_USERNAME"]
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@ -61,34 +59,18 @@ fun getHostOsName(): String {
|
||||
}
|
||||
|
||||
kotlin {
|
||||
|
||||
val libsodiumCompilation : org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests.() -> Unit = {
|
||||
compilations.getByName("main") {
|
||||
val libsodiumCinterop by cinterops.creating {
|
||||
defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val hostOsName = getHostOsName()
|
||||
if (ideaActive) {
|
||||
when(hostOsName) {
|
||||
"linux" -> linuxX64("native", libsodiumCompilation)
|
||||
"macos" -> macosX64("native", libsodiumCompilation)
|
||||
"windows" -> mingwX64("native", libsodiumCompilation)
|
||||
}
|
||||
}
|
||||
if (hostOsName == "linux") {
|
||||
jvm()
|
||||
js {
|
||||
browser {
|
||||
testTask {
|
||||
enabled = true //Until I sort out testing on travis
|
||||
useKarma {
|
||||
useChrome()
|
||||
browser {
|
||||
testTask {
|
||||
enabled = true //Until I sort out testing on travis
|
||||
useKarma {
|
||||
useChrome()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
nodejs {
|
||||
testTask {
|
||||
useMocha() {
|
||||
@ -99,7 +81,6 @@ kotlin {
|
||||
|
||||
}
|
||||
linuxX64("linux") {
|
||||
libsodiumCompilation(this)
|
||||
binaries {
|
||||
staticLib {
|
||||
}
|
||||
@ -192,41 +173,43 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
val nativeMain = if (ideaActive) {
|
||||
val nativeMain by getting {
|
||||
dependsOn(commonMain)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
}
|
||||
val nativeMain by creating {
|
||||
dependsOn(commonMain)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
}
|
||||
nativeMain
|
||||
} else {
|
||||
val nativeMain by creating {
|
||||
dependsOn(commonMain)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
}
|
||||
}
|
||||
nativeMain
|
||||
}
|
||||
val nativeTest = if (ideaActive) {
|
||||
val nativeTest by getting {
|
||||
dependsOn(commonTest)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
}
|
||||
|
||||
|
||||
val nativeTest by creating {
|
||||
dependsOn(commonTest)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
}
|
||||
nativeTest
|
||||
} else {
|
||||
val nativeTest by creating {
|
||||
dependsOn(commonTest)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
}
|
||||
}
|
||||
nativeTest
|
||||
}
|
||||
|
||||
targets.withType<KotlinNativeTarget> {
|
||||
println("Target $name")
|
||||
compilations.getByName("main") {
|
||||
println("Setting cinterop for $name")
|
||||
defaultSourceSet.dependsOn(nativeMain)
|
||||
if (!name.contains("ios")) {
|
||||
val libsodiumCinterop by cinterops.creating {
|
||||
defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
|
||||
}
|
||||
}
|
||||
}
|
||||
compilations.getByName("test") {
|
||||
println("Setting cinterop for $name")
|
||||
if (!name.contains("ios")) {
|
||||
defaultSourceSet.dependsOn(nativeTest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (hostOsName == "linux") {
|
||||
val jvmMain by getting {
|
||||
dependencies {
|
||||
@ -261,10 +244,22 @@ kotlin {
|
||||
}
|
||||
val linuxMain by getting {
|
||||
dependsOn(nativeMain)
|
||||
//Force idea to consider native sourceset
|
||||
if (ideaActive) {
|
||||
kotlin.srcDir("src/nativeMain/kotlin")
|
||||
}
|
||||
}
|
||||
val linuxTest by getting {
|
||||
dependsOn(nativeTest)
|
||||
//Force idea to consider native sourceset
|
||||
if (ideaActive) {
|
||||
kotlin.srcDir("src/nativeTest/kotlin")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Not supported in coroutines at the moment
|
||||
// val linuxArm32HfpMain by getting {
|
||||
// dependsOn(nativeMain)
|
||||
@ -354,9 +349,9 @@ kotlin {
|
||||
task<Copy>("copyPackageJson") {
|
||||
dependsOn("compileKotlinJs")
|
||||
println("Copying package.json from $projectDir/core/src/jsMain/npm")
|
||||
from ("$projectDir/src/jsMain/npm")
|
||||
from("$projectDir/src/jsMain/npm")
|
||||
println("Node modules dir ${node.nodeModulesDir}")
|
||||
into ("${node.nodeModulesDir}")
|
||||
into("${node.nodeModulesDir}")
|
||||
}
|
||||
|
||||
tasks {
|
||||
@ -369,14 +364,15 @@ tasks {
|
||||
}
|
||||
|
||||
dokka {
|
||||
println ("Dokka !")
|
||||
println("Dokka !")
|
||||
impliedPlatforms = mutableListOf("Common")
|
||||
kotlinTasks {
|
||||
listOf()
|
||||
}
|
||||
sourceRoot {
|
||||
println ("Common !")
|
||||
path = "/home/ionspin/Projects/Future/kotlin-multiplatform-crypto/crypto/src/commonMain" //TODO remove static path!
|
||||
println("Common !")
|
||||
path =
|
||||
"/home/ionspin/Projects/Future/kotlin-multiplatform-crypto/crypto/src/commonMain" //TODO remove static path!
|
||||
platforms = listOf("Common")
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2019 Ugljesa Jovanovic
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 com.ionspin.kotlin.crypto
|
||||
|
||||
import com.ionspin.kotlin.crypto.util.testBlocking
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 21-Sep-2019
|
||||
*/
|
||||
class SRNGTest {
|
||||
@Test
|
||||
fun testSrng() = testBlocking {
|
||||
Crypto.initialize()
|
||||
//Just a sanity test, need to add better srng tests.
|
||||
val randomBytes1 = SRNG.getRandomBytes(10)
|
||||
val randomBytes2 = SRNG.getRandomBytes(10)
|
||||
randomBytes1.forEach { println("RB1: $it")}
|
||||
randomBytes2.forEach { println("RB2: $it")}
|
||||
assertTrue { !randomBytes1.contentEquals(randomBytes2) }
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.ionspin.kotlin.crypto
|
||||
|
||||
actual object Initializer {
|
||||
actual suspend fun initialize() {
|
||||
// sodi
|
||||
}
|
||||
|
||||
actual fun initializeWithCallback(done: () -> Unit) {
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.ionspin.kotlin.crypto
|
||||
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import libsodium.sodium_init
|
||||
|
||||
actual object Initializer {
|
||||
actual suspend fun initialize() {
|
||||
GlobalScope.launch {
|
||||
sodium_init()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
actual fun initializeWithCallback(done: () -> Unit) {
|
||||
sodium_init()
|
||||
done()
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@
|
||||
package com.ionspin.kotlin.crypto
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import libsodium.randombytes_buf
|
||||
import platform.posix.*
|
||||
//import libsod
|
||||
|
||||
@ -30,7 +31,7 @@ actual object SRNG {
|
||||
actual fun getRandomBytes(amount: Int): UByteArray {
|
||||
memScoped {
|
||||
val array = allocArray<UByteVar>(amount)
|
||||
// randombytes_buf()
|
||||
randombytes_buf(array, amount.toULong())
|
||||
return UByteArray(amount) {
|
||||
array[it]
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.ionspin.kotlin.crypto.hash.blake2b
|
||||
import com.ionspin.kotlin.crypto.util.toHexString
|
||||
import interop.*
|
||||
import kotlinx.cinterop.*
|
||||
import libsodium.*
|
||||
/**
|
@ -6,6 +6,7 @@ package com.ionspin.kotlin.crypto.hash.blake2b
|
||||
* on 24-May-2020
|
||||
*/
|
||||
|
||||
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bStateless
|
||||
import com.ionspin.kotlin.crypto.util.testBlocking
|
||||
import interop.*
|
||||
import kotlinx.cinterop.*
|
@ -16,30 +16,26 @@
|
||||
*/
|
||||
|
||||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
import com.moowork.gradle.node.task.NodeTask
|
||||
import org.gradle.api.tasks.testing.logging.TestLogging
|
||||
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||
|
||||
plugins {
|
||||
kotlin(PluginsDeps.multiplatform)
|
||||
id (PluginsDeps.mavenPublish)
|
||||
id (PluginsDeps.signing)
|
||||
id (PluginsDeps.node) version Versions.nodePlugin
|
||||
id (PluginsDeps.dokka) version Versions.dokkaPlugin
|
||||
id(PluginsDeps.mavenPublish)
|
||||
id(PluginsDeps.signing)
|
||||
id(PluginsDeps.node) version Versions.nodePlugin
|
||||
id(PluginsDeps.dokka) version Versions.dokkaPlugin
|
||||
}
|
||||
|
||||
val sonatypeStaging = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
|
||||
val sonatypeSnapshots = "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||
|
||||
val sonatypePassword : String? by project
|
||||
val sonatypePassword: String? by project
|
||||
|
||||
val sonatypeUsername : String? by project
|
||||
val sonatypeUsername: String? by project
|
||||
|
||||
val sonatypePasswordEnv : String? = System.getenv()["SONATYPE_PASSWORD"]
|
||||
val sonatypeUsernameEnv : String? = System.getenv()["SONATYPE_USERNAME"]
|
||||
val sonatypePasswordEnv: String? = System.getenv()["SONATYPE_PASSWORD"]
|
||||
val sonatypeUsernameEnv: String? = System.getenv()["SONATYPE_USERNAME"]
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@ -61,13 +57,6 @@ fun getHostOsName(): String {
|
||||
|
||||
kotlin {
|
||||
val hostOsName = getHostOsName()
|
||||
if (ideaActive) {
|
||||
when(hostOsName) {
|
||||
"linux" -> linuxX64("native")
|
||||
"macos" -> macosX64("native")
|
||||
"windows" -> mingwX64("native")
|
||||
}
|
||||
}
|
||||
if (hostOsName == "linux") {
|
||||
jvm()
|
||||
js {
|
||||
@ -196,41 +185,39 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
val nativeMain = if (ideaActive) {
|
||||
val nativeMain by getting {
|
||||
dependsOn(commonMain)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
}
|
||||
|
||||
val nativeMain by creating {
|
||||
dependsOn(commonMain)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
}
|
||||
nativeMain
|
||||
} else {
|
||||
val nativeMain by creating {
|
||||
dependsOn(commonMain)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
}
|
||||
}
|
||||
nativeMain
|
||||
}
|
||||
val nativeTest = if (ideaActive) {
|
||||
val nativeTest by getting {
|
||||
dependsOn(commonTest)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
}
|
||||
|
||||
|
||||
val nativeTest by creating {
|
||||
dependsOn(commonTest)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
}
|
||||
nativeTest
|
||||
} else {
|
||||
val nativeTest by creating {
|
||||
dependsOn(commonTest)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
}
|
||||
}
|
||||
nativeTest
|
||||
}
|
||||
|
||||
targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
|
||||
compilations.getByName("main") {
|
||||
println("Setting native sourceset dependancy for $name")
|
||||
if (!name.contains("ios")) {
|
||||
defaultSourceSet.dependsOn(nativeMain)
|
||||
}
|
||||
}
|
||||
compilations.getByName("test") {
|
||||
println("Setting native sourceset dependancy for $name")
|
||||
if (!name.contains("ios")) {
|
||||
defaultSourceSet.dependsOn(nativeTest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (hostOsName == "linux") {
|
||||
val jvmMain by getting {
|
||||
dependencies {
|
||||
@ -262,9 +249,17 @@ kotlin {
|
||||
}
|
||||
val linuxMain by getting {
|
||||
dependsOn(nativeMain)
|
||||
//Force idea to consider native sourceset
|
||||
if (ideaActive) {
|
||||
kotlin.srcDir("src/nativeMain/kotlin")
|
||||
}
|
||||
}
|
||||
val linuxTest by getting {
|
||||
dependsOn(nativeTest)
|
||||
//Force idea to consider native sourceset
|
||||
if (ideaActive) {
|
||||
kotlin.srcDir("src/nativeTest/kotlin")
|
||||
}
|
||||
}
|
||||
//Not supported in coroutines at the moment
|
||||
// val linuxArm32HfpMain by getting {
|
||||
@ -355,9 +350,9 @@ kotlin {
|
||||
task<Copy>("copyPackageJson") {
|
||||
dependsOn("compileKotlinJs")
|
||||
println("Copying package.json from $projectDir/core/src/jsMain/npm")
|
||||
from ("$projectDir/src/jsMain/npm")
|
||||
from("$projectDir/src/jsMain/npm")
|
||||
println("Node modules dir ${node.nodeModulesDir}")
|
||||
into ("${node.nodeModulesDir}")
|
||||
into("${node.nodeModulesDir}")
|
||||
}
|
||||
|
||||
tasks {
|
||||
@ -370,23 +365,20 @@ tasks {
|
||||
}
|
||||
|
||||
dokka {
|
||||
println ("Dokka !")
|
||||
println("Dokka !")
|
||||
impliedPlatforms = mutableListOf("Common")
|
||||
kotlinTasks {
|
||||
listOf()
|
||||
}
|
||||
sourceRoot {
|
||||
println ("Common !")
|
||||
path = "/home/ionspin/Projects/Future/kotlin-multiplatform-crypto/crypto/src/commonMain" //TODO remove static path!
|
||||
println("Common !")
|
||||
path =
|
||||
"/home/ionspin/Projects/Future/kotlin-multiplatform-crypto/crypto/src/commonMain" //TODO remove static path!
|
||||
platforms = listOf("Common")
|
||||
}
|
||||
}
|
||||
if (getHostOsName() == "linux") {
|
||||
|
||||
val npmInstall by getting
|
||||
val compileKotlinJs by getting(AbstractCompile::class)
|
||||
val compileTestKotlinJs by getting(Kotlin2JsCompile::class)
|
||||
|
||||
val jvmTest by getting(Test::class) {
|
||||
testLogging {
|
||||
events("PASSED", "FAILED", "SKIPPED")
|
||||
@ -397,7 +389,7 @@ tasks {
|
||||
|
||||
testLogging {
|
||||
events("PASSED", "FAILED", "SKIPPED")
|
||||
// showStandardStreams = true
|
||||
// showStandardStreams = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,13 +61,6 @@ fun getHostOsName(): String {
|
||||
|
||||
kotlin {
|
||||
val hostOsName = getHostOsName()
|
||||
if (ideaActive) {
|
||||
when(hostOsName) {
|
||||
"linux" -> linuxX64("native")
|
||||
"macos" -> macosX64("native")
|
||||
"windows" -> mingwX64("native")
|
||||
}
|
||||
}
|
||||
if (hostOsName == "linux") {
|
||||
jvm()
|
||||
js {
|
||||
@ -197,39 +190,34 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
val nativeMain = if (ideaActive) {
|
||||
val nativeMain by getting {
|
||||
dependsOn(commonMain)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
}
|
||||
|
||||
val nativeMain by creating {
|
||||
dependsOn(commonMain)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
}
|
||||
nativeMain
|
||||
} else {
|
||||
val nativeMain by creating {
|
||||
dependsOn(commonMain)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
}
|
||||
}
|
||||
nativeMain
|
||||
}
|
||||
val nativeTest = if (ideaActive) {
|
||||
val nativeTest by getting {
|
||||
dependsOn(commonTest)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
|
||||
val nativeTest by creating {
|
||||
dependsOn(commonTest)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
}
|
||||
}
|
||||
|
||||
targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
|
||||
compilations.getByName("main") {
|
||||
println("Setting native sourceset dependancy for $name")
|
||||
if (!name.contains("ios")) {
|
||||
defaultSourceSet.dependsOn(nativeMain)
|
||||
}
|
||||
}
|
||||
nativeTest
|
||||
} else {
|
||||
val nativeTest by creating {
|
||||
dependsOn(commonTest)
|
||||
dependencies {
|
||||
implementation(Deps.Native.coroutines)
|
||||
compilations.getByName("test") {
|
||||
println("Setting native sourceset dependancy for $name")
|
||||
if (!name.contains("ios")) {
|
||||
defaultSourceSet.dependsOn(nativeTest)
|
||||
}
|
||||
}
|
||||
nativeTest
|
||||
}
|
||||
|
||||
if (hostOsName == "linux") {
|
||||
@ -263,9 +251,17 @@ kotlin {
|
||||
}
|
||||
val linuxMain by getting {
|
||||
dependsOn(nativeMain)
|
||||
//Force idea to consider native sourceset
|
||||
if (ideaActive) {
|
||||
kotlin.srcDir("src/nativeMain/kotlin")
|
||||
}
|
||||
}
|
||||
val linuxTest by getting {
|
||||
dependsOn(nativeTest)
|
||||
//Force idea to consider native sourceset
|
||||
if (ideaActive) {
|
||||
kotlin.srcDir("src/nativeTest/kotlin")
|
||||
}
|
||||
}
|
||||
//Not supported in coroutines at the moment
|
||||
// val linuxArm32HfpMain by getting {
|
||||
|
Loading…
x
Reference in New Issue
Block a user