diff --git a/build.gradle.kts b/build.gradle.kts index f8d017c..2fa960f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,21 +1,9 @@ plugins { - kotlin("multiplatform") version "2.1.0" + kotlin("multiplatform") apply false + id("buildSrc") } repositories { mavenCentral() -} - - -kotlin { - jvm() - mingwX64() - sourceSets { - commonMain { - dependencies { - implementation("io.ktor:ktor-client-core:3.1.1") - implementation("io.ktor:ktor-network:3.1.1") - } - } - } + maven("https://maven.landgrafhomyak.ru/") } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..5f5a006 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +kotlin.mpp.applyDefaultHierarchyTemplate=false +kotlin.native.enableKlibsCrossCompilation=true \ No newline at end of file diff --git a/modules/build-script/build.gradle.kts b/modules/build-script/build.gradle.kts new file mode 100644 index 0000000..70160fb --- /dev/null +++ b/modules/build-script/build.gradle.kts @@ -0,0 +1,20 @@ +plugins { + `kotlin-dsl` +} + +repositories { + mavenCentral() + maven("https://maven.landgrafhomyak.ru/") +} + + +kotlin { + sourceSets { + main { + dependencies { + api("ru.landgrafhomyak.kotlin:kotlin-mpp-gradle-build-helper:v0.2k2.0.20") + compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:2.1.0") + } + } + } +} \ No newline at end of file diff --git a/modules/build-script/settings.gradle.kts b/modules/build-script/settings.gradle.kts new file mode 100644 index 0000000..235f414 --- /dev/null +++ b/modules/build-script/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "build-script" \ No newline at end of file diff --git a/modules/build-script/src/main/kotlin/ru/landgrafhomyak/bgtu/networks0/build_script/BuildSrcPlugin.kt b/modules/build-script/src/main/kotlin/ru/landgrafhomyak/bgtu/networks0/build_script/BuildSrcPlugin.kt new file mode 100644 index 0000000..1d5b3db --- /dev/null +++ b/modules/build-script/src/main/kotlin/ru/landgrafhomyak/bgtu/networks0/build_script/BuildSrcPlugin.kt @@ -0,0 +1,10 @@ +package ru.landgrafhomyak.bgtu.networks0.build_script + +import org.gradle.api.Plugin +import org.gradle.api.Project + +class BuildSrcPlugin : Plugin { + override fun apply(project: Project) { +// project.extensions.add("utility", DslExtension) + } +} \ No newline at end of file diff --git a/modules/build-script/src/main/kotlin/ru/landgrafhomyak/bgtu/networks0/build_script/Dependencies.kt b/modules/build-script/src/main/kotlin/ru/landgrafhomyak/bgtu/networks0/build_script/Dependencies.kt new file mode 100644 index 0000000..912c452 --- /dev/null +++ b/modules/build-script/src/main/kotlin/ru/landgrafhomyak/bgtu/networks0/build_script/Dependencies.kt @@ -0,0 +1,5 @@ +package ru.landgrafhomyak.bgtu.networks0.build_script + +object Dependencies { + val kotlin_atomicfu = "org.jetbrains.kotlinx:atomicfu:${Versions.kotlin_atomicfu}" +} \ No newline at end of file diff --git a/modules/build-script/src/main/kotlin/ru/landgrafhomyak/bgtu/networks0/build_script/Versions.kt b/modules/build-script/src/main/kotlin/ru/landgrafhomyak/bgtu/networks0/build_script/Versions.kt new file mode 100644 index 0000000..689a4ad --- /dev/null +++ b/modules/build-script/src/main/kotlin/ru/landgrafhomyak/bgtu/networks0/build_script/Versions.kt @@ -0,0 +1,6 @@ +package ru.landgrafhomyak.bgtu.networks0.build_script + +@Suppress( "MayBeConstant") +object Versions { + val kotlin_atomicfu = "0.27.0" +} \ No newline at end of file diff --git a/modules/build-script/src/main/kotlin/ru/landgrafhomyak/bgtu/networks0/build_script/kotlin_source_sets.kt b/modules/build-script/src/main/kotlin/ru/landgrafhomyak/bgtu/networks0/build_script/kotlin_source_sets.kt new file mode 100644 index 0000000..07ecf18 --- /dev/null +++ b/modules/build-script/src/main/kotlin/ru/landgrafhomyak/bgtu/networks0/build_script/kotlin_source_sets.kt @@ -0,0 +1,123 @@ +package ru.landgrafhomyak.bgtu.networks0.build_script + +import java.util.function.BiFunction +import kotlin.properties.ReadOnlyProperty +import kotlin.reflect.KProperty +import org.gradle.api.Action +import org.gradle.api.NamedDomainObjectContainer +import org.gradle.api.NamedDomainObjectProvider +import org.gradle.api.Transformer +import org.gradle.api.provider.Provider +import org.gradle.api.specs.Spec +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet + +@Suppress("FunctionName") +private fun NamedDomainObjectContainer._createConditional( + name: String, + vararg children: KotlinSourceSet? +): KotlinSourceSet? { + val existingChildren = children.filterNotNull() + + if (existingChildren.isEmpty()) + return null + + val ss = this.create(name) + existingChildren + .forEach { child -> child.dependsOn(ss) } + + return ss +} + +fun NamedDomainObjectContainer.setupHierarchy() { + val linuxX64Main = this.findByName("linuxX64Main") + val linuxX64Test = this.findByName("linuxX64Test") + val linuxArm64Main = this.findByName("linuxArm64Main") + val linuxArm64Test = this.findByName("linuxArm64Test") + + val linuxMain = this._createConditional("linuxMain", linuxX64Main, linuxArm64Main) + val linuxTest = this._createConditional("linuxTest", linuxX64Test, linuxArm64Test) + + val macosX64Main = this.findByName("macosX64Main") + val macosX64Test = this.findByName("macosX64Test") + val macosArm64Main = this.findByName("macosArm64Main") + val macosArm64Test = this.findByName("macosArm64Test") + + val macosMain = this._createConditional("macosMain", macosX64Main, macosArm64Main) + val macosTest = this._createConditional("macosTest", macosX64Test, macosArm64Test) + + val posixMain = this._createConditional("posixMain", linuxMain, macosMain) + val posixTest = this._createConditional("posixTest", linuxTest, macosTest) + + val mingwX64Main = this.findByName("mingwX64Main") + val mingwX64Test = this.findByName("mingwX64Test") + + val windowsMain = this._createConditional("windowsMain", mingwX64Main) + val windowsTest = this._createConditional("windowsTest", mingwX64Test) + + val nativeMain = this._createConditional("nativeMain", posixMain, windowsMain) + val nativeTest = this._createConditional("nativeTest", posixTest, windowsTest) + + nativeMain?.dependsOn(this.getByName("commonMain")) + nativeTest?.dependsOn(this.getByName("commonTest")) +} + + +val NamedDomainObjectContainer.posixMain by SourceSetDelegate +val NamedDomainObjectContainer.posixTest by SourceSetDelegate +val NamedDomainObjectContainer.windowsMain by SourceSetDelegate +val NamedDomainObjectContainer.windowsTest by SourceSetDelegate + + +private object SourceSetDelegate : ReadOnlyProperty, NamedDomainObjectProvider> { + private class BoundProvider( + private val _collection: NamedDomainObjectContainer, + private val _name: String + ) : NamedDomainObjectProvider { + override fun get(): KotlinSourceSet = this._collection.getByName(this._name) + + override fun getOrNull(): KotlinSourceSet? = this._collection.findByName(this._name) + + override fun isPresent(): Boolean = this.getOrNull() != null + + @Deprecated("Deprecated in Java") + override fun forUseAtConfigurationTime(): Provider { + TODO("Not yet implemented") + } + + override fun getName(): String = this._name + + override fun configure(action: Action) { + action.execute(this.get()) + } + + override fun zip(right: Provider, combiner: BiFunction): Provider { + TODO("Not yet implemented") + } + + override fun orElse(provider: Provider): Provider { + TODO("Not yet implemented") + } + + override fun orElse(value: KotlinSourceSet): Provider { + TODO("Not yet implemented") + } + + override fun flatMap(transformer: Transformer?, in KotlinSourceSet>): Provider { + TODO("Not yet implemented") + } + + override fun filter(spec: Spec): Provider { + TODO("Not yet implemented") + } + + override fun map(transformer: Transformer): Provider { + TODO("Not yet implemented") + } + + override fun getOrElse(defaultValue: KotlinSourceSet): KotlinSourceSet = this.getOrNull() ?: defaultValue + } + + override fun getValue(thisRef: NamedDomainObjectContainer, property: KProperty<*>): NamedDomainObjectProvider { + return BoundProvider(thisRef, property.name) + } +} \ No newline at end of file diff --git a/modules/build-script/src/main/resources/META-INF/gradle-plugins/buildSrc.properties b/modules/build-script/src/main/resources/META-INF/gradle-plugins/buildSrc.properties new file mode 100644 index 0000000..bc90ea6 --- /dev/null +++ b/modules/build-script/src/main/resources/META-INF/gradle-plugins/buildSrc.properties @@ -0,0 +1 @@ +implementation-class=ru.landgrafhomyak.bgtu.networks0.build_script.BuildSrcPlugin \ No newline at end of file diff --git a/modules/low-level/c-interop-utilities/build.gradle.kts b/modules/low-level/c-interop-utilities/build.gradle.kts index c3e6b28..c90094d 100644 --- a/modules/low-level/c-interop-utilities/build.gradle.kts +++ b/modules/low-level/c-interop-utilities/build.gradle.kts @@ -1,5 +1,7 @@ +import ru.landgrafhomyak.bgtu.networks0.build_script.setupHierarchy + plugins { - kotlin("multiplatform") version "2.1.0" + kotlin("multiplatform") } repositories { @@ -14,67 +16,6 @@ kotlin { macosX64() macosArm64() sourceSets { - val commonMain by getting { - dependencies { - } - } - - val commonTest by getting { - dependencies { - } - } - - val nativeMain by creating { - dependsOn(commonMain) - } - val nativeTest by creating { - dependsOn(commonTest) - } - - val posixMain by creating { - dependsOn(nativeMain) - } - val posixTest by creating { - dependsOn(nativeTest) - } - - val linuxMain by creating { - dependsOn(posixMain) - } - val linuxTest by creating { - dependsOn(posixTest) - } - - val linuxX64Main by getting { - dependsOn(linuxMain) - } - val linuxX64Test by getting { - dependsOn(linuxTest) - } - val linuxArm64Main by getting { - dependsOn(linuxMain) - } - val linuxArm64Test by getting { - dependsOn(linuxTest) - } - - val macosMain by creating { - dependsOn(posixMain) - } - val macosTest by creating { - dependsOn(posixTest) - } - val macosX64Main by getting { - dependsOn(macosMain) - } - val macosX64Test by getting { - dependsOn(macosTest) - } - val macosArm64Main by getting { - dependsOn(macosMain) - } - val macosArm64Test by getting { - dependsOn(macosTest) - } + setupHierarchy() } } \ No newline at end of file diff --git a/modules/low-level/multithreading/build.gradle.kts b/modules/low-level/multithreading/build.gradle.kts index ea28994..7036139 100644 --- a/modules/low-level/multithreading/build.gradle.kts +++ b/modules/low-level/multithreading/build.gradle.kts @@ -1,5 +1,7 @@ +import ru.landgrafhomyak.bgtu.networks0.build_script.setupHierarchy + plugins { - kotlin("multiplatform") version "2.1.0" + kotlin("multiplatform") } repositories { @@ -14,71 +16,12 @@ kotlin { macosX64() macosArm64() sourceSets { - val commonMain by getting { - dependencies { - } - } - - val commonTest by getting { - dependencies { - } - } - - val nativeMain by creating { - dependsOn(commonMain) + setupHierarchy() + nativeMain { dependencies { implementation(project(":modules:low-level:c-interop-utilities")) } } - val nativeTest by creating { - dependsOn(commonTest) - } - - val posixMain by creating { - dependsOn(nativeMain) - } - val posixTest by creating { - dependsOn(nativeTest) - } - - val linuxMain by creating { - dependsOn(posixMain) - } - val linuxTest by creating { - dependsOn(posixTest) - } - - val linuxX64Main by getting { - dependsOn(linuxMain) - } - val linuxX64Test by getting { - dependsOn(linuxTest) - } - val linuxArm64Main by getting { - dependsOn(linuxMain) - } - val linuxArm64Test by getting { - dependsOn(linuxTest) - } - - val macosMain by creating { - dependsOn(posixMain) - } - val macosTest by creating { - dependsOn(posixTest) - } - val macosX64Main by getting { - dependsOn(macosMain) - } - val macosX64Test by getting { - dependsOn(macosTest) - } - val macosArm64Main by getting { - dependsOn(macosMain) - } - val macosArm64Test by getting { - dependsOn(macosTest) - } } } \ No newline at end of file diff --git a/modules/low-level/sockets/build.gradle.kts b/modules/low-level/sockets/build.gradle.kts index 983a959..5638980 100644 --- a/modules/low-level/sockets/build.gradle.kts +++ b/modules/low-level/sockets/build.gradle.kts @@ -1,3 +1,6 @@ +import ru.landgrafhomyak.bgtu.networks0.build_script.Dependencies +import ru.landgrafhomyak.bgtu.networks0.build_script.setupHierarchy + plugins { kotlin("multiplatform") version "2.1.0" } @@ -14,72 +17,19 @@ kotlin { macosX64() macosArm64() sourceSets { - val commonMain by getting { + setupHierarchy() + + commonMain { dependencies { - implementation("org.jetbrains.kotlinx:atomicfu:0.27.0") + implementation(Dependencies.kotlin_atomicfu) } } - val commonTest by getting { - dependencies { - } - } - - val nativeMain by creating { - dependsOn(commonMain) + nativeMain { dependencies { implementation(project(":modules:low-level:c-interop-utilities")) implementation(project(":modules:low-level:multithreading")) } } - val nativeTest by creating { - dependsOn(commonTest) - } - - val posixMain by creating { - dependsOn(nativeMain) - } - val posixTest by creating { - dependsOn(nativeTest) - } - - val linuxMain by creating { - dependsOn(posixMain) - } - val linuxTest by creating { - dependsOn(posixTest) - } - - val linuxX64Main by getting { - dependsOn(linuxMain) - } - val linuxX64Test by getting { - dependsOn(linuxTest) - } - val linuxArm64Main by getting { - dependsOn(linuxMain) - } - val linuxArm64Test by getting { - dependsOn(linuxTest) - } - - val macosMain by creating { - dependsOn(posixMain) - } - val macosTest by creating { - dependsOn(posixTest) - } - val macosX64Main by getting { - dependsOn(macosMain) - } - val macosX64Test by getting { - dependsOn(macosTest) - } - val macosArm64Main by getting { - dependsOn(macosMain) - } - val macosArm64Test by getting { - dependsOn(macosTest) - } } } \ No newline at end of file diff --git a/modules/low-level/sockets/src/linuxMain/kotlin/ru/landgrafhomyak/bgtu/networks0/low_level/sockets/SocketBlockingEventLoop.kt b/modules/low-level/sockets/src/linuxMain/kotlin/ru/landgrafhomyak/bgtu/networks0/low_level/sockets/SocketBlockingEventLoop.kt index 4b7b2cb..3ff92dc 100644 --- a/modules/low-level/sockets/src/linuxMain/kotlin/ru/landgrafhomyak/bgtu/networks0/low_level/sockets/SocketBlockingEventLoop.kt +++ b/modules/low-level/sockets/src/linuxMain/kotlin/ru/landgrafhomyak/bgtu/networks0/low_level/sockets/SocketBlockingEventLoop.kt @@ -150,5 +150,9 @@ actual class SocketBlockingEventLoop : SocketEventLoop { override suspend fun _waitForRead() = this@SocketBlockingEventLoop._waitForRead(this._socketFd) + override fun close() { + TODO("Not yet implemented") + } + } } \ No newline at end of file diff --git a/modules/low-level/sockets/src/nativeMain/kotlin/ru/landgrafhomyak/bgtu/networks0/low_level/sockets/BlockingSocketEventLoop.native.kt b/modules/low-level/sockets/src/nativeMain/kotlin/ru/landgrafhomyak/bgtu/networks0/low_level/sockets/BlockingSocketEventLoop.native.kt deleted file mode 100644 index ffd9d29..0000000 --- a/modules/low-level/sockets/src/nativeMain/kotlin/ru/landgrafhomyak/bgtu/networks0/low_level/sockets/BlockingSocketEventLoop.native.kt +++ /dev/null @@ -1,27 +0,0 @@ -package ru.landgrafhomyak.bgtu.networks0.low_level.sockets - -actual class SocketBlockingEventLoop : ru.landgrafhomyak.bgtu.networks0.low_level.sockets.SocketEventLoop { - actual constructor() { - - TODO("Not yet implemented") - } - - override fun icmp_IPv4(addr: String): ru.landgrafhomyak.bgtu.networks0.low_level.sockets.IcmpSocket { - TODO("Not yet implemented") - } - - override fun icmp_IPv6(addr: String): ru.landgrafhomyak.bgtu.networks0.low_level.sockets.IcmpSocket { - TODO("Not yet implemented") - } - - - private fun _mainloop() { - - } - - actual companion object { - actual fun runForever(el: ru.landgrafhomyak.bgtu.networks0.low_level.sockets.SocketBlockingEventLoop) { - el._mainloop() - } - } -} \ No newline at end of file diff --git a/modules/low-level/sockets/src/nativeMain/kotlin/ru/landgrafhomyak/bgtu/networks0/low_level/sockets/IcmpSocket.kt b/modules/low-level/sockets/src/nativeMain/kotlin/ru/landgrafhomyak/bgtu/networks0/low_level/sockets/IcmpSocket.kt deleted file mode 100644 index 111a1d5..0000000 --- a/modules/low-level/sockets/src/nativeMain/kotlin/ru/landgrafhomyak/bgtu/networks0/low_level/sockets/IcmpSocket.kt +++ /dev/null @@ -1,6 +0,0 @@ -package ru.landgrafhomyak.bgtu.networks0.low_level.sockets - -interface IcmpSocket { - suspend fun send(data: UByteArray) - suspend fun recv(): UByteArray -} \ No newline at end of file diff --git a/modules/low-level/sockets/src/nativeMain/kotlin/ru/landgrafhomyak/bgtu/networks0/low_level/sockets/SocketEventLoop.kt b/modules/low-level/sockets/src/nativeMain/kotlin/ru/landgrafhomyak/bgtu/networks0/low_level/sockets/SocketEventLoop.kt deleted file mode 100644 index 32a32b2..0000000 --- a/modules/low-level/sockets/src/nativeMain/kotlin/ru/landgrafhomyak/bgtu/networks0/low_level/sockets/SocketEventLoop.kt +++ /dev/null @@ -1,7 +0,0 @@ -package ru.landgrafhomyak.bgtu.networks0.low_level.sockets - -@Suppress("FunctionName") -interface SocketEventLoop { - fun icmp_IPv4(addr: String): IcmpSocket - fun icmp_IPv6(addr: String): IcmpSocket -} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index c0352d4..56746fc 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,26 @@ +includeBuild("./modules/build-script") { + dependencySubstitution { + substitute(module("buildSrc:buildSrc:buildSrc")).using(project(":")) + } +} + + +pluginManagement { + repositories { + mavenCentral() + maven("https://maven.landgrafhomyak.ru/") + } + plugins { + kotlin("multiplatform") version "2.1.0" + id("buildSrc") + } + resolutionStrategy { + eachPlugin { + if (requested.id.id == "buildSrc") + useModule("buildSrc:buildSrc:buildSrc") + } + } +} include(":modules:low-level:c-interop-utilities") include(":modules:low-level:multithreading") include(":modules:low-level:sockets") \ No newline at end of file