From 3f7df6c651c4697821582091affc41b57209d856 Mon Sep 17 00:00:00 2001 From: Ugljesa Jovanovic Date: Sun, 24 May 2020 17:24:32 +0200 Subject: [PATCH] Adding libsodium --- multiplatform-crypto-api/build.gradle.kts | 124 ------------------ .../build.gradle.kts | 23 +++- .../crypto/hash/blake2b/Blake2bDelegated.kt | 3 +- .../ionspin/kotlin/bignum/integer/Placeholder | 0 .../crypto/hash/blake2b/Blake2bLinuxTest.kt | 23 ++++ .../src/nativeInterop/cinterop/libsodium.def | 6 +- 6 files changed, 49 insertions(+), 130 deletions(-) delete mode 100644 multiplatform-crypto-delegated/src/linuxTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder create mode 100644 multiplatform-crypto-delegated/src/linuxTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bLinuxTest.kt diff --git a/multiplatform-crypto-api/build.gradle.kts b/multiplatform-crypto-api/build.gradle.kts index ab1fe53..0f5ad6d 100644 --- a/multiplatform-crypto-api/build.gradle.kts +++ b/multiplatform-crypto-api/build.gradle.kts @@ -49,13 +49,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 { @@ -171,8 +164,6 @@ kotlin { dependencies { implementation(kotlin(Deps.Common.stdLib)) implementation(kotlin(Deps.Common.test)) - implementation(Deps.Common.coroutines) - implementation(Deps.Common.kotlinBigNum) } } val commonTest by getting { @@ -182,41 +173,6 @@ kotlin { } } - val nativeMain = if (ideaActive) { - val nativeMain by getting { - 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) - } - } - nativeTest - } else { - val nativeTest by creating { - dependsOn(commonTest) - dependencies { - implementation(Deps.Native.coroutines) - } - } - nativeTest - } - if (hostOsName == "linux") { val jvmMain by getting { dependencies { @@ -246,88 +202,8 @@ kotlin { implementation(kotlin(Deps.Js.test)) } } - val linuxMain by getting { - dependsOn(nativeMain) - } - val linuxTest by getting { - dependsOn(nativeTest) - } - //Not supported in coroutines at the moment -// val linuxArm32HfpMain by getting { -// dependsOn(nativeMain) -// } -// -// val linuxArm32HfpTest by getting { -// dependsOn(nativeTest) -// } - -// val linuxArm64Main by getting { -// dependsOn(nativeMain) -// } -// -// val linuxArm64Test by getting { -// dependsOn(nativeTest) -// } - } - if (hostOsName == "macos") { - - val iosMain by getting { - dependsOn(nativeMain) - } - val iosTest by getting { - dependsOn(nativeTest) - } - - val ios64ArmMain by getting { - dependsOn(nativeMain) - } - val ios64ArmTest by getting { - dependsOn(nativeTest) - } - - val ios32ArmMain by getting { - dependsOn(nativeMain) - } - val ios32ArmTest by getting { - dependsOn(nativeTest) - } - - val macosX64Main by getting { - dependsOn(nativeMain) - } - val macosX64Test by getting { - dependsOn(nativeTest) - } - } - -// Coroutines don't support mingwx86 yet -// val mingwX86Main by getting { -// dependsOn(commonMain) -// dependencies { -// implementation(Deps.Native.coroutines) -// } -// } - -// val mingwX86Test by getting { -// dependsOn(commonTest) -// } -// - if (hostOsName == "windows") { - val mingwX64Main by getting { - dependsOn(commonMain) - dependencies { - implementation(Deps.Native.coroutines) - } - } - - val mingwX64Test by getting { - dependsOn(commonTest) - } - } - - all { languageSettings.enableLanguageFeature("InlineClasses") } diff --git a/multiplatform-crypto-delegated/build.gradle.kts b/multiplatform-crypto-delegated/build.gradle.kts index 7c59ec3..e43b981 100644 --- a/multiplatform-crypto-delegated/build.gradle.kts +++ b/multiplatform-crypto-delegated/build.gradle.kts @@ -89,6 +89,11 @@ kotlin { } linuxX64("linux") { + compilations.getByName("main") { + val libsodiumCinterop by cinterops.creating { + defFile(project.file("src/nativeInterop/cinterop/libsodium.def")) + } + } binaries { staticLib { optimized = true @@ -383,14 +388,14 @@ tasks { testLogging { events("PASSED", "FAILED", "SKIPPED") - // showStandardStreams = true + showStandardStreams = true } } val jsNodeTest by getting(KotlinJsTest::class) { testLogging { events("PASSED", "FAILED", "SKIPPED") - showStandardStreams = true +// showStandardStreams = true } } @@ -479,4 +484,18 @@ publishing { } } +//configurations.forEach { +// +// if (it.name == "linuxCompileKlibraries") { +// println("Configuration name: ${it.name}") +// it.attributes { +// this.keySet().forEach { key -> +// val attribute = getAttribute(key) +// println(" |-- Attribute $key ${attribute}") +// attribute(org.jetbrains.kotlin.gradle.plugin.ProjectLocalConfigurations.ATTRIBUTE, "publicZ") +// } +// } +// } +//} + diff --git a/multiplatform-crypto-delegated/src/linuxMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt b/multiplatform-crypto-delegated/src/linuxMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt index 95758a3..4b235f1 100644 --- a/multiplatform-crypto-delegated/src/linuxMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt +++ b/multiplatform-crypto-delegated/src/linuxMain/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bDelegated.kt @@ -1,5 +1,6 @@ package com.ionspin.kotlin.crypto.hash.blake2b - +import interop.* +import kotlinx.cinterop.* /** * Created by Ugljesa Jovanovic * ugljesa.jovanovic@ionspin.com diff --git a/multiplatform-crypto-delegated/src/linuxTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder b/multiplatform-crypto-delegated/src/linuxTest/kotlin/com/ionspin/kotlin/bignum/integer/Placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/multiplatform-crypto-delegated/src/linuxTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bLinuxTest.kt b/multiplatform-crypto-delegated/src/linuxTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bLinuxTest.kt new file mode 100644 index 0000000..7427ca5 --- /dev/null +++ b/multiplatform-crypto-delegated/src/linuxTest/kotlin/com/ionspin/kotlin/crypto/hash/blake2b/Blake2bLinuxTest.kt @@ -0,0 +1,23 @@ +package com.ionspin.kotlin.crypto.hash.blake2b + +/** + * Created by Ugljesa Jovanovic + * ugljesa.jovanovic@ionspin.com + * on 24-May-2020 + */ + +import interop.* +import kotlinx.cinterop.* +import libsodium.* + +import kotlin.test.Test + +class Blake2bLinuxTest { + + @Test + fun testCinterop() { + val sodiumInitResult = sodium_init() +// println("Sodium init $sodiumInitResult") + println("1") + } +} \ No newline at end of file diff --git a/multiplatform-crypto-delegated/src/nativeInterop/cinterop/libsodium.def b/multiplatform-crypto-delegated/src/nativeInterop/cinterop/libsodium.def index bc35402..1be50a3 100644 --- a/multiplatform-crypto-delegated/src/nativeInterop/cinterop/libsodium.def +++ b/multiplatform-crypto-delegated/src/nativeInterop/cinterop/libsodium.def @@ -1,6 +1,6 @@ headers = sodium.h headerFilter = sodium.h sodium/** staticLibraries = libsodium.a -libraryPaths = lib -compilerOpts = -Iinclude -linkerOpts = {{LDFLAGS}} \ No newline at end of file +libraryPaths = /usr/lib +compilerOpts = -Iinclude -I/usr/include +linkerOpts = -L/usr/lib -lsodium \ No newline at end of file