Skip to content

Commit

Permalink
Enabling linuxArm64 builds
Browse files Browse the repository at this point in the history
  • Loading branch information
bcmedeiros committed May 12, 2023
1 parent 6ec3c74 commit 2e0895e
Show file tree
Hide file tree
Showing 17 changed files with 137 additions and 14 deletions.
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/IdeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.jetbrains.kotlin.konan.target.*

fun KotlinMultiplatformExtension.ideaTarget(): KotlinNativeTarget = when (HostManager.host) {
is KonanTarget.LINUX_X64 -> linuxX64()
is KonanTarget.LINUX_ARM64 -> linuxArm64()
is KonanTarget.MACOS_X64 -> macosX64()
is KonanTarget.MACOS_ARM64 -> macosArm64()
is KonanTarget.MINGW_X64 -> mingwX64()
Expand Down
12 changes: 11 additions & 1 deletion buildSrc/src/main/kotlin/NativeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ fun Project.posixTargets(): List<String> = fastOr {
}

fun Project.nixTargets(): List<String> = fastOr {
darwinTargets() + kotlin.linuxX64().name
darwinTargets() + linuxTargets()
}

fun Project.linuxTargets(): List<String> = fastOr {
with(kotlin) {
listOf (
linuxX64(),
linuxArm64(),
)
}.map { it.name }
}

fun Project.darwinTargets(): List<String> = fastOr {
Expand Down Expand Up @@ -71,6 +80,7 @@ fun Project.desktopTargets(): List<String> = fastOr {
macosX64(),
macosArm64(),
linuxX64(),
linuxArm64(),
mingwX64()
).map { it.name }
}
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Publication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fun isAvailableForPublication(publication: Publication): Boolean {
"kotlinMultiplatform"
)
result = result || name in jvmAndCommon
result = result || (HOST_NAME == "linux" && name == "linuxX64")
result = result || (HOST_NAME == "linux" && (name == "linuxX64" || name == "linuxArm64"))
result = result || (HOST_NAME == "windows" && name == "mingwX64")
val macPublications = setOf(
"iosX64",
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/TargetsConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ fun Project.configureTargets() {

if (hasNative) {
tasks.findByName("linkDebugTestLinuxX64")?.onlyIf { HOST_NAME == "linux" }
tasks.findByName("linkDebugTestLinuxArm64")?.onlyIf { HOST_NAME == "linux" }
tasks.findByName("linkDebugTestMingwX64")?.onlyIf { HOST_NAME == "windows" }
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ kotlin.native.binary.memoryModel=experimental
#kotlinx.atomicfu.enableJsIrTransformation=true

kotlin_version=1.8.10
coroutines_version=1.6.4
atomicfu_version=0.20.0
coroutines_version=1.7.0-RC
atomicfu_version=0.20.2
slf4j_version=1.7.36
junit_version=4.13.2
logback_version=1.2.11
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[versions]
kotlin-version = "1.8.10"
kotlinx-html-version = "0.8.1"
coroutines-version = "1.6.4"
atomicfu-version = "0.18.5"
kotlinx-html-version = "0.8.1-SNAPSHOT"
coroutines-version = "1.7.0-RC"
atomicfu-version = "0.20.2"
serialization-version = "1.5.0"
validator-version = "0.8.0"
ktlint-version = "3.10.0"
Expand Down
2 changes: 1 addition & 1 deletion ktor-client/ktor-client-curl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ kotlin {
includeDirs.headerFilterOnly(paths)
}

createCInterop("libcurl", listOf("macosArm64")) {
createCInterop("libcurl", listOf("macosArm64", "linuxArm64")) {
defFile = File(projectDir, "desktop/interop/libcurl_arm64.def")
includeDirs.headerFilterOnly(paths)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class DatagramSendChannel(
private val closedCause = atomic<Throwable?>(null)
private val lock = Mutex()

@ExperimentalCoroutinesApi
@DelicateCoroutinesApi
override val isClosedForSend: Boolean
get() = socket.isClosed

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package io.ktor.network.selector

import kotlinx.cinterop.*
import platform.linux.*
import platform.posix.*

internal actual fun pselectBridge(
descriptor: Int,
readSet: CPointer<fd_set>,
writeSet: CPointer<fd_set>,
errorSet: CPointer<fd_set>
): Int = pselect(descriptor, readSet, writeSet, errorSet, null, null)

internal actual fun inetNtopBridge(
type: Int,
address: CPointer<*>,
addressOf: CPointer<*>,
size: Int
) {
@Suppress("UNCHECKED_CAST")
inet_ntop(type, address, addressOf as CPointer<ByteVarOf<Byte>>, size.convert())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package io.ktor.network.util

import kotlinx.cinterop.*
import platform.linux.*
import platform.posix.*

internal actual fun ktor_inet_ntop(
family: Int,
src: CValuesRef<*>?,
dst: CValuesRef<ByteVar>?,
size: socklen_t
): CPointer<ByteVar>? = inet_ntop(family, src, dst, size)

internal actual fun <T> unpack_sockaddr_un(
sockaddr: sockaddr,
block: (family: UShort, path: String) -> T
): T {
val address = sockaddr.ptr.reinterpret<sockaddr_un>().pointed
return block(address.sun_family, address.sun_path.toKString())
}

internal actual fun pack_sockaddr_un(
family: UShort,
path: String,
block: (address: CPointer<sockaddr>, size: socklen_t) -> Unit
) {
cValue<sockaddr_un> {
strcpy(sun_path, path)
sun_family = family

block(ptr.reinterpret(), sizeOf<sockaddr_un>().convert())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package io.ktor.network.sockets.tests

internal actual fun Any.supportsUnixDomainSockets(): Boolean = true
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class DatagramSendChannel(
private val closedCause = atomic<Throwable?>(null)
private val lock = Mutex()

@ExperimentalCoroutinesApi
@DelicateCoroutinesApi
override val isClosedForSend: Boolean
get() = socket.isClosed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal class RequestBodyHandler(
}
}

@OptIn(ExperimentalCoroutinesApi::class)
@OptIn(DelicateCoroutinesApi::class)
fun upgrade(): ByteReadChannel {
val result = queue.trySend(Upgrade)
if (result.isSuccess) return newChannel()
Expand All @@ -93,7 +93,7 @@ internal class RequestBodyHandler(
return result
}

@OptIn(ExperimentalCoroutinesApi::class)
@OptIn(DelicateCoroutinesApi::class)
private fun tryOfferChannelOrToken(token: Any) {
val result = queue.trySend(token)
if (result.isSuccess) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ internal class DefaultWebSocketSessionImpl(
raw.cancel()
}

@OptIn(InternalAPI::class)
@OptIn(InternalAPI::class, DelicateCoroutinesApi::class)
private fun runIncomingProcessor(ponger: SendChannel<Frame.Ping>): Job = launch(
IncomingProcessorCoroutineName + Dispatchers.Unconfined
) {
Expand Down
20 changes: 20 additions & 0 deletions ktor-test-dispatcher/linuxArm64/src/TestLinuxArm64.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.ktor.test.dispatcher

import kotlinx.coroutines.*
import platform.posix.*
import kotlin.coroutines.*

/**
* Test runner for native suspend tests.
*/
public actual fun testSuspend(
context: CoroutineContext,
timeoutMillis: Long,
block: suspend CoroutineScope.() -> Unit
) {
executeInWorker(timeoutMillis) {
runBlocking {
block()
}
}
}
21 changes: 21 additions & 0 deletions ktor-utils/linuxArm64/src/io/ktor/util/ThreadInfoLinux.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package io.ktor.util

import kotlinx.cinterop.*
import platform.linux.*
import platform.posix.*
import threadUtils.*

internal actual fun collectStack(thread: pthread_t): List<String> {
val size = collect_stack(thread)
if (size < 0) throw IllegalArgumentException("Thread is stopped")
val symbols = backtrace_symbols(callstack, size)!!
return List(stack_size) { symbols[it]!!.toKString() }
}

internal actual fun setSignalHandler() {
set_signal_handler()
}
2 changes: 1 addition & 1 deletion ktor-utils/posix/src/io/ktor/util/ThreadInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public object ThreadInfo {
}

public fun registerCurrentThread() {
val thread = pthread_self()!!
val thread = pthread_self()
threads[Worker.current] = thread
}

Expand Down

0 comments on commit 2e0895e

Please sign in to comment.