Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ internal fun grpc_status_code.toKotlin(): StatusCode = when (this) {
grpc_status_code.GRPC_STATUS_UNAVAILABLE -> StatusCode.UNAVAILABLE
grpc_status_code.GRPC_STATUS_DATA_LOSS -> StatusCode.DATA_LOSS
grpc_status_code.GRPC_STATUS_UNAUTHENTICATED -> StatusCode.UNAUTHENTICATED
grpc_status_code.GRPC_STATUS__DO_NOT_USE -> error("Invalid status code: ${this.ordinal}")
grpc_status_code.GRPC_STATUS__DO_NOT_USE -> error("Invalid status code: $this")
else -> error("Invalid status code: $this")
}

internal fun StatusCode.toRawCallAllocation(): grpc_status_code = when (this) {
Expand Down
11 changes: 11 additions & 0 deletions protobuf/protobuf-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,14 @@ tasks.withType<BufGenerateTask>().configureEach {
outputDirectory = generatedCodeDir
}
}

// TODO: What is the correct way to declare this dependency? (KRPC-223)
// (without it fails when executing "publishAllPublicationsToBuildRepository")"
val bufGenerateCommonMain = tasks.named("bufGenerateCommonMain")

tasks.withType<org.gradle.jvm.tasks.Jar>().configureEach {
// Only for sources jars
if (archiveClassifier.orNull == "sources" || name.endsWith("SourcesJar")) {
dependsOn(bufGenerateCommonMain)
}
}
18 changes: 18 additions & 0 deletions samples/grpc-kmp-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
*.iml
.kotlin
.gradle
**/build/
xcuserdata
!src/**/build/
local.properties
.idea
.DS_Store
captures
.externalNativeBuild
.cxx
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcodeproj/project.xcworkspace/
!*.xcworkspace/contents.xcworkspacedata
**/xcshareddata/WorkspaceSettings.xcsettings
45 changes: 45 additions & 0 deletions samples/grpc-kmp-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
This is a Kotlin Multiplatform project targeting iOS, Desktop (JVM), Server, demonstrating the `kotlinx.rpc` library
for gRPC.

* [/composeApp](./composeApp/src) is for code that will be shared across Compose Multiplatform applications.
- [commonMain](./composeApp/src/commonMain/kotlin) contains all the relevant gRPC client application code for all platforms.

* [/server](./server/src/main/kotlin) is for the gRPC server application.

* [/shared](./shared/src) is for the code that will be shared between all targets in the project.
It contains the proto files and the generated code used by both, the server and the client applications.

### Build and Run Desktop (JVM) Application

To build and run the development version of the desktop app, use the run configuration from the run widget
in your IDE’s toolbar or run it directly from the terminal:
- on macOS/Linux
```shell
./gradlew :composeApp:run
```
- on Windows
```shell
.\gradlew.bat :composeApp:run
```

### Build and Run Server

To build and run the server, use the run configuration from the run widget
in your IDE’s toolbar or run it directly from the terminal:
- on macOS/Linux
```shell
./gradlew :server:run
```
- on Windows
```shell
.\gradlew.bat :server:run
```

### Build and Run iOS Application

To build and run the development version of the iOS app, use the run configuration from the run widget
in your IDE’s toolbar or open the [/iosApp](./iosApp) directory in Xcode and run it from there.

---

Learn more about [Kotlin Multiplatform](https://www.jetbrains.com/help/kotlin-multiplatform-dev/get-started.html)…
10 changes: 10 additions & 0 deletions samples/grpc-kmp-app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
// this is necessary to avoid the plugins to be loaded multiple times
// in each subproject's classloader
alias(libs.plugins.composeHotReload) apply false
alias(libs.plugins.composeMultiplatform) apply false
alias(libs.plugins.composeCompiler) apply false
alias(libs.plugins.kotlinJvm) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.kotlinxRpc) apply false
}
60 changes: 60 additions & 0 deletions samples/grpc-kmp-app/composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.composeMultiplatform)
alias(libs.plugins.composeCompiler)
alias(libs.plugins.composeHotReload)
}

kotlin {
listOf(
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
iosTarget.binaries.framework {
baseName = "ComposeApp"
isStatic = true
}
}

jvm()

sourceSets {
commonMain.dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.ui)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(libs.androidx.lifecycle.viewmodelCompose)
implementation(libs.androidx.lifecycle.runtimeCompose)
implementation(libs.kotlinx.datetime)
implementation(libs.kotlinx.rpc.protobuf.core)
implementation(libs.kotlinx.rpc.grpc.core)
implementation(libs.grpc.netty)
implementation(projects.shared)
}
commonTest.dependencies {
implementation(libs.kotlin.test)
}
jvmMain.dependencies {
implementation(compose.desktop.currentOs)
implementation(libs.kotlinx.coroutinesSwing)
}
}
}


compose.desktop {
application {
mainClass = "kotlinx.rpc.sample.MainKt"

nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "kotlinx.rpc.sample"
packageVersion = "1.0.0"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="450dp"
android:height="450dp"
android:viewportWidth="64"
android:viewportHeight="64">
<path
android:pathData="M56.25,18V46L32,60 7.75,46V18L32,4Z"
android:fillColor="#6075f2"/>
<path
android:pathData="m41.5,26.5v11L32,43V60L56.25,46V18Z"
android:fillColor="#6b57ff"/>
<path
android:pathData="m32,43 l-9.5,-5.5v-11L7.75,18V46L32,60Z">
<aapt:attr name="android:fillColor">
<gradient
android:centerX="23.131"
android:centerY="18.441"
android:gradientRadius="42.132"
android:type="radial">
<item android:offset="0" android:color="#FF5383EC"/>
<item android:offset="0.867" android:color="#FF7F52FF"/>
</gradient>
</aapt:attr>
</path>
<path
android:pathData="M22.5,26.5 L32,21 41.5,26.5 56.25,18 32,4 7.75,18Z">
<aapt:attr name="android:fillColor">
<gradient
android:startX="44.172"
android:startY="4.377"
android:endX="17.973"
android:endY="34.035"
android:type="linear">
<item android:offset="0" android:color="#FF33C3FF"/>
<item android:offset="0.878" android:color="#FF5383EC"/>
</gradient>
</aapt:attr>
</path>
<path
android:pathData="m32,21 l9.526,5.5v11L32,43 22.474,37.5v-11z"
android:fillColor="#000000"/>
</vector>
Loading
Loading