rust-protobuf icon indicating copy to clipboard operation
rust-protobuf copied to clipboard

Cannot compile crate when generating .rs with serde with protoc

Open xenosathl opened this issue 7 years ago • 3 comments

I cannot compile my project after generating .rs file from .proto with protoc. As I'm really poor with describing, so I will do step by step reproduction:

  1. Cargo.toml:
[dependencies]
serde = { version = "1.0.90", features = ["derive"] }
serde_bytes = "0.11.1"
protobuf = { git = "https://github.com/stepancheg/rust-protobuf.git", branch = "master" }
protoc-rust = { git = "https://github.com/stepancheg/rust-protobuf.git", branch = "master" }

[features]
deafult = ["with-serde"]
  1. src/header.proto:
syntax = "proto2";

import "rustproto.proto";
option (rustproto.serde_derive_all) = true;

message Header {
    required uint32 msg_id = 1;
}
  1. Download this repo and put all from rust-protobuf/proto into src/ (basically directory google and file rustproto.proto)

  2. Run protoc --rust_out . header.proto

  3. src/lib.rs:

mod header;

5a. cargo build:

   Compiling interfaces v0.2.0 (/home/tom/workspace/rust/servo/interfaces)
error[E0407]: method `as_any` is not a member of trait `protobuf::Message`
   --> src/header.rs:119:5
    |
119 | /     fn as_any(&self) -> &::std::any::Any {
120 | |         self as &::std::any::Any
121 | |     }
    | |_____^ not a member of trait `protobuf::Message`

error[E0407]: method `as_any_mut` is not a member of trait `protobuf::Message`
   --> src/header.rs:122:5
    |
122 | /     fn as_any_mut(&mut self) -> &mut ::std::any::Any {
123 | |         self as &mut ::std::any::Any
124 | |     }
    | |_____^ not a member of trait `protobuf::Message`

error[E0407]: method `into_any` is not a member of trait `protobuf::Message`
   --> src/header.rs:125:5
    |
125 | /     fn into_any(self: Box<Self>) -> ::std::boxed::Box<::std::any::Any> {
126 | |         self
127 | |     }
    | |_____^ not a member of trait `protobuf::Message`

error[E0433]: failed to resolve: could not find `types` in `protobuf`
   --> src/header.rs:145:104
    |
145 |                 fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint32>(
    |                                                                                                        ^^^^^ could not find `types` in `protobuf`

error[E0407]: method `as_ref` is not a member of trait `protobuf::reflect::ProtobufValue`
   --> src/header.rs:184:5
    |
184 | /     fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef {
185 | |         ::protobuf::reflect::ProtobufValueRef::Message(self)
186 | |     }
    | |_____^ not a member of trait `protobuf::reflect::ProtobufValue`

error[E0433]: failed to resolve: could not find `ProtobufValueRef` in `reflect`
   --> src/header.rs:185:30
    |
185 |         ::protobuf::reflect::ProtobufValueRef::Message(self)
    |                              ^^^^^^^^^^^^^^^^ could not find `ProtobufValueRef` in `reflect`

error[E0412]: cannot find type `CachedSize` in module `protobuf`
  --> src/header.rs:33:34
   |
33 |     pub cached_size: ::protobuf::CachedSize,
   |                                  ^^^^^^^^^^ not found in `protobuf`
help: possible candidate is found in another module, you can import it into scope
   |
21 | use protobuf::rt::CachedSize;
   |

error[E0425]: cannot find value `ONCE_INIT` in `protobuf::lazy`
   --> src/header.rs:139:37
    |
139 |             lock: ::protobuf::lazy::ONCE_INIT,
    |                                     ^^^^^^^^^ not found in `protobuf::lazy`
help: possible candidate is found in another module, you can import it into scope
    |
21  | use std::sync::ONCE_INIT;
    |

error[E0425]: cannot find function `make_simple_field_accessor` in `protobuf::reflect::accessor`
   --> src/header.rs:145:60
    |
145 |                 fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint32>(
    |                                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `protobuf::reflect::accessor`
help: possible candidate is found in another module, you can import it into scope
    |
21  | use protobuf::reflect::rt::make_simple_field_accessor;
    |

error[E0425]: cannot find value `ONCE_INIT` in `protobuf::lazy`
   --> src/header.rs:161:37
    |
161 |             lock: ::protobuf::lazy::ONCE_INIT,
    |                                     ^^^^^^^^^ not found in `protobuf::lazy`
help: possible candidate is found in another module, you can import it into scope
    |
21  | use std::sync::ONCE_INIT;
    |

error[E0412]: cannot find type `ProtobufValueRef` in module `protobuf::reflect`
   --> src/header.rs:184:46
    |
184 |     fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef {
    |                                              ^^^^^^^^^^^^^^^^ help: a trait with a similar name exists: `ProtobufValue`

error[E0425]: cannot find value `ONCE_INIT` in `protobuf::lazy`
   --> src/header.rs:205:29
    |
205 |     lock: ::protobuf::lazy::ONCE_INIT,
    |                             ^^^^^^^^^ not found in `protobuf::lazy`
help: possible candidate is found in another module, you can import it into scope
    |
21  | use std::sync::ONCE_INIT;
    |

error[E0603]: module `lazy` is private
   --> src/header.rs:138:44
    |
138 |         static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy {
    |                                            ^^^^

error[E0603]: module `lazy` is private
   --> src/header.rs:138:109
    |
138 |         static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy {
    |                                                                                                             ^^^^

error[E0603]: module `lazy` is private
   --> src/header.rs:139:31
    |
139 |             lock: ::protobuf::lazy::ONCE_INIT,
    |                               ^^^^

error[E0603]: module `accessor` is private
   --> src/header.rs:145:50
    |
145 |                 fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint32>(
    |                                                  ^^^^^^^^

error[E0603]: module `lazy` is private
   --> src/header.rs:160:42
    |
160 |         static mut instance: ::protobuf::lazy::Lazy<Header> = ::protobuf::lazy::Lazy {
    |                                          ^^^^

error[E0603]: module `lazy` is private
   --> src/header.rs:160:75
    |
160 |         static mut instance: ::protobuf::lazy::Lazy<Header> = ::protobuf::lazy::Lazy {
    |                                                                           ^^^^

error[E0603]: module `lazy` is private
   --> src/header.rs:161:31
    |
161 |             lock: ::protobuf::lazy::ONCE_INIT,
    |                               ^^^^

error[E0603]: module `lazy` is private
   --> src/header.rs:204:52
    |
204 | static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy {
    |                                                    ^^^^

error[E0603]: module `lazy` is private
   --> src/header.rs:204:122
    |
204 | static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy {
    |                                                                                                                          ^^^^

error[E0603]: module `lazy` is private
   --> src/header.rs:205:23
    |
205 |     lock: ::protobuf::lazy::ONCE_INIT,
    |                       ^^^^

error[E0308]: mismatched types
   --> src/header.rs:140:18
    |
140 |             ptr: 0 as *const ::protobuf::reflect::MessageDescriptor,
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `std::cell::UnsafeCell`, found *-ptr
    |
    = note: expected type `std::cell::UnsafeCell<*const protobuf::reflect::message::MessageDescriptor>`
               found type `*const protobuf::reflect::message::MessageDescriptor`

error[E0308]: mismatched types
   --> src/header.rs:162:18
    |
162 |             ptr: 0 as *const Header,
    |                  ^^^^^^^^^^^^^^^^^^ expected struct `std::cell::UnsafeCell`, found *-ptr
    |
    = note: expected type `std::cell::UnsafeCell<*const header::Header>`
               found type `*const header::Header`

error[E0308]: mismatched types
   --> src/header.rs:206:10
    |
206 |     ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto,
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `std::cell::UnsafeCell`, found *-ptr
    |
    = note: expected type `std::cell::UnsafeCell<*const protobuf::descriptor::FileDescriptorProto>`
               found type `*const protobuf::descriptor::FileDescriptorProto`

error: aborting due to 25 previous errors

Some errors occurred: E0308, E0407, E0412, E0425, E0433, E0603.
For more information about an error, try `rustc --explain E0308`.
error: Could not compile `interfaces`.

To learn more, run the command again with --verbose.

=====================================

=====================================

5b. cargo build --features deafult

   Compiling interfaces v0.2.0 (/home/tom/workspace/rust/servo/interfaces)
error: cannot find derive macro `Deserialize` in this scope
  --> src/header.rs:25:54
   |
25 | #[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
   |                                                      ^^^^^^^^^^^

error: cannot find derive macro `Serialize` in this scope
  --> src/header.rs:25:43
   |
25 | #[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
   |                                           ^^^^^^^^^

error[E0407]: method `as_any` is not a member of trait `protobuf::Message`
   --> src/header.rs:119:5
    |
119 | /     fn as_any(&self) -> &::std::any::Any {
120 | |         self as &::std::any::Any
121 | |     }
    | |_____^ not a member of trait `protobuf::Message`

error[E0407]: method `as_any_mut` is not a member of trait `protobuf::Message`
   --> src/header.rs:122:5
    |
122 | /     fn as_any_mut(&mut self) -> &mut ::std::any::Any {
123 | |         self as &mut ::std::any::Any
124 | |     }
    | |_____^ not a member of trait `protobuf::Message`

error[E0407]: method `into_any` is not a member of trait `protobuf::Message`
   --> src/header.rs:125:5
    |
125 | /     fn into_any(self: Box<Self>) -> ::std::boxed::Box<::std::any::Any> {
126 | |         self
127 | |     }
    | |_____^ not a member of trait `protobuf::Message`

error[E0433]: failed to resolve: could not find `types` in `protobuf`
   --> src/header.rs:145:104
    |
145 |                 fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint32>(
    |                                                                                                        ^^^^^ could not find `types` in `protobuf`

error[E0407]: method `as_ref` is not a member of trait `protobuf::reflect::ProtobufValue`
   --> src/header.rs:184:5
    |
184 | /     fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef {
185 | |         ::protobuf::reflect::ProtobufValueRef::Message(self)
186 | |     }
    | |_____^ not a member of trait `protobuf::reflect::ProtobufValue`

error[E0433]: failed to resolve: could not find `ProtobufValueRef` in `reflect`
   --> src/header.rs:185:30
    |
185 |         ::protobuf::reflect::ProtobufValueRef::Message(self)
    |                              ^^^^^^^^^^^^^^^^ could not find `ProtobufValueRef` in `reflect`

error[E0412]: cannot find type `CachedSize` in module `protobuf`
  --> src/header.rs:33:34
   |
33 |     pub cached_size: ::protobuf::CachedSize,
   |                                  ^^^^^^^^^^ not found in `protobuf`
help: possible candidate is found in another module, you can import it into scope
   |
21 | use protobuf::rt::CachedSize;
   |

error[E0425]: cannot find value `ONCE_INIT` in `protobuf::lazy`
   --> src/header.rs:139:37
    |
139 |             lock: ::protobuf::lazy::ONCE_INIT,
    |                                     ^^^^^^^^^ not found in `protobuf::lazy`
help: possible candidate is found in another module, you can import it into scope
    |
21  | use std::sync::ONCE_INIT;
    |

error[E0425]: cannot find function `make_simple_field_accessor` in `protobuf::reflect::accessor`
   --> src/header.rs:145:60
    |
145 |                 fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint32>(
    |                                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `protobuf::reflect::accessor`
help: possible candidate is found in another module, you can import it into scope
    |
21  | use protobuf::reflect::rt::make_simple_field_accessor;
    |

error[E0425]: cannot find value `ONCE_INIT` in `protobuf::lazy`
   --> src/header.rs:161:37
    |
161 |             lock: ::protobuf::lazy::ONCE_INIT,
    |                                     ^^^^^^^^^ not found in `protobuf::lazy`
help: possible candidate is found in another module, you can import it into scope
    |
21  | use std::sync::ONCE_INIT;
    |

error[E0412]: cannot find type `ProtobufValueRef` in module `protobuf::reflect`
   --> src/header.rs:184:46
    |
184 |     fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef {
    |                                              ^^^^^^^^^^^^^^^^ help: a trait with a similar name exists: `ProtobufValue`

error[E0425]: cannot find value `ONCE_INIT` in `protobuf::lazy`
   --> src/header.rs:205:29
    |
205 |     lock: ::protobuf::lazy::ONCE_INIT,
    |                             ^^^^^^^^^ not found in `protobuf::lazy`
help: possible candidate is found in another module, you can import it into scope
    |
21  | use std::sync::ONCE_INIT;
    |

error[E0603]: module `lazy` is private
   --> src/header.rs:138:44
    |
138 |         static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy {
    |                                            ^^^^

error[E0603]: module `lazy` is private
   --> src/header.rs:138:109
    |
138 |         static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy {
    |                                                                                                             ^^^^

error[E0603]: module `lazy` is private
   --> src/header.rs:139:31
    |
139 |             lock: ::protobuf::lazy::ONCE_INIT,
    |                               ^^^^

error[E0603]: module `accessor` is private
   --> src/header.rs:145:50
    |
145 |                 fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint32>(
    |                                                  ^^^^^^^^

error[E0603]: module `lazy` is private
   --> src/header.rs:160:42
    |
160 |         static mut instance: ::protobuf::lazy::Lazy<Header> = ::protobuf::lazy::Lazy {
    |                                          ^^^^

error[E0603]: module `lazy` is private
   --> src/header.rs:160:75
    |
160 |         static mut instance: ::protobuf::lazy::Lazy<Header> = ::protobuf::lazy::Lazy {
    |                                                                           ^^^^

error[E0603]: module `lazy` is private
   --> src/header.rs:161:31
    |
161 |             lock: ::protobuf::lazy::ONCE_INIT,
    |                               ^^^^

error[E0603]: module `lazy` is private
   --> src/header.rs:204:52
    |
204 | static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy {
    |                                                    ^^^^

error[E0603]: module `lazy` is private
   --> src/header.rs:204:122
    |
204 | static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy {
    |                                                                                                                          ^^^^

error[E0603]: module `lazy` is private
   --> src/header.rs:205:23
    |
205 |     lock: ::protobuf::lazy::ONCE_INIT,
    |                       ^^^^

error[E0658]: The attribute `serde` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
  --> src/header.rs:30:40
   |
30 |     #[cfg_attr(feature = "with-serde", serde(skip))]
   |                                        ^^^^^^^^^^^

error[E0658]: The attribute `serde` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
  --> src/header.rs:32:40
   |
32 |     #[cfg_attr(feature = "with-serde", serde(skip))]
   |                                        ^^^^^^^^^^^

error[E0308]: mismatched types
   --> src/header.rs:140:18
    |
140 |             ptr: 0 as *const ::protobuf::reflect::MessageDescriptor,
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `std::cell::UnsafeCell`, found *-ptr
    |
    = note: expected type `std::cell::UnsafeCell<*const protobuf::reflect::message::MessageDescriptor>`
               found type `*const protobuf::reflect::message::MessageDescriptor`

error[E0308]: mismatched types
   --> src/header.rs:162:18
    |
162 |             ptr: 0 as *const Header,
    |                  ^^^^^^^^^^^^^^^^^^ expected struct `std::cell::UnsafeCell`, found *-ptr
    |
    = note: expected type `std::cell::UnsafeCell<*const header::Header>`
               found type `*const header::Header`

error[E0308]: mismatched types
   --> src/header.rs:206:10
    |
206 |     ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto,
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `std::cell::UnsafeCell`, found *-ptr
    |
    = note: expected type `std::cell::UnsafeCell<*const protobuf::descriptor::FileDescriptorProto>`
               found type `*const protobuf::descriptor::FileDescriptorProto`

error: aborting due to 29 previous errors

Some errors occurred: E0308, E0407, E0412, E0425, E0433, E0603, E0658.
For more information about an error, try `rustc --explain E0308`.
error: Could not compile `interfaces`.

To learn more, run the command again with --verbose.

Some additional information:

  • cargo --version: cargo 1.35.0 (6f3e9c367 2019-04-04)
  • rustc --version: rustc 1.35.0 (3c235d560 2019-05-20)
  • protoc --version: libprotoc 3.0.0
  • deps protobuf and protobuf-codegen both checked out at 76c8892a410fa7
  • protobuf-codegen v2.6.2

For better visualization of repo:

$ tree -L 2 # in ./src/
.
├── google
│   └── protobuf
├── header.proto
├── header.rs
├── lib.rs
└── rustproto.proto

2 directories, 4 files

Changing from proto2 to proto3 doesn't help.

So, what do I miss? Thanks in advance

EDIT: one of the logs was doubled - corrected. fixed minor typos

xenosathl avatar Jun 23 '19 18:06 xenosathl

Works on my machine: https://github.com/stepancheg/repro-424

I suspect you have installed the wrong version of rust-protobuf (e. g. stable, and not master).

Also note that you added dependency protoc-rust, but you are generating protos manually, so you don't use that crate.

stepancheg avatar Jun 23 '19 20:06 stepancheg

Thanks for quick answer.

As you see, protobuf's version is matched with master, so it would be weird if stable release somehow survived cargo build process.

I cloned your repro repo and indeed it built with success. I tried to find some diffs between Cargo.lock files but unfortunately most important difference is protobuf commit - a7ea73e vs 76c8892 .

Anyway, as you produced working reproduction which compiles fine on my PC I think it should be closed and should be treated as environment error.

Thanks for help and I'm sorry for interrupting you ;)

xenosathl avatar Jun 26 '19 18:06 xenosathl

Note current master and version >= 2.7 compiles protobuf version into generated files.

https://github.com/stepancheg/rust-protobuf/commit/2ab4d50c27c4dd7803b64ce1a43e2c134532c7a6

Error should be better now.

Thanks for help and I'm sorry for interrupting you ;)

Not at all. But I don't promise to reply fast.

stepancheg avatar Jul 01 '19 23:07 stepancheg