Skip to content

Commit 5598b26

Browse files
authored
add native platforms (#101)
1 parent 289d188 commit 5598b26

File tree

9,788 files changed

+436
-257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

9,788 files changed

+436
-257
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,26 @@ on:
77
workflow_dispatch:
88

99
jobs:
10-
build:
11-
runs-on: ubuntu-latest
10+
test:
11+
strategy:
12+
matrix:
13+
include:
14+
- runner: ubuntu-latest
15+
target: jvm
16+
- runner: macos-latest
17+
target: macosArm64
18+
- runner: ubuntu-latest
19+
target: linuxX64
20+
- runner: windows-latest
21+
target: mingwX64
22+
runs-on: "${{ matrix.runner }}"
23+
name: "test (${{ matrix.target }})"
1224
steps:
1325
- uses: "actions/checkout@v4"
1426
with:
1527
fetch-depth: 0
1628
- uses: "./.github/actions/setup"
17-
- run: "./gradlew build"
29+
- run: "./gradlew ${{ matrix.target }}Test"
1830

1931
build-docs:
2032
runs-on: ubuntu-latest
@@ -49,7 +61,7 @@ jobs:
4961

5062
all-good:
5163
needs:
52-
- "build"
64+
- "test"
5365
- "check-format"
5466
- "build-docs"
5567
runs-on: "ubuntu-latest"

build.gradle.kts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,58 @@ kotlin {
2828

2929
jvm()
3030

31+
// native tier 1
32+
macosX64()
33+
macosArm64()
34+
iosSimulatorArm64()
35+
iosX64()
36+
iosArm64()
37+
38+
// native tier 2
39+
linuxX64()
40+
linuxArm64()
41+
watchosSimulatorArm64()
42+
watchosX64()
43+
watchosArm32()
44+
watchosArm64()
45+
tvosSimulatorArm64()
46+
tvosX64()
47+
tvosArm64()
48+
49+
// native tier 3
50+
mingwX64()
51+
watchosDeviceArm64()
52+
53+
// native tier 3 - but no suitable Ktor engine available
54+
// androidNativeArm32()
55+
// androidNativeArm64()
56+
// androidNativeX86()
57+
// androidNativeX64()
58+
3159
applyDefaultHierarchyTemplate()
3260

3361
sourceSets {
34-
jvmMain.dependencies {
62+
commonMain.dependencies {
3563
implementation(kotlin("stdlib"))
3664
implementation(libs.kotlinx.serialization.json)
3765
implementation(libs.ktor.client.content.negotiation)
3866
implementation(libs.ktor.serialization.kotlinx.json)
3967
implementation(libs.ktorfit)
4068
}
4169

42-
jvmTest.dependencies {
70+
jvmMain.dependencies { implementation(libs.ktor.client.okhttp) }
71+
appleMain.dependencies { implementation(libs.ktor.client.darwin) }
72+
linuxMain.dependencies { implementation(libs.ktor.client.curl) }
73+
mingwMain.dependencies { implementation(libs.ktor.client.winhttp) }
74+
75+
commonTest.dependencies {
4376
implementation(kotlin("test"))
44-
implementation(kotlin("reflect"))
4577
implementation(libs.kotlinx.coroutines.test)
4678
implementation(libs.kotlinx.io)
4779
implementation(libs.ktor.client.mock)
4880
}
81+
82+
jvmTest.dependencies { implementation(kotlin("reflect")) }
4983
}
5084
}
5185

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
kotlin.code.style=official
22
kotlin.incremental.wasm=true
3+
kotlin.daemon.jvmargs=-Xmx2048M
34
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
45
org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true
56
org.gradle.configuration-cache=false
7+
org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8

gradle/libs.versions.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-t
2121
kotlinx-io = { module = "org.jetbrains.kotlinx:kotlinx-io-core", version.ref = "kotlinx-io" }
2222
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
2323
ktorfit = { module = "de.jensklingenberg.ktorfit:ktorfit-lib", version.ref = "gradle-ktorfit" }
24+
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
25+
ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
26+
ktor-client-winhttp = { module = "io.ktor:ktor-client-winhttp", version.ref = "ktor" }
27+
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
28+
ktor-client-curl = { module = "io.ktor:ktor-client-curl", version.ref = "ktor" }
29+
ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor" }
2430
ktor-client-mock = { module = "io.ktor:ktor-client-mock", version.ref = "ktor" }
2531
ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
2632
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package dev.sargunv.pokekotlin.util
2+
3+
import io.ktor.client.engine.darwin.Darwin
4+
5+
internal actual fun getDefaultEngine() = Darwin.create()

src/jvmMain/kotlin/dev/sargunv/pokekotlin/client/PokeApiClient.kt renamed to src/commonMain/kotlin/dev/sargunv/pokekotlin/client/PokeApiClient.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.sargunv.pokekotlin.client
22

33
import de.jensklingenberg.ktorfit.Ktorfit.Builder
4+
import dev.sargunv.pokekotlin.util.getDefaultEngine
45
import io.ktor.client.HttpClient
56
import io.ktor.client.HttpClientConfig
67
import io.ktor.client.engine.HttpClientEngine
@@ -9,7 +10,7 @@ import io.ktor.serialization.kotlinx.json.json
910

1011
class PokeApiClient(
1112
baseUrl: String = "https://pokeapi.co/api/v2/",
12-
engine: HttpClientEngine? = null,
13+
engine: HttpClientEngine = getDefaultEngine(),
1314
configure: HttpClientConfig<*>.() -> Unit = {},
1415
) : PokeApi by getInstance(baseUrl, engine, configure) {
1516
private companion object {
@@ -20,16 +21,12 @@ class PokeApiClient(
2021

2122
private fun getInstance(
2223
baseUrl: String,
23-
engine: HttpClientEngine?,
24+
engine: HttpClientEngine,
2425
configure: HttpClientConfig<*>.() -> Unit,
2526
) =
2627
Builder()
2728
.baseUrl(baseUrl)
28-
.httpClient(
29-
client =
30-
if (engine == null) HttpClient { configureWithJson(configure) }
31-
else HttpClient(engine) { configureWithJson(configure) }
32-
)
29+
.httpClient(HttpClient(engine) { configureWithJson(configure) })
3330
.build()
3431
.createPokeApi()
3532
}

0 commit comments

Comments
 (0)