Skip to content

Commit 3082a69

Browse files
authored
Make protoc-gen-kotlin-multiplatform (formerly protobuf-plugin) an included build (#411)
1 parent ee32c27 commit 3082a69

Some content is hidden

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

57 files changed

+280
-182
lines changed

docs/pages/kotlinx-rpc/topics/platforms.topic

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@
7777
<td><list><li>apple<list><li>ios<list><li>iosArm64</li><li>iosSimulatorArm64</li><li>iosX64</li></list></li><li>macos<list><li>macosArm64</li><li>macosX64</li></list></li><li>watchos<list><li>watchosArm32</li><li>watchosArm64</li><li>watchosDeviceArm64</li><li>watchosSimulatorArm64</li><li>watchosX64</li></list></li><li>tvos<list><li>tvosArm64</li><li>tvosSimulatorArm64</li><li>tvosX64</li></list></li></list></li><li>linux<list><li>linuxArm64</li><li>linuxX64</li></list></li><li>windows<list><li>mingwX64</li></list></li></list></td>
7878
</tr>
7979

80-
<tr>
81-
<td>protobuf-plugin</td>
82-
<td>Jvm Only</td>
83-
<td>-</td>
84-
<td>-</td>
85-
<td>-</td>
86-
</tr>
87-
8880
<tr>
8981
<td>utils</td>
9082
<td>jvm</td>

gradle-conventions/src/main/kotlin/conventions-publishing.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import util.other.isPublicModule
99
import util.tasks.ValidatePublishedArtifactsTask
1010

1111
val isGradlePlugin = project.name == "gradle-plugin"
12+
val isProtocGen = project.name == "protoc-gen"
1213
val publishingExtension = project.extensions.findByType<PublishingExtension>()
1314
val globalRootDir: String by extra
1415

@@ -53,7 +54,7 @@ fun PublishingExtension.configurePublication() {
5354
// mainly for kotlinMultiplatform publication
5455
setPublicArtifactId(project)
5556

56-
if (!isGradlePlugin) {
57+
if (!isGradlePlugin && !isProtocGen) {
5758
fixModuleMetadata(project)
5859
}
5960

gradle-conventions/src/main/kotlin/util/publication.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
@file:Suppress("detekt.MaxLineLength")
@@ -17,16 +17,21 @@ import util.other.getSensitiveProperty
1717
import java.io.File
1818

1919
const val KOTLINX_RPC_PREFIX = "kotlinx-rpc"
20+
const val PROTOC_GEN = "protoc-gen"
21+
const val PROTOC_GEN_KOTLIN_MULTIPLATFORM = "protoc-gen-kotlin-multiplatform"
2022

2123
/**
2224
* Important to configure inside [KotlinTarget.mavenPublication]
2325
* AND in [PublishingExtension.configurePublication] in the conventions-publishing.gradle.kts file.
2426
*/
25-
@Suppress("KDocUnresolvedReference")
27+
@Suppress("KDocUnresolvedReference", "LoggingSimilarMessage")
2628
fun MavenPublication.setPublicArtifactId(project: Project) {
2729
val publication = this
2830

29-
if (!publication.artifactId.startsWith(KOTLINX_RPC_PREFIX)) {
31+
if (publication.artifactId == PROTOC_GEN) {
32+
publication.artifactId = PROTOC_GEN_KOTLIN_MULTIPLATFORM
33+
project.logger.info("Altered artifactId for $name publication: $artifactId")
34+
} else if (!publication.artifactId.startsWith(KOTLINX_RPC_PREFIX)) {
3035
publication.artifactId = "$KOTLINX_RPC_PREFIX-$artifactId"
3136
project.logger.info("Altered artifactId for $name publication: $artifactId")
3237
}
@@ -101,6 +106,8 @@ private fun String.updateAvailableAtModuleField(projectName: String): String {
101106
// in "available-at" object:
102107
// from: "url": "../../krpc-client-iossimulatorarm64/0.2.0/krpc-client-iossimulatorarm64-0.2.0.module",
103108
// to: "url": "../../kotlinx-rpc-krpc-client-iossimulatorarm64/0.2.0/kotlinx-rpc-krpc-client-iossimulatorarm64-0.2.0.module",
109+
//
110+
// and same idea for protoc-gen
104111
private fun String.updateAvailableAtUrlField(projectName: String, version: String): String {
105112
return replace(
106113
availableAtUrl(projectName, version, "(\\w+)", "(.+)").toRegex(),

grpc/grpc-core/api/grpc-core.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
public final class kotlinx/rpc/grpc/GrpcClient : kotlinx/rpc/RpcClient {
22
public final fun awaitTermination-VtjQ1oo (JLkotlin/coroutines/Continuation;)Ljava/lang/Object;
3+
public static synthetic fun awaitTermination-VtjQ1oo$default (Lkotlinx/rpc/grpc/GrpcClient;JLkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
34
public fun call (Lkotlinx/rpc/RpcCall;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
45
public fun callServerStreaming (Lkotlinx/rpc/RpcCall;)Lkotlinx/coroutines/flow/Flow;
56
public final fun shutdown ()V

grpc/grpc-core/api/grpc-core.klib.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ final class kotlinx.rpc.grpc/GrpcClient : kotlinx.rpc/RpcClient { // kotlinx.rpc
116116
final fun shutdown() // kotlinx.rpc.grpc/GrpcClient.shutdown|shutdown(){}[0]
117117
final fun shutdownNow() // kotlinx.rpc.grpc/GrpcClient.shutdownNow|shutdownNow(){}[0]
118118
final suspend fun <#A1: kotlin/Any?> call(kotlinx.rpc/RpcCall): #A1 // kotlinx.rpc.grpc/GrpcClient.call|call(kotlinx.rpc.RpcCall){0§<kotlin.Any?>}[0]
119-
final suspend fun awaitTermination(kotlin.time/Duration) // kotlinx.rpc.grpc/GrpcClient.awaitTermination|awaitTermination(kotlin.time.Duration){}[0]
119+
final suspend fun awaitTermination(kotlin.time/Duration = ...) // kotlinx.rpc.grpc/GrpcClient.awaitTermination|awaitTermination(kotlin.time.Duration){}[0]
120120
}
121121

122122
final class kotlinx.rpc.grpc/GrpcServer : kotlinx.rpc.grpc/Server, kotlinx.rpc/RpcServer { // kotlinx.rpc.grpc/GrpcServer|null[0]

grpc/grpc-core/build.gradle.kts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
import kotlinx.rpc.buf.tasks.BufGenerateTask
6+
import kotlinx.rpc.proto.kxrpc
7+
import org.gradle.kotlin.dsl.withType
8+
19
/*
210
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
311
*/
@@ -34,5 +42,48 @@ kotlin {
3442
implementation(libs.protobuf.kotlin)
3543
}
3644
}
45+
46+
jvmTest {
47+
dependencies {
48+
implementation(projects.grpc.grpcCore)
49+
implementation(libs.coroutines.core)
50+
implementation(libs.coroutines.test)
51+
implementation(libs.kotlin.test)
52+
53+
implementation(libs.grpc.stub)
54+
implementation(libs.grpc.netty)
55+
implementation(libs.grpc.protobuf)
56+
implementation(libs.grpc.kotlin.stub)
57+
implementation(libs.protobuf.java.util)
58+
implementation(libs.protobuf.kotlin)
59+
}
60+
}
61+
}
62+
}
63+
64+
65+
protoSourceSets {
66+
jvmTest {
67+
proto {
68+
exclude("exclude/**")
69+
}
70+
}
71+
}
72+
73+
rpc {
74+
grpc {
75+
val globalRootDir: String by extra
76+
77+
protocPlugins.kxrpc {
78+
local {
79+
javaJar("$globalRootDir/protoc-gen/build/libs/protoc-gen-$version-all.jar")
80+
}
81+
}
82+
83+
project.tasks.withType<BufGenerateTask>().configureEach {
84+
if (name.endsWith("Test")) {
85+
dependsOn(gradle.includedBuild("protoc-gen").task(":jar"))
86+
}
87+
}
3788
}
3889
}

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/GrpcClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class GrpcClient internal constructor(private val channel: ManagedChannel
3030
channel.shutdownNow()
3131
}
3232

33-
public suspend fun awaitTermination(duration: Duration) {
33+
public suspend fun awaitTermination(duration: Duration = Duration.INFINITE) {
3434
channel.awaitTermination(duration)
3535
}
3636

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/GrpcServer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ import kotlin.time.Duration
1818
* providing the ability to host gRPC services.
1919
*
2020
* @property port Specifies the port used by the server to listen for incoming connections.
21-
* @param builder exposes platform-specific Server builder.
21+
* @param configure exposes platform-specific Server builder.
2222
*/
2323
public class GrpcServer internal constructor(
2424
override val port: Int = 8080,
25-
builder: ServerBuilder<*>.() -> Unit,
25+
configure: ServerBuilder<*>.() -> Unit,
2626
) : RpcServer, Server {
2727
private var isBuilt = false
2828
private lateinit var internalServer: Server
2929

30-
private val serverBuilder: ServerBuilder<*> = ServerBuilder(port).apply(builder)
30+
private val serverBuilder: ServerBuilder<*> = ServerBuilder(port).apply(configure)
3131
private val registry: MutableHandlerRegistry by lazy {
3232
MutableHandlerRegistry().apply { serverBuilder.fallbackHandlerRegistry(this) }
3333
}

protobuf-plugin/src/test/kotlin/kotlinx/rpc/protobuf/test/GrpcServerTest.kt renamed to grpc/grpc-core/src/jvmTest/kotlin/kotlinx/rpc/grpc/core/test/GrpcServerTest.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
package kotlinx.rpc.protobuf.test
5+
package kotlinx.rpc.grpc.core.test
66

77
import kotlinx.coroutines.sync.Mutex
88
import kotlinx.coroutines.sync.withLock
@@ -22,14 +22,16 @@ abstract class GrpcServerTest {
2222
usePlaintext()
2323
}
2424

25-
val grpcServer = GrpcServer(8080) {
25+
val grpcServer = GrpcServer(8080, builder = {
2626
registerServices()
27-
}
27+
})
2828

2929
grpcServer.start()
3030
test(grpcClient)
3131
grpcServer.shutdown()
3232
grpcServer.awaitTermination()
33+
grpcClient.shutdown()
34+
grpcClient.awaitTermination()
3335
}
3436
}
3537
}

protobuf-plugin/src/test/kotlin/kotlinx/rpc/protobuf/test/StreamingTest.kt renamed to grpc/grpc-core/src/jvmTest/kotlin/kotlinx/rpc/grpc/core/test/StreamingTest.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
package kotlinx.rpc.protobuf.test
5+
package kotlinx.rpc.grpc.core.test
66

77
import StreamingTestService
88
import kotlinx.coroutines.flow.Flow
@@ -11,21 +11,22 @@ import kotlinx.coroutines.flow.flow
1111
import kotlinx.coroutines.flow.last
1212
import kotlinx.coroutines.flow.toList
1313
import kotlinx.rpc.RpcServer
14+
import kotlinx.rpc.grpc.test.invoke
1415
import kotlinx.rpc.registerService
1516
import kotlinx.rpc.withService
1617
import kotlin.test.Test
1718
import kotlin.test.assertEquals
1819

1920
class StreamingTestServiceImpl : StreamingTestService {
20-
override fun Server(message: References): Flow<References> {
21+
override fun Server(message: kotlinx.rpc.grpc.test.References): Flow<kotlinx.rpc.grpc.test.References> {
2122
return flow { emit(message); emit(message); emit(message) }
2223
}
2324

24-
override suspend fun Client(message: Flow<References>): References {
25+
override suspend fun Client(message: Flow<kotlinx.rpc.grpc.test.References>): kotlinx.rpc.grpc.test.References {
2526
return message.last()
2627
}
2728

28-
override fun Bidi(message: Flow<References>): Flow<References> {
29+
override fun Bidi(message: Flow<kotlinx.rpc.grpc.test.References>): Flow<kotlinx.rpc.grpc.test.References> {
2930
return message
3031
}
3132
}
@@ -38,8 +39,8 @@ class StreamingTest : GrpcServerTest() {
3839
@Test
3940
fun testServerStreaming() = runGrpcTest { grpcClient ->
4041
val service = grpcClient.withService<StreamingTestService>()
41-
service.Server(References {
42-
other = Other {
42+
service.Server(kotlinx.rpc.grpc.test.References {
43+
other = kotlinx.rpc.grpc.test.Other {
4344
field= 42
4445
}
4546
}).toList().run {
@@ -56,8 +57,8 @@ class StreamingTest : GrpcServerTest() {
5657
val service = grpcClient.withService<StreamingTestService>()
5758
val result = service.Client(flow {
5859
repeat(3) {
59-
emit(References {
60-
other = Other {
60+
emit(kotlinx.rpc.grpc.test.References {
61+
other = kotlinx.rpc.grpc.test.Other {
6162
field = 42 + it
6263
}
6364
})
@@ -72,8 +73,8 @@ class StreamingTest : GrpcServerTest() {
7273
val service = grpcClient.withService<StreamingTestService>()
7374
service.Bidi(flow {
7475
repeat(3) {
75-
emit(References {
76-
other = Other {
76+
emit(kotlinx.rpc.grpc.test.References {
77+
other = kotlinx.rpc.grpc.test.Other {
7778
field = 42 + it
7879
}
7980
})

0 commit comments

Comments
 (0)