Skip to content

Commit 00ab378

Browse files
committed
Make protoc-gen-kotlinx (formerly protobuf-plugin) an included build
1 parent ee32c27 commit 00ab378

Some content is hidden

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

54 files changed

+269
-172
lines changed

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

Lines changed: 2 additions & 2 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")
@@ -26,7 +26,7 @@ const val KOTLINX_RPC_PREFIX = "kotlinx-rpc"
2626
fun MavenPublication.setPublicArtifactId(project: Project) {
2727
val publication = this
2828

29-
if (!publication.artifactId.startsWith(KOTLINX_RPC_PREFIX)) {
29+
if (!publication.artifactId.startsWith(KOTLINX_RPC_PREFIX) && !publication.artifactId.startsWith("protoc-gen-")) {
3030
publication.artifactId = "$KOTLINX_RPC_PREFIX-$artifactId"
3131
project.logger.info("Altered artifactId for $name publication: $artifactId")
3232
}

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-kotlinx/build/libs/protoc-gen-kotlinx-$version-all.jar")
80+
}
81+
}
82+
83+
project.tasks.withType<BufGenerateTask>().configureEach {
84+
if (name.endsWith("Test")) {
85+
dependsOn(gradle.includedBuild("protoc-gen-kotlinx").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
})

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
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.rpc.RpcServer
8+
import kotlinx.rpc.grpc.test.AllPrimitives
9+
import kotlinx.rpc.grpc.test.invoke
10+
import kotlinx.rpc.grpc.test.PrimitiveService
811
import kotlinx.rpc.registerService
912
import kotlinx.rpc.withService
1013
import kotlin.test.Test

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

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
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 ReferenceTestService
88
import References
9-
import invoke
109
import Other
10+
import invoke
1111
import kotlinx.rpc.RpcServer
12+
import kotlinx.rpc.grpc.test.AllPrimitives
13+
import kotlinx.rpc.grpc.test.Nested
14+
import kotlinx.rpc.grpc.test.OneOf
15+
import kotlinx.rpc.grpc.test.OptionalTypes
16+
import kotlinx.rpc.grpc.test.Repeated
17+
import kotlinx.rpc.grpc.test.TestMap
18+
import kotlinx.rpc.grpc.test.UsingEnum
19+
import kotlinx.rpc.grpc.test.invoke
1220
import kotlinx.rpc.registerService
1321
import kotlinx.rpc.withService
1422
import kotlin.test.Test
@@ -17,9 +25,9 @@ import kotlin.test.assertEquals
1725
import kotlin.test.assertNotNull
1826

1927
class ReferenceTestServiceImpl : ReferenceTestService {
20-
override suspend fun Get(message: References): kotlinx.rpc.protobuf.test.References {
21-
return kotlinx.rpc.protobuf.test.References {
22-
other = kotlinx.rpc.protobuf.test.Other {
28+
override suspend fun Get(message: References): kotlinx.rpc.grpc.test.References {
29+
return kotlinx.rpc.grpc.test.References {
30+
other = kotlinx.rpc.grpc.test.Other {
2331
field = message.other.arg.toInt()
2432
}
2533

@@ -60,11 +68,13 @@ class TestReferenceService : GrpcServerTest() {
6068
@Test
6169
fun testReferenceService() = runGrpcTest { grpcClient ->
6270
val service = grpcClient.withService<ReferenceTestService>()
63-
val result = service.Get(References {
71+
val arg = References {
6472
other = Other {
6573
arg = "42"
6674
}
67-
})
75+
}
76+
77+
val result = service.Get(arg)
6878

6979
assertEquals("42", result.primitive)
7080
assertEquals(42, result.other.field)
@@ -74,10 +84,10 @@ class TestReferenceService : GrpcServerTest() {
7484
fun testEnum() = runGrpcTest { grpcClient ->
7585
val service = grpcClient.withService<ReferenceTestService>()
7686
val result = service.Enum(UsingEnum {
77-
enum = Enum.ONE
87+
enum = kotlinx.rpc.grpc.test.Enum.ONE
7888
})
7989

80-
assertEquals(Enum.ONE, result.enum)
90+
assertEquals(kotlinx.rpc.grpc.test.Enum.ONE, result.enum)
8191
}
8292

8393
@Test
@@ -86,7 +96,7 @@ class TestReferenceService : GrpcServerTest() {
8696
val resultNotNull = service.Optional(OptionalTypes {
8797
name = "test"
8898
age = 42
89-
reference = kotlinx.rpc.protobuf.test.Other {
99+
reference = kotlinx.rpc.grpc.test.Other {
90100
field = 42
91101
}
92102
})
@@ -111,8 +121,8 @@ class TestReferenceService : GrpcServerTest() {
111121
val service = grpcClient.withService<ReferenceTestService>()
112122
val result = service.Repeated(Repeated {
113123
listString = listOf("test", "hello")
114-
listReference = listOf(kotlinx.rpc.protobuf.test.References {
115-
other = kotlinx.rpc.protobuf.test.Other {
124+
listReference = listOf(kotlinx.rpc.grpc.test.References {
125+
other = kotlinx.rpc.grpc.test.Other {
116126
field = 42
117127
}
118128
})
@@ -212,8 +222,8 @@ class TestReferenceService : GrpcServerTest() {
212222
val service = grpcClient.withService<ReferenceTestService>()
213223
val result = service.Map(TestMap {
214224
primitives = mapOf("1" to 2, "2" to 1)
215-
references = mapOf("ref" to kotlinx.rpc.protobuf.test.References {
216-
other = kotlinx.rpc.protobuf.test.Other {
225+
references = mapOf("ref" to kotlinx.rpc.grpc.test.References {
226+
other = kotlinx.rpc.grpc.test.Other {
217227
field = 42
218228
}
219229
})
@@ -228,7 +238,7 @@ class TestReferenceService : GrpcServerTest() {
228238
val service = grpcClient.withService<ReferenceTestService>()
229239
val result1 = service.OneOf(OneOf {
230240
primitives = OneOf.Primitives.StringValue("42")
231-
references = OneOf.References.Other(kotlinx.rpc.protobuf.test.Other {
241+
references = OneOf.References.Other(kotlinx.rpc.grpc.test.Other {
232242
field = 42
233243
})
234244
mixed = OneOf.Mixed.Int64(42L)
@@ -242,8 +252,8 @@ class TestReferenceService : GrpcServerTest() {
242252

243253
val result2 = service.OneOf(OneOf {
244254
primitives = OneOf.Primitives.Bool(true)
245-
references = OneOf.References.InnerReferences(kotlinx.rpc.protobuf.test.References {
246-
other = kotlinx.rpc.protobuf.test.Other {
255+
references = OneOf.References.InnerReferences(kotlinx.rpc.grpc.test.References {
256+
other = kotlinx.rpc.grpc.test.Other {
247257
field = 42
248258
}
249259
})

0 commit comments

Comments
 (0)