Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional fields not supported in proto3 syntax #625

Closed
jesseduffield opened this issue May 31, 2022 · 6 comments · Fixed by #626
Closed

Optional fields not supported in proto3 syntax #625

jesseduffield opened this issue May 31, 2022 · 6 comments · Fixed by #626

Comments

@jesseduffield
Copy link
Contributor

If I try to generate code with protoc-gen-rust i.e. with the command: protoc --rust_out=out test.proto I get the following error:

test.proto: is a proto3 file that contains optional fields, but code generator protoc-gen-rust hasn't been updated to support optional fields in proto3. Please ask the owner of this code generator to support proto3 optional.--rust_out:

Here's my test.proto file:

syntax = "proto3";

message Test {
  optional string value = 1;
}

Without the optional keyword the command does not raise an error. Likewise, if I change the syntax to proto2, the command does not raise an error.

I installed protoc-gen-rust via cargo install protobuf-codegen (version v3.0.2 was installed).

OS version:

uname -a
Linux 78ae9044ec23 5.10.104-linuxkit #1 SMP Wed Mar 9 19:05:23 UTC 2022 x86_64 Linux

Looking through the docs, it seems that optional fields should be supported, so I'm not sure if I'm doing something wrong or not. My goal is to end up with an Option in the generated rust code.

Thanks :)

@stepancheg
Copy link
Owner

stepancheg commented May 31, 2022

Interesting. Optional fields work, but when using protobuf-codegen crate, and I didn't test with protoc binary.

If you need to run protoc manually, this need to be implemented (in rust-protobuf): https://github.com/protocolbuffers/protobuf/blob/main/docs/implementing_proto3_presence.md#signaling-that-your-code-generator-supports-proto3-optional

@jesseduffield
Copy link
Contributor Author

Thanks for the quick response. When you say it needs to be implemented: are you referring to actually implementing support for proto3 optional fields, or do you just mean telling protoc that we already do have support?

@stepancheg
Copy link
Owner

stepancheg commented May 31, 2022

are you referring to actually implementing support for proto3 optional fields, or do you just mean telling protoc that we already do have support?

The latter, only need to signal to protoc.

proto3 optional is implemented, test.

@jesseduffield
Copy link
Contributor Author

I believe #626 will do the trick

@stepancheg
Copy link
Owner

Reopening until it is released.

@stepancheg
Copy link
Owner

3.0.3

Tim-Zhang added a commit to Tim-Zhang/rust-protobuf that referenced this issue Aug 18, 2022
It's a backport of stepancheg#626.

Fixes: stepancheg#625

Signed-off-by: Tim Zhang <tim@hyper.sh>
Tim-Zhang added a commit to Tim-Zhang/rust-protobuf that referenced this issue Sep 7, 2022
It's a backport of stepancheg#626.

Fixes: stepancheg#625

Signed-off-by: Tim Zhang <tim@hyper.sh>
Tim-Zhang added a commit to Tim-Zhang/rust-protobuf that referenced this issue Sep 7, 2022
It's a backport of stepancheg#626.

Fixes: stepancheg#625

Signed-off-by: Tim Zhang <tim@hyper.sh>
stepancheg pushed a commit that referenced this issue Sep 26, 2022
It's a backport of #626.

Fixes: #625

Signed-off-by: Tim Zhang <tim@hyper.sh>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants