Skip to content

Provide support for imported files and Well-Known types in gRPC #448

@gregboero

Description

@gregboero

Describe the bug
An error occurred (see stack trace in step 5) during Buf generation due to the use of an import statement in a .proto file.

To Reproduce
Steps to reproduce the behavior:

  1. Kotlin version: 2.2.0

  2. Gradle version: 9.0.0

  3. OS (or at least the KMP platform): Windows

  4. Minimal reproducer in code:

    • Clone the [grpc-app](https://github.com/Kotlin/kotlinx-rpc/tree/main/samples/grpc-app) sample project.
    • In the image-recognizer.proto file, add: import "google/protobuf/empty.proto";
    • Create a custom Buf configuration file (buf.yaml):
      version: v2
      deps:
        # Common Protobuf types.
        - buf.build/googleapis/googleapis
      lint:
        use:
          # Indicates that all the default rules should be used.
          # See https://buf.build/docs/lint/rules for more details.
          - STANDARD
        except:
          - PACKAGE_DIRECTORY_MATCH
          - RPC_REQUEST_RESPONSE_UNIQUE
          - RPC_REQUEST_STANDARD_NAME
          - RPC_RESPONSE_STANDARD_NAME
      breaking:
        use:
          # Indicates that breaking change detection should be done on a file level.
          # See https://buf.build/docs/breaking/rules for more details.
          - FILE
      modules:
        - path: proto
    • Update the build.gradle.kts file:
      rpc {
          grpc {
              buf {
                  configFile = file("src/main/proto/buf.yaml")
              }
          }
      }
    • Run the Gradle task bufGenerateMain.
  5. Error description:

    Execution failed for task ':bufGenerateMain'.
    > Process buf finished:
      - Buf Arguments: [...\build.buf\buf\1.55.1\d04c47a7d4c47f7fd91922b6f4fa746b8623b134\buf-1.55.1-windows-x86_64.exe, generate, --output, ...\build\protoBuild\generated\main, --config, ...\src\main\proto\buf.yaml]
      - Exit code: 1
      - Stdout: No output
      - Stderr:
          WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
          WARNING: sun.misc.Unsafe::arrayBaseOffset has been called by com.google.protobuf.UnsafeUtil$MemoryAccessor (file:/.../caches/modules-2/files-2.1/org.jetbrains.kotlinx/protoc-gen-kotlin-multiplatform/0.10.0-grpc-121/7b0ffaa90f70e4658a81a10a7de2c0da8536aaeb/protoc-gen-kotlin-multiplatform-0.10.0-grpc-121-all.jar)
          WARNING: Please consider reporting this to the maintainers of class com.google.protobuf.UnsafeUtil$MemoryAccessor
          WARNING: sun.misc.Unsafe::arrayBaseOffset will be removed in a future release
          Exception in thread "main" java.lang.IllegalStateException: Unknown dependency google/protobuf/empty.proto for image-recognizer.proto proto file, wrong topological order
            at kotlinx.rpc.protobuf.ProtoToModelInterpreter.toModel(ProtoToModelInterpreter.kt:39)
            at kotlinx.rpc.protobuf.ProtoToModelInterpreter.interpretProtocRequest(ProtoToModelInterpreter.kt:30)
            at kotlinx.rpc.protobuf.RpcProtobufPlugin.generateKotlinFiles(RpcProtobufPlugin.kt:104)
            at kotlinx.rpc.protobuf.RpcProtobufPlugin.run(RpcProtobufPlugin.kt:75)
            at kotlinx.rpc.protobuf.MainKt.main(Main.kt:13)
            at kotlinx.rpc.protobuf.MainKt.main(Main.kt)
    

Expected behavior
The files should be generated successfully.

Additional context
No error occurs when using the Buf CLI directly with only the Java buf plugin.

Metadata

Metadata

Assignees

Labels

featureNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions