Skip to content

Commit

Permalink
Move to Kotlin 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
davidepianca98 committed Aug 15, 2020
1 parent c38bf4d commit 205497d
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 51 deletions.
21 changes: 7 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
kotlin("multiplatform") version "1.3.72"
kotlin("plugin.serialization") version "1.3.72"
kotlin("multiplatform") version "1.4.0"
kotlin("plugin.serialization") version "1.4.0"
id("maven-publish")
id("com.github.johnrengelman.shadow") version "5.2.0"
}
Expand All @@ -15,6 +15,7 @@ val serializationVersion: String by project
repositories {
mavenCentral()
jcenter()
maven(url = "https://kotlin.bintray.com/kotlinx")
}

kotlin {
Expand Down Expand Up @@ -54,15 +55,15 @@ kotlin {
sourceSets {
all {
languageSettings.apply {
useExperimentalAnnotation("kotlin.ExperimentalStdlibApi")
useExperimentalAnnotation("kotlinx.serialization.ExperimentalSerializationApi")
useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
}
}
commonMain {
dependencies {
implementation(kotlin("stdlib-common"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serializationVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf-common:$serializationVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$serializationVersion")
}
}
commonTest {
Expand All @@ -74,21 +75,17 @@ kotlin {
val jvmMain by getting {
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serializationVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$serializationVersion")
}
}
val jvmTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-junit"))
implementation("com.hivemq:hivemq-mqtt-client:1.1.3")
implementation("com.hivemq:hivemq-mqtt-client:1.2.1")
}
}
val mingwMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-mingwx64:$serializationVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf-mingwx64:$serializationVersion")
}
}
val mingwTest by getting {
Expand All @@ -97,8 +94,6 @@ kotlin {
val linuxX64Main by getting {
dependencies {
implementation(files("src/nativeInterop/openssl-linux-x64.klib"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-linuxx64:$serializationVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf-linuxx64:$serializationVersion")
}
}
val linuxX64Test by getting {
Expand All @@ -107,8 +102,6 @@ kotlin {
val linuxArm32HfpMain by getting {
dependencies {
implementation(files("src/nativeInterop/openssl-linux-arm32-hfp.klib"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-linuxarm32hfp:$serializationVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf-linuxarm32hfp:$serializationVersion")
}
}
val linuxArm32HfpTest by getting {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
kotlin.code.style=official
serializationVersion=0.20.0
serializationVersion=1.0.0-RC
3 changes: 2 additions & 1 deletion src/commonMain/kotlin/mqtt/broker/Broker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ class Broker(
matchedSubscriptions.filter { it.value.isShared() }.groupBy { it.value.shareName }.forEach {
val shareName = it.key
if (shareName != null) {
val subscriptionEntry = it.value.minBy { subscription -> subscription.value.timestampShareSent }!!
val subscriptionEntry =
it.value.minByOrNull { subscription -> subscription.value.timestampShareSent }!!
val clientId = subscriptionEntry.key
val subscription = subscriptionEntry.value
val session = sessions[clientId]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ class ClusterDiscoveryConnection(private val socket: UDPSocket, private val brok

override fun dataReceived() {
socket.read()?.let { data ->
val packet = ProtoBuf.load(DiscoveryPacket.serializer(), data.data.toByteArray())
val packet = ProtoBuf.decodeFromByteArray(DiscoveryPacket.serializer(), data.data.toByteArray())
if (packet.name != broker.cluster!!.name) {
broker.addClusterConnection(data.sourceAddress)
}
}
}

fun sendDiscovery(port: Int) {
val packet = ProtoBuf.dump(DiscoveryPacket.serializer(), DiscoveryPacket(broker.cluster!!.name)).toUByteArray()
val packet = ProtoBuf.encodeToByteArray(DiscoveryPacket.serializer(), DiscoveryPacket(broker.cluster!!.name))
.toUByteArray()
socket.send(packet, "255.255.255.255", port)
}
}
4 changes: 2 additions & 2 deletions src/commonMain/kotlin/mqtt/broker/cluster/DiscoveryPacket.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package mqtt.broker.cluster

import kotlinx.serialization.Serializable
import kotlinx.serialization.protobuf.ProtoId
import kotlinx.serialization.protobuf.ProtoNumber

@Serializable
data class DiscoveryPacket(
@ProtoId(1)
@ProtoNumber(1)
val name: String = ""
)
2 changes: 1 addition & 1 deletion src/linuxArm32HfpMain/kotlin/socket/ServerSocket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ actual open class ServerSocket actual constructor(private val broker: Broker) :
clients[discoverySocket] = clusterConnection
clusterConnection.sendDiscovery(broker.cluster.discoveryPort)
}
maxFd = listOf(mqttSocket, mqttUdpSocket, clusteringSocket, discoverySocket).max()!!
maxFd = listOf(mqttSocket, mqttUdpSocket, clusteringSocket, discoverySocket).maxOrNull()!!
}
}

Expand Down
23 changes: 0 additions & 23 deletions src/linuxArm32HfpMain/kotlin/socket/tls/openssl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,6 @@ import kotlinx.cinterop.*
import kotlinx.cinterop.internal.CCall
import kotlinx.cinterop.internal.CStruct
import platform.posix.*
import kotlin.Any
import kotlin.Deprecated
import kotlin.DeprecationLevel
import kotlin.Int
import kotlin.String
import kotlin.Suppress
import kotlin.UByte
import kotlin.UInt
import kotlin.ULong
import kotlin.UShort
import kotlin.Unit
import kotlin.UnsupportedOperationException

// NOTE THIS FILE IS AUTO-GENERATED

Expand Down Expand Up @@ -3210,10 +3198,6 @@ external fun BIO_copy_next_retry(b: CValuesRef<BIO>?): Unit
@CCall("knifunptr_openssl364_BIO_printf")
external fun BIO_printf(bio: CValuesRef<BIO>?, @CCall.CString format: String?, vararg variadicArguments: Any?): Int

@Deprecated("Unable to import this declaration", level = DeprecationLevel.ERROR)
fun BIO_vprintf(bio: CValuesRef<BIO>?, @CCall.CString format: String?, args: CValue<va_list>): Int =
throw UnsupportedOperationException()

@CCall("knifunptr_openssl366_BIO_snprintf")
external fun BIO_snprintf(
buf: CValuesRef<ByteVar>?,
Expand All @@ -3222,10 +3206,6 @@ external fun BIO_snprintf(
vararg variadicArguments: Any?
): Int

@Deprecated("Unable to import this declaration", level = DeprecationLevel.ERROR)
fun BIO_vsnprintf(buf: CValuesRef<ByteVar>?, n: size_t, @CCall.CString format: String?, args: CValue<va_list>): Int =
throw UnsupportedOperationException()

@CCall("knifunptr_openssl368_BIO_meth_new")
external fun BIO_meth_new(type: Int, @CCall.CString name: String?): CPointer<BIO_METHOD>?

Expand Down Expand Up @@ -18881,9 +18861,6 @@ external fun ERR_print_errors(bp: CValuesRef<BIO>?): Unit
@CCall("knifunptr_openssl4086_ERR_add_error_data")
external fun ERR_add_error_data(num: Int, vararg variadicArguments: Any?): Unit

@Deprecated("Unable to import this declaration", level = DeprecationLevel.ERROR)
fun ERR_add_error_vdata(num: Int, args: CValue<va_list>): Unit = throw UnsupportedOperationException()

@CCall("knifunptr_openssl4088_ERR_load_strings")
external fun ERR_load_strings(lib: Int, str: CValuesRef<ERR_STRING_DATA>?): Int

Expand Down
2 changes: 1 addition & 1 deletion src/linuxX64Main/kotlin/socket/ServerSocket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ actual open class ServerSocket actual constructor(private val broker: Broker) :
clients[discoverySocket] = clusterConnection
clusterConnection.sendDiscovery(broker.cluster.discoveryPort)
}
maxFd = listOf(mqttSocket, mqttUdpSocket, clusteringSocket, discoverySocket).max()!!
maxFd = listOf(mqttSocket, mqttUdpSocket, clusteringSocket, discoverySocket).maxOrNull()!!
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/linuxX64Main/resources/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ RUN set -x \
ENV OPENSSL_VERSION="1.1.1g"

RUN set -x \
&& wget --no-check-certificate -O /tmp/kotlin-native-linux-1.3.72.tar.gz "https://github.com/JetBrains/kotlin/releases/download/v1.3.72/kotlin-native-linux-1.3.72.tar.gz" \
&& wget --no-check-certificate -O /tmp/kotlin-native-linux-1.4.tar.gz "https://github.com/JetBrains/kotlin/releases/download/v1.4.0/kotlin-native-linux-1.4.tar.gz" \
&& cd /tmp \
&& tar -xzvf kotlin-native-linux-1.3.72.tar.gz
&& tar -xzvf kotlin-native-linux-1.4.tar.gz

RUN set -x \
&& /tmp/kotlin-native-linux-1.3.72/bin/cinterop -def openssl.def; exit 0
&& /tmp/kotlin-native-linux-1.4/bin/cinterop -def openssl.def; exit 0

RUN set -x \
### BUILD OpenSSL
Expand Down Expand Up @@ -68,16 +68,16 @@ RUN set -x \
&& cd /tmp \
&& mkdir klib_linux_x64 \
&& cd /tmp/klib_linux_x64 \
&& ../kotlin-native-linux-1.3.72/bin/cinterop -def ../openssl.def -target "linux_x64" -o openssl
&& ../kotlin-native-linux-1.4/bin/cinterop -def ../openssl.def -target "linux_x64" -o openssl

#RUN set -x \
# && cd /tmp \
# && mkdir klib_mingw_x64 \
# && cd /tmp/klib_mingw_x64 \
# && ../kotlin-native-linux-1.3.72/bin/cinterop -def ../openssl.def -target "mingw_x64" -o openssl
# && ../kotlin-native-linux-1.4/bin/cinterop -def ../openssl.def -target "mingw_x64" -o openssl

RUN set -x \
&& cd /tmp \
&& mkdir klib_linux_arm32_hfp \
&& cd /tmp/klib_linux_arm32_hfp \
&& ../kotlin-native-linux-1.3.72/bin/cinterop -def ../openssl.def -target "linux_arm32_hfp" -o openssl
&& ../kotlin-native-linux-1.4/bin/cinterop -def ../openssl.def -target "linux_arm32_hfp" -o openssl
Binary file modified src/nativeInterop/cinterop/opensslLibs/mingwX64/libcrypto.a
Binary file not shown.
Binary file modified src/nativeInterop/openssl-linux-arm32-hfp.klib
Binary file not shown.
Binary file modified src/nativeInterop/openssl-linux-x64.klib
Binary file not shown.

0 comments on commit 205497d

Please sign in to comment.