square / wire

gRPC and protocol buffers for Android, Kotlin, Swift and Java.
https://square.github.io/wire/
Apache License 2.0
4.24k stars 570 forks source link

Crash on annotations.proto #2927

Closed santhanamk closed 4 months ago

santhanamk commented 5 months ago

I have this annotations.proto file:

// Copyright (c) 2015, Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

import "google/http.proto";
import "google/protobuf/descriptor.proto";
// ...

extend .google.protobuf.MethodOptions {
    HttpRule http = 72295728;
}

But when it gets processed by the Wire Gradle plugin (via Android Studio) I get this crash:

Cause: extensions are not allowed in proto3 for extend google.protobuf.MethodOptions (...app/src/main/proto/google/annotations.proto:28:1)

Is there a workaround or solution for this?

oldergod commented 5 months ago

As the error specifies, you cannot define extensions in proto3 files. Change the syntax or don't use an extension?

santhanamk commented 5 months ago

Ok thanks for your reply! Why is it that other libraries like KrotoDC or even the protoc-gen/protobuf libraries for Java/Kotlin are able to process this file without crashing?

Is the Wire Compiler more strict?

Also, what would be an alternate syntax that I could use?

oldergod commented 5 months ago

Thank you. It looks like we missed that when adding proto3 support. Extensions are allowed for defining options, even in proto3 files. I can fix that at some point but your best move right now would be to move this extension definition in a proto2 file.

oldergod commented 5 months ago

Actually @santhanamk you can get your build pass by removing the leading ..

- extend .google.protobuf.MethodOptions {
+ extend google.protobuf.MethodOptions {
santhanamk commented 5 months ago

@oldergod if I remove the .. I see this error:

Screenshot 2024-05-07 at 10 31 44 AM

I think it is due to the descriptor.proto import above.

For proto3 however, after I remove the . and do a Build in Android Studio wire is successful, and still generates all of the proto files. Do you think the HttpRule is getting ignored somehow?

If I downgrade to proto2 and move that extend into there then that does work as well.

Do you know by roughly when you could fix this bug? Thanks for your help.

oldergod commented 5 months ago

Any syntax error in the .proto file is only noise. You gotta run Wire to be sure that it works or not.

oldergod commented 5 months ago

The fix, I would not count on it before the summer. Might happen before.

santhanamk commented 5 months ago

ok thank you!