Skip to content

Commit bcad454

Browse files
authored
Linux support (#11)
* add linux support * create linux curl engine simultaneous ws and http reproduce case * work around linux issue, add basic echo test on linux/windows native * update ci * fix linux ci command * fix linux test * add macos and js basic echo test * fix macos ci * update log logic, add more test cases
1 parent 08c08b6 commit bcad454

File tree

27 files changed

+563
-117
lines changed

27 files changed

+563
-117
lines changed

.github/workflows/ci.yaml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,20 @@ permissions:
1515

1616
jobs:
1717
build:
18-
runs-on: ubuntu-latest
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
include:
22+
- os: macos-latest
23+
cov: on
24+
cmd: "./gradlew :kmp-socketio:jvmTest --info"
25+
- os: macos-latest
26+
cmd: "./gradlew :kmp-socketio:macosX64Test --info && ./kmp-socketio/src/jsTest/start_server.sh && ./gradlew :kmp-socketio:jsBrowserTest --info && ./kmp-socketio/src/jsTest/stop_server.sh"
27+
- os: ubuntu-latest
28+
cmd: "./gradlew :kmp-socketio:linuxX64Test --info"
29+
- os: windows-latest
30+
cmd: "./gradlew :kmp-socketio:mingwX64Test --info"
31+
runs-on: ${{ matrix.os }}
1932
permissions:
2033
pull-requests: write
2134
contents: write
@@ -33,17 +46,19 @@ jobs:
3346
- uses: actions/setup-node@v4
3447
with:
3548
node-version: 14
49+
architecture: 'x64'
3650
- name: Setup Test Env
3751
run: |
3852
cd kmp-socketio/src/jvmTest/resources/
3953
npm install
40-
- name: Run Jvm tests
41-
run: |
42-
./gradlew :kmp-socketio:jvmTest --info
54+
- name: Run tests
55+
run: ${{ matrix.cmd }}
4356
- name: Gen coverage
57+
if: ${{ matrix.cov == 'on' }}
4458
run: |
4559
./gradlew koverXmlReport
4660
- name: Add coverage to PR
61+
if: ${{ matrix.cov == 'on' }}
4762
id: jacoco
4863
uses: madrapps/[email protected]
4964
with:
@@ -54,26 +69,28 @@ jobs:
5469
pass-emoji: ":white_check_mark:"
5570
fail-emoji: ":negative_squared_cross_mark:"
5671
- name: Overall coverage check
57-
if: ${{ steps.jacoco.outputs.coverage-overall < 80 || steps.jacoco.outputs.coverage-changed-files < 80 }}
72+
if: ${{ matrix.cov == 'on' && (steps.jacoco.outputs.coverage-overall < 80 || steps.jacoco.outputs.coverage-changed-files < 80) }}
5873
uses: actions/github-script@v7
5974
with:
6075
script: |
6176
core.setFailed("Coverage check failed! overall ${{ steps.jacoco.outputs.coverage-overall }}, diff ${{ steps.jacoco.outputs.coverage-changed-files }}.")
6277
- name: Create coverage summary json
78+
if: ${{ matrix.cov == 'on' }}
6379
uses: jsdaniell/[email protected]
6480
with:
6581
dir: kmp-socketio/build/reports/kover/
6682
name: "coverage.json"
6783
json: '{"total":{"instructions":{"pct":${{ steps.jacoco.outputs.coverage-overall }} }}}'
6884
- name: Create Coverage Badges
85+
if: ${{ matrix.cov == 'on' }}
6986
uses: jaywcjlove/coverage-badges-cli@main
7087
with:
7188
source: ${{ github.workspace }}/kmp-socketio/build/reports/kover/coverage.json
7289
output: dist/badges.svg
7390
jsonPath: total.instructions.pct
7491
- name: Deploy
7592
uses: peaceiris/actions-gh-pages@v4
76-
if: ${{ github.ref == 'refs/heads/main' }}
93+
if: ${{ matrix.cov == 'on' && github.ref == 'refs/heads/main' }}
7794
with:
7895
commit_message: ${{ github.event.head_commit.message }}
7996
github_token: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,11 @@ KMP (pure Kotlin) implementation of SocketIO client.
1010
| :----------------: | :------------------: |
1111
| `JVM` 17 | 🚀 |
1212
| `JS` (Chrome) | 🚀 |
13-
| `WasmJS` (Chrome) | 🚀 |
1413
| `Android` | 🚀 |
1514
| `iOS` | 🚀 |
1615
| `macOS` | 🚀 |
1716
| `Windows X64` | 🚀 |
18-
| `Linux X64` | 🔮 |
19-
20-
About Linux support: Ktor's curl engine doesn't support websockets now,
21-
although CIO engine supports websockets, but it doesn't support TLS.
22-
23-
Ref:
24-
25-
- [Native Sockets TLS Client/Server support for linux](https://github.com/ktorio/ktor/pull/2939)
26-
- [Possible websockets support for curl engine](https://github.com/whyoleg/ktor/tree/libcurl-ws)
17+
| `Linux X64` | 🚀 |
2718

2819
## Dependency
2920

@@ -66,6 +57,11 @@ Most of the APIs are the same as socket.io-client-java, here are some difference
6657

6758
### Logging with [kmp-xlog](https://github.com/HackWebRTC/kmp-xlog)
6859

60+
## Development
61+
62+
To check coverage details, run `./gradlew :kmp-socketio:jvmTest --info && ./gradlew koverHtmlReport`,
63+
then check `kmp-socketio/build/reports/kover/html/index.html`.
64+
6965
## Example
7066

7167
Before running examples, run `node kmp-socketio/src/jvmTest/resources/socket-server.js` to start the socket-io echo server,
@@ -96,20 +92,18 @@ Use Chrome CORS Unblock extension to workaround with CORS error.
9692
./gradlew :example:shared:jsBrowserRun
9793
```
9894

99-
### WASM JS
100-
101-
Use Chrome CORS Unblock extension to workaround with CORS error.
102-
103-
```bash
104-
./gradlew :example:shared:wasmJsBrowserRun
105-
```
106-
10795
### Windows
10896

10997
```bash
11098
.\gradlew runKmp_socketioDebugExecutableMingwX64
11199
```
112100

101+
### Linux
102+
103+
```bash
104+
./gradlew runKmp_socketioDebugExecutableLinuxX64
105+
```
106+
113107
### macOS
114108

115109
```bash
@@ -121,6 +115,8 @@ Use Chrome CORS Unblock extension to workaround with CORS error.
121115
Maven central portal credentials and signing configs are set in `~/.gradle/gradle.properties`.
122116

123117
```bash
118+
# on Linux: need manual release on website
119+
./gradlew clean publishLinuxX64PublicationToMavenCentralRepository --no-configuration-cache
124120
# on Windows: need manual release on website
125121
.\gradlew clean publishMingwX64PublicationToMavenCentralRepository --no-configuration-cache
126122
# on macOS: need manual release on website
@@ -132,7 +128,6 @@ Maven central portal credentials and signing configs are set in `~/.gradle/gradl
132128
publishIosX64PublicationToMavenCentralRepository \
133129
publishMacosArm64PublicationToMavenCentralRepository \
134130
publishMacosX64PublicationToMavenCentralRepository \
135-
publishWasmJsPublicationToMavenCentralRepository \
136131
publishJsPublicationToMavenCentralRepository \
137132
--no-configuration-cache
138133
```

buildSrc/src/main/kotlin/Constants.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
object Consts {
22
const val releaseGroup = "com.piasy"
33
const val releaseName = "kmp-socketio"
4-
const val releaseVersion = "1.1.4"
4+
const val releaseVersion = "1.2.0"
55

66
val androidNS = "$releaseGroup.${releaseName.replace('-', '.')}"
77
}

example/shared/build.gradle.kts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
21
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
32

43
plugins {
@@ -40,27 +39,8 @@ kotlin {
4039
}
4140
binaries.executable()
4241
}
43-
@OptIn(ExperimentalWasmDsl::class)
44-
wasmJs {
45-
moduleName = "example"
46-
browser {
47-
val rootDirPath = project.rootDir.path
48-
val projectDirPath = project.projectDir.path
49-
commonWebpackConfig {
50-
outputFileName = "composeApp.js"
51-
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
52-
static = (static ?: mutableListOf()).apply {
53-
// Serve sources to debug inside browser
54-
add(rootDirPath)
55-
add(projectDirPath)
56-
}
57-
}
58-
}
59-
}
60-
binaries.executable()
61-
}
6242

63-
listOf(/*linuxX64(), */mingwX64()).forEach {
43+
listOf(linuxX64(), mingwX64()).forEach {
6444
it.binaries {
6545
executable("kmp_socketio") {
6646
entryPoint = "com.piasy.kmp.socketio.example.main"
@@ -76,11 +56,6 @@ kotlin {
7656
implementation(project(":kmp-socketio"))
7757
}
7858
}
79-
wasmJsMain {
80-
dependencies {
81-
implementation(libs.kotlinx.browser)
82-
}
83-
}
8459
}
8560
}
8661

example/shared/src/wasmJsMain/kotlin/com/piasy/kmp/socketio/example/Platform.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

example/shared/src/wasmJsMain/resources/index.html

Lines changed: 0 additions & 11 deletions
This file was deleted.

gradle/libs.versions.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ compileSdk = "35"
55
minSdk = "21"
66
targetSdk = "35"
77
agp = "8.7.3"
8-
kotlin = "2.1.0"
8+
kotlin = "2.1.10"
99
mockk = "1.13.16"
10-
ktor = "3.0.3"
10+
ktor = "3.1.0"
1111
coroutine = "1.10.1"
12-
compose = "1.7.7"
12+
compose = "1.7.8"
1313

1414
[libraries]
1515
junit = "junit:junit:4.13.2"
@@ -18,9 +18,10 @@ kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotl
1818
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
1919
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutine" }
2020
json = "org.json:json:20250107"
21+
kommand = "com.kgit2:kommand:2.3.0"
22+
2123
socketioParser = "org.hildan.socketio:socketio-kotlin:2.0.0"
2224
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutine" }
23-
kotlinx-browser = "org.jetbrains.kotlinx:kotlinx-browser:0.3"
2425
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
2526
ktor-client-websockets = { module = "io.ktor:ktor-client-websockets", version.ref = "ktor" }
2627
ktor-client-logging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" }
@@ -32,14 +33,14 @@ ktor-client-curl = { module = "io.ktor:ktor-client-curl", version.ref = "ktor" }
3233
ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor" }
3334
ktor-client-java = { module = "io.ktor:ktor-client-java", version.ref = "ktor" }
3435
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
35-
kmpXlog = "com.piasy:kmp-xlog-api:1.3.5"
36+
kmpXlog = "com.piasy:kmp-xlog-api:1.4.1"
3637

3738
androidx-compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" }
3839
androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
3940
androidx-compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
4041
androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" }
4142
androidx-compose-material = { module = "androidx.compose.material:material", version.ref = "compose" }
42-
androidx-activity-compose = "androidx.activity:activity-compose:1.10.0"
43+
androidx-activity-compose = "androidx.activity:activity-compose:1.10.1"
4344

4445
[plugins]
4546
android-library = { id = "com.android.library", version.ref = "agp" }

kmp-socketio/build.gradle.kts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import com.vanniktech.maven.publish.SonatypeHost
2-
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
32

43
plugins {
54
alias(libs.plugins.kmp)
@@ -20,29 +19,21 @@ kotlin {
2019
iosX64()
2120
macosArm64()
2221
macosX64()
22+
2323
js(IR) {
2424
browser {
2525
}
2626
binaries.executable()
2727
}
28-
mingwX64 {}
29-
@OptIn(ExperimentalWasmDsl::class)
30-
wasmJs {
31-
browser {
32-
}
33-
binaries.executable()
34-
}
3528

36-
// Ktor's curl engine doesn't support websockets now,
37-
// although CIO engine supports websockets, but it doesn't support TLS.
38-
// - [Native Sockets TLS Client/Server support for linux](https://github.com/ktorio/ktor/pull/2939)
39-
// - [Possible websockets support for curl engine](https://github.com/whyoleg/ktor/tree/libcurl-ws)
40-
//linuxX64 {}
29+
mingwX64 {}
30+
linuxX64 {}
4131

4232
applyDefaultHierarchyTemplate()
4333
sourceSets {
4434
all {
4535
languageSettings.optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
36+
languageSettings.optIn("kotlinx.cinterop.ExperimentalForeignApi")
4637
}
4738

4839
commonMain {
@@ -55,6 +46,13 @@ kotlin {
5546
api(libs.kmpXlog)
5647
}
5748
}
49+
commonTest {
50+
dependencies {
51+
implementation(libs.kotlin.test)
52+
implementation(libs.kotlinx.coroutines.test)
53+
}
54+
}
55+
5856
jvmMain {
5957
dependencies {
6058
//api(libs.ktor.client.java) // java engine can't get ws response headers
@@ -77,11 +75,17 @@ kotlin {
7775
implementation(libs.json)
7876
}
7977
}
78+
8079
appleMain {
8180
dependencies {
8281
api(libs.ktor.client.darwin)
8382
}
8483
}
84+
macosTest {
85+
dependencies {
86+
implementation(libs.kommand)
87+
}
88+
}
8589
jsMain {
8690
dependencies {
8791
api(libs.ktor.client.js)
@@ -92,9 +96,14 @@ kotlin {
9296
api(libs.ktor.client.winhttp)
9397
}
9498
}
95-
wasmJsMain {
99+
linuxMain {
100+
dependencies {
101+
api(libs.ktor.client.curl)
102+
}
103+
}
104+
linuxTest {
96105
dependencies {
97-
api(libs.ktor.client.wasm)
106+
implementation(libs.kommand)
98107
}
99108
}
100109
}

0 commit comments

Comments
 (0)