Skip to content

Commit

Permalink
feat: improved core binary framework export
Browse files Browse the repository at this point in the history
  • Loading branch information
programadorthi committed Feb 9, 2024
1 parent 00e8279 commit f2f4b70
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 30 deletions.
29 changes: 29 additions & 0 deletions buildSrc/src/main/kotlin/NativeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import org.gradle.api.*
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework

fun Project.fastOr(block: () -> List<String>): List<String> {
return block()
Expand Down Expand Up @@ -78,3 +79,31 @@ fun Project.windowsTargets(): List<String> = fastOr {
).map { it.name }
}
}

fun Project.darwinTargetsFramework(
action: Framework.() -> Unit = {}
) {
val projectName = name
val specialCharacters = """\W""".toRegex()

with(kotlin) {
listOf(
macosX64(),
macosArm64(),
iosX64(),
iosArm64(),
iosSimulatorArm64(),
).forEach { iosTarget ->
val moduleName = projectName
.lowercase()
.split(specialCharacters)
.joinToString(separator = "") { splitName ->
splitName.replaceFirstChar { it.uppercase() }
}
iosTarget.binaries.framework {
baseName = "${moduleName}Shared"
action()
}
}
}
}
23 changes: 0 additions & 23 deletions buildSrc/src/main/kotlin/TargetsConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ val Project.hasJvm: Boolean get() = hasCommon || hasJvmAndNix || files.any { it.
val Project.hasNative: Boolean get() = hasCommon || hasNix || hasPosix || hasDarwin || hasDesktop || hasWindows

fun Project.configureTargets() {
val projectName = name
val specialCharacters = """\W""".toRegex()

configureCommon()
if (hasJvm) configureJvm()

Expand All @@ -40,26 +37,6 @@ fun Project.configureTargets() {
configureJs()
}

if (hasDarwin) {
listOf(
macosX64(),
macosArm64(),
iosX64(),
iosArm64(),
iosSimulatorArm64(),
).forEach { iosTarget ->
val moduleName = projectName
.lowercase()
.split(specialCharacters)
.joinToString(separator = "") { splitName ->
splitName.replaceFirstChar { it.uppercase() }
}
iosTarget.binaries.framework {
baseName = "${moduleName}Shared"
}
}
}

if (hasPosix || hasDarwin || hasWindows) extra.set("hasNative", true)

sourceSets {
Expand Down
4 changes: 4 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ plugins {

applyBasicSetup()

darwinTargetsFramework {
export(libs.ktor.utils)
}

kotlin {
sourceSets {
commonMain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

@file:OptIn(ExperimentalObjCRefinement::class)

package dev.programadorthi.routing.core

import dev.programadorthi.routing.core.application.ApplicationCall
import io.ktor.util.pipeline.PipelineInterceptor
import io.ktor.utils.io.KtorDsl
import kotlin.experimental.ExperimentalObjCRefinement
import kotlin.native.HiddenFromObjC

/**
* Builds a route to match the specified [path].
Expand Down Expand Up @@ -53,13 +57,15 @@ public fun Route.method(
}

@KtorDsl
@HiddenFromObjC
public fun Route.handle(
path: String,
name: String? = null,
body: PipelineInterceptor<Unit, ApplicationCall>,
): Route = route(path, name) { handle(body) }

@KtorDsl
@HiddenFromObjC
public fun Route.handle(
path: String,
method: RouteMethod,
Expand Down
5 changes: 0 additions & 5 deletions core/darwin/src/dev/programadorthi/routing/core/Attributes.kt

This file was deleted.

1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", ve
ktor-events = { module = "io.ktor:ktor-events", version.ref = "ktor" }
ktor-http = { module = "io.ktor:ktor-http", version.ref = "ktor" }
ktor-resources = { module = "io.ktor:ktor-resources", version.ref = "ktor" }
ktor-utils = { module = "io.ktor:ktor-utils", version.ref = "ktor" }
serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "serialization" }
serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization" }
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ import dev.programadorthi.routing.core.Route
import dev.programadorthi.routing.core.Routing
import dev.programadorthi.routing.core.application
import dev.programadorthi.routing.core.routing
import io.ktor.util.logging.KtorSimpleLogger
import io.ktor.util.logging.Logger
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext

public val LocalVoyagerRouting: ProvidableCompositionLocal<Routing> =
staticCompositionLocalOf {
Expand Down

0 comments on commit f2f4b70

Please sign in to comment.