diff --git a/compiler/local-plugin/src/main/kotlin/GenerateKsrpcProject.kt b/compiler/local-plugin/src/main/kotlin/GenerateKsrpcProject.kt index 111e9bbe..832cb2a2 100644 --- a/compiler/local-plugin/src/main/kotlin/GenerateKsrpcProject.kt +++ b/compiler/local-plugin/src/main/kotlin/GenerateKsrpcProject.kt @@ -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, @@ -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 { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1b171056..b1eebca4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" } diff --git a/ksrpc-jni/src/nativeMain/kotlin/JNI.kt b/ksrpc-jni/src/nativeMain/kotlin/JNI.kt index 3bbf1f63..6b6a36b3 100644 --- a/ksrpc-jni/src/nativeMain/kotlin/JNI.kt +++ b/ksrpc-jni/src/nativeMain/kotlin/JNI.kt @@ -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 diff --git a/ksrpc-ktor/client/build.gradle.kts b/ksrpc-ktor/client/build.gradle.kts index 367de6ff..2373a6f0 100644 --- a/ksrpc-ktor/client/build.gradle.kts +++ b/ksrpc-ktor/client/build.gradle.kts @@ -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) + } } diff --git a/ksrpc-server/build.gradle.kts b/ksrpc-server/build.gradle.kts index 41636a6a..b7231cf7 100644 --- a/ksrpc-server/build.gradle.kts +++ b/ksrpc-server/build.gradle.kts @@ -22,6 +22,7 @@ plugins { ksrpcModule( supportJs = false, supportLinuxArm64 = false, + supportIos = false, supportMingw = false ) diff --git a/ksrpc-sockets/src/macosX64Main/kotlin/TermiosUtil.macosX64.kt b/ksrpc-sockets/src/iosMain/kotlin/TermiosUtil.macosX64.kt similarity index 100% rename from ksrpc-sockets/src/macosX64Main/kotlin/TermiosUtil.macosX64.kt rename to ksrpc-sockets/src/iosMain/kotlin/TermiosUtil.macosX64.kt diff --git a/ksrpc-sockets/src/macosMain/kotlin/TermiosUtil.macosX64.kt b/ksrpc-sockets/src/macosMain/kotlin/TermiosUtil.macosX64.kt new file mode 100644 index 00000000..2c115e3b --- /dev/null +++ b/ksrpc-sockets/src/macosMain/kotlin/TermiosUtil.macosX64.kt @@ -0,0 +1,23 @@ +/** + * Copyright (C) 2024 Jason Monk + * + * 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() +} diff --git a/ksrpc-test/build.gradle.kts b/ksrpc-test/build.gradle.kts index e1cda02c..dd018446 100644 --- a/ksrpc-test/build.gradle.kts +++ b/ksrpc-test/build.gradle.kts @@ -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 { } } diff --git a/ksrpc-test/src/jvmTest/kotlin/JniTest.kt b/ksrpc-test/src/jvmTest/kotlin/JniTest.kt index e0686193..ceb88ffc 100644 --- a/ksrpc-test/src/jvmTest/kotlin/JniTest.kt +++ b/ksrpc-test/src/jvmTest/kotlin/JniTest.kt @@ -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()}")