Skip to content

Commit 160c975

Browse files
committed
Added support for Well-Known Types
1 parent 2130297 commit 160c975

File tree

38 files changed

+3910
-75
lines changed

38 files changed

+3910
-75
lines changed

gradle-plugin/src/main/kotlin/kotlinx/rpc/buf/tasks/BufGenerateTask.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public abstract class BufGenerateTask : BufExecTask() {
5656
/**
5757
* Whether to include Well-Known Types.
5858
*
59+
* Automatically sets [includeImports] to `true`.
60+
*
5961
* @see <a href="https://buf.build/docs/reference/cli/buf/generate/#include-wkt">buf generate --include-wkt</a>
6062
* @see [BufGenerateExtension.includeWkt]
6163
*/
@@ -91,7 +93,7 @@ public abstract class BufGenerateTask : BufExecTask() {
9193
buildList {
9294
add("--output"); add(outputDirectory.get().absolutePath)
9395

94-
if (includeImports.get()) {
96+
if (includeImports.get() || includeWkt.get()) {
9597
add("--include-imports")
9698
}
9799

gradle-plugin/src/main/kotlin/kotlinx/rpc/internal/configureLocalProtocGenDevelopmentDependency.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import org.gradle.kotlin.dsl.provideDelegate
1414
import org.gradle.kotlin.dsl.withType
1515

1616
@InternalRpcApi
17-
public fun Project.configureLocalProtocGenDevelopmentDependency() {
17+
public fun Project.configureLocalProtocGenDevelopmentDependency(
18+
sourceSetSuffix: String = "Test",
19+
) {
1820
val globalRootDir: String by extra
1921

2022
rpcExtension().protoc.plugins {
@@ -32,7 +34,7 @@ public fun Project.configureLocalProtocGenDevelopmentDependency() {
3234
}
3335

3436
tasks.withType<BufGenerateTask>().configureEach {
35-
if (name.endsWith("Test")) {
37+
if (name.endsWith(sourceSetSuffix)) {
3638
val includedBuild = gradle.includedBuild("protoc-gen")
3739
dependsOn(includedBuild.task(":grpc:jar"))
3840
dependsOn(includedBuild.task(":protobuf:jar"))

protobuf/protobuf-core/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ kotlin {
1919
dependencies {
2020
api(projects.utils)
2121
api(projects.protobuf.protobufInputStream)
22+
api(projects.protobuf.protobufWellKnownTypes)
2223
api(libs.kotlinx.io.core)
2324
}
2425
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
@file:OptIn(InternalRpcApi::class)
6+
7+
import kotlinx.rpc.buf.tasks.BufGenerateTask
8+
import kotlinx.rpc.internal.InternalRpcApi
9+
import kotlinx.rpc.internal.configureLocalProtocGenDevelopmentDependency
10+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
11+
12+
plugins {
13+
alias(libs.plugins.conventions.kmp)
14+
alias(libs.plugins.kotlinx.rpc)
15+
}
16+
17+
configureLocalProtocGenDevelopmentDependency(sourceSetSuffix = "Main")
18+
19+
val generatedCodeDir = layout.projectDirectory
20+
.dir("src")
21+
.dir("commonMain")
22+
.dir("generated-code")
23+
.asFile
24+
25+
tasks.withType<BufGenerateTask>().configureEach {
26+
if (name.contains("Main")) {
27+
includeWkt = true
28+
outputDirectory = generatedCodeDir
29+
}
30+
}
31+
32+
kotlin {
33+
// for timestamp
34+
compilerOptions {
35+
apiVersion = KotlinVersion.KOTLIN_2_1
36+
}
37+
38+
sourceSets {
39+
commonMain {
40+
dependencies {
41+
api(projects.protobuf.protobufCore)
42+
api(projects.grpc.grpcCodec)
43+
44+
api(libs.kotlinx.io.core)
45+
}
46+
}
47+
}
48+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
kotlinx.rpc.exclude.wasmWasi=true
5+
kotlinx.rpc.exclude.js=true
6+
kotlinx.rpc.exclude.wasmJs=true
7+
kotlinx.rpc.exclude.iosArm64=true
8+
kotlinx.rpc.exclude.iosX64=true
9+
kotlinx.rpc.exclude.iosSimulatorArm64=true
10+
kotlinx.rpc.exclude.linuxArm64=true
11+
kotlinx.rpc.exclude.linuxX64=true
12+
kotlinx.rpc.exclude.macosX64=true
13+
kotlinx.rpc.exclude.mingwX64=true
14+
kotlinx.rpc.exclude.tvosArm64=true
15+
kotlinx.rpc.exclude.tvosSimulatorArm64=true
16+
kotlinx.rpc.exclude.tvosX64=true
17+
kotlinx.rpc.exclude.watchosArm32=true
18+
kotlinx.rpc.exclude.watchosArm64=true
19+
kotlinx.rpc.exclude.watchosDeviceArm64=true
20+
kotlinx.rpc.exclude.watchosSimulatorArm64=true
21+
kotlinx.rpc.exclude.watchosX64=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@file:OptIn(ExperimentalRpcApi::class, InternalRpcApi::class)
2+
package com.google.protobuf.kotlin
3+
4+
import kotlinx.rpc.internal.utils.*
5+
6+
@kotlinx.rpc.grpc.codec.WithCodec(com.google.protobuf.kotlin.AnyInternal.CODEC::class)
7+
public interface Any {
8+
public val typeUrl: String
9+
public val value: ByteArray
10+
11+
public companion object
12+
}
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@file:OptIn(ExperimentalRpcApi::class, InternalRpcApi::class)
2+
package com.google.protobuf.kotlin
3+
4+
import kotlinx.rpc.internal.utils.*
5+
6+
@kotlinx.rpc.grpc.codec.WithCodec(com.google.protobuf.kotlin.ApiInternal.CODEC::class)
7+
public interface Api {
8+
public val name: String
9+
public val methods: List<com.google.protobuf.kotlin.Method>
10+
public val options: List<com.google.protobuf.kotlin.Option>
11+
public val version: String
12+
public val sourceContext: com.google.protobuf.kotlin.SourceContext
13+
public val mixins: List<com.google.protobuf.kotlin.Mixin>
14+
public val syntax: com.google.protobuf.kotlin.Syntax
15+
16+
public companion object
17+
}
18+
19+
@kotlinx.rpc.grpc.codec.WithCodec(com.google.protobuf.kotlin.MethodInternal.CODEC::class)
20+
public interface Method {
21+
public val name: String
22+
public val requestTypeUrl: String
23+
public val requestStreaming: Boolean
24+
public val responseTypeUrl: String
25+
public val responseStreaming: Boolean
26+
public val options: List<com.google.protobuf.kotlin.Option>
27+
public val syntax: com.google.protobuf.kotlin.Syntax
28+
29+
public companion object
30+
}
31+
32+
@kotlinx.rpc.grpc.codec.WithCodec(com.google.protobuf.kotlin.MixinInternal.CODEC::class)
33+
public interface Mixin {
34+
public val name: String
35+
public val root: String
36+
37+
public companion object
38+
}
39+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@file:OptIn(ExperimentalRpcApi::class, InternalRpcApi::class)
2+
package com.google.protobuf.kotlin
3+
4+
import kotlinx.rpc.internal.utils.*
5+
6+
@kotlinx.rpc.grpc.codec.WithCodec(com.google.protobuf.kotlin.DurationInternal.CODEC::class)
7+
public interface Duration {
8+
public val seconds: Long
9+
public val nanos: Int
10+
11+
public companion object
12+
}
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@file:OptIn(ExperimentalRpcApi::class, InternalRpcApi::class)
2+
package com.google.protobuf.kotlin
3+
4+
import kotlinx.rpc.internal.utils.*
5+
6+
@kotlinx.rpc.grpc.codec.WithCodec(com.google.protobuf.kotlin.EmptyInternal.CODEC::class)
7+
public interface Empty {
8+
public companion object
9+
}
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@file:OptIn(ExperimentalRpcApi::class, InternalRpcApi::class)
2+
package com.google.protobuf.kotlin
3+
4+
import kotlinx.rpc.internal.utils.*
5+
6+
@kotlinx.rpc.grpc.codec.WithCodec(com.google.protobuf.kotlin.FieldMaskInternal.CODEC::class)
7+
public interface FieldMask {
8+
public val paths: List<kotlin.String>
9+
10+
public companion object
11+
}
12+

0 commit comments

Comments
 (0)