Skip to content

Commit

Permalink
Fix building on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
Monkopedia committed Feb 5, 2024
1 parent 67aaa00 commit e6ab19d
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 28 deletions.
40 changes: 23 additions & 17 deletions compiler/local-plugin/src/main/kotlin/GenerateKsrpcProject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fun Project.ksrpcModule(
supportJs: Boolean = true,
supportNative: Boolean = true,
supportAndroidNative: Boolean = false,
supportIos: Boolean = supportNative,
supportLinuxArm64: Boolean = supportNative,
supportMingw: Boolean = supportNative,
includePublications: Boolean = true,
Expand Down Expand Up @@ -90,28 +91,33 @@ fun Project.ksrpcModule(
binaries {}
nativeConfig()
}
iosX64 {
binaries {}
nativeConfig()
}
iosArm64 {
binaries {}
nativeConfig()
}
iosSimulatorArm64 {
binaries {}
nativeConfig()
if (supportIos) {
iosX64 {
binaries {}
nativeConfig()
}
iosArm64 {
binaries {}
nativeConfig()
}
iosSimulatorArm64 {
binaries {}
nativeConfig()
}
}

linuxX64 {
binaries {}
nativeConfig()
}
if (supportLinuxArm64) {
linuxArm64 {
val hostOs = System.getProperty("os.name")
if (hostOs == "Linux") {
linuxX64 {
binaries {}
nativeConfig()
}
if (supportLinuxArm64) {
linuxArm64 {
binaries {}
nativeConfig()
}
}
}
if (supportAndroidNative) {
androidNativeX64 {
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jnanoid = { module = "com.aventrix.jnanoid:jnanoid", version.ref = "jnanoid" }
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j"}
ktor-client = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-curl = { module = "io.ktor:ktor-client-curl", version.ref = "ktor" }
ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
ktor-client-websockets = { module = "io.ktor:ktor-client-websockets", version.ref = "ktor" }
ktor-server = { module = "io.ktor:ktor-server-core", version.ref = "ktor" }
Expand Down
1 change: 0 additions & 1 deletion ksrpc-jni/src/nativeMain/kotlin/JNI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.monkopedia.jni.jobject
import com.monkopedia.jni.jstring
import com.monkopedia.jni.jvalue
import kotlin.native.concurrent.ThreadLocal
import kotlin.native.concurrent.Worker
import kotlinx.cinterop.CPointer
import kotlinx.cinterop.CPointerVarOf
import kotlinx.cinterop.ExperimentalForeignApi
Expand Down
13 changes: 12 additions & 1 deletion ksrpc-ktor/client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,18 @@ kotlin {
sourceSets["jsMain"].dependencies {
compileOnly(libs.ktor.client)
}
sourceSets["nativeMain"].dependencies {
if (System.getProperty("os.name") == "Linux") {
sourceSets["linuxMain"].dependencies {
implementation(libs.ktor.client.curl)
}
}
sourceSets["mingwMain"].dependencies {
implementation(libs.ktor.client.curl)
}
sourceSets["macosMain"].dependencies {
implementation(libs.ktor.client.curl)
}
sourceSets["iosMain"].dependencies {
implementation(libs.ktor.client.darwin)
}
}
1 change: 1 addition & 0 deletions ksrpc-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ plugins {
ksrpcModule(
supportJs = false,
supportLinuxArm64 = false,
supportIos = false,
supportMingw = false
)

Expand Down
23 changes: 23 additions & 0 deletions ksrpc-sockets/src/macosMain/kotlin/TermiosUtil.macosX64.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (C) 2024 Jason Monk <monkopedia@gmail.com>
*
* 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 com.monkopedia.ksrpc.sockets

import platform.posix.ICANON
import platform.posix.termios

actual fun termios.setICanon() {
c_lflag = c_lflag and ICANON.inv().toULong()
}
26 changes: 18 additions & 8 deletions ksrpc-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,28 @@ kotlin {
}
val copyLib = tasks.register("copyLib", Copy::class) {
val hostOs = System.getProperty("os.name")
val hostTarget = when {
hostOs == "Mac OS X" -> "macosX64"
hostOs == "Linux" -> "linuxX64"
hostOs.startsWith("Windows") -> "mingwX64"
val arch = System.getProperty("os.arch")
when {
hostOs == "Mac OS X" -> {
if (arch == "aarch64") {
dependsOn(tasks.findByName("linkReleaseSharedMacosArm64"))
from(buildDir.resolve("bin/macosArm64/releaseShared/libksrpc_test.dylib"))
destinationDir = buildDir.resolve("generated/lib/resources/libs/")
} else {
dependsOn(tasks.findByName("linkReleaseSharedMacosX64"))
from(buildDir.resolve("bin/macosX64/releaseShared/libksrpc_test.dylib"))
destinationDir = buildDir.resolve("generated/lib/resources/libs/")
}
}
hostOs == "Linux" -> {
dependsOn(tasks.findByName("linkDebugSharedLinuxX64"))
from(buildDir.resolve("bin/linuxX64/debugShared/libksrpc_test.so"))
destinationDir = buildDir.resolve("generated/lib/resources/libs/")
}
else -> throw GradleException(
"Host OS '$hostOs' is not supported in Kotlin/Native $project."
)
}
val extension = if (hostTarget == "linuxX64") "so" else "dylib"
dependsOn(tasks.findByName("linkDebugShared${hostTarget.capitalize()}"))
from(buildDir.resolve("bin/$hostTarget/debugShared/libksrpc_test.$extension"))
destinationDir = buildDir.resolve("generated/lib/resources/libs/")
doFirst {
}
}
Expand Down
6 changes: 5 additions & 1 deletion ksrpc-test/src/jvmTest/kotlin/JniTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ class JniTest {
}

private fun extension(): String =
if (NativeUtils::class.java.getResourceAsStream("/libs/libksrpc_test.so") != null) "so" else "dylib"
if (NativeUtils::class.java.getResourceAsStream("/libs/libksrpc_test.so") != null) {
"so"
} else {
"dylib"
}

private suspend fun CoroutineScope.createService(): JniTestInterface {
NativeUtils.loadLibraryFromJar("/libs/libksrpc_test.${extension()}")
Expand Down

0 comments on commit e6ab19d

Please sign in to comment.