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

A lot of errors during compilation of generated code

Open DimanNe opened this issue 2 years ago • 5 comments

I am using native codegen & parser. I was trying to compile generated rs files from created from this file and got these errors:

   Compiling input v0.1.0 (/home/dimanne/devel/scripts/observability/digester)
error: an inner attribute is not permitted in this context
 --> /home/dimanne/devel/scripts/observability/target/debug/build/input-0327159e6708cec6/out/protos/tetragon.rs:6:1
  |
6 | #![allow(unknown_lints)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
  = note: outer attributes, like `#[test]`, annotate the item following them

error: an inner attribute is not permitted in this context
 --> /home/dimanne/devel/scripts/observability/target/debug/build/input-0327159e6708cec6/out/protos/tetragon.rs:7:1
  |
7 | #![allow(clippy::all)]
  | ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
  = note: outer attributes, like `#[test]`, annotate the item following them




error[E0753]: expected outer doc comment
  --> /home/dimanne/devel/scripts/observability/target/debug/build/input-0327159e6708cec6/out/protos/tetragon.rs:22:1
   |
22 | //! Generated file from `tetragon.proto`
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: inner doc comments like this (starting with `//!` or `/*!`) can only appear before items
help: you might have meant to write a regular comment
   |
22 - //! Generated file from `tetragon.proto`
22 + // Generated file from `tetragon.proto`
   |


error[E0433]: failed to resolve: there are too many leading `super` keywords
   --> /home/dimanne/devel/scripts/observability/target/debug/build/input-0327159e6708cec6/out/protos/tetragon.rs:614:62
    |
614 |     pub permitted: ::std::vec::Vec<::protobuf::EnumOrUnknown<super::capabilities::CapabilitiesType>>,
    |                                                              ^^^^^ there are too many leading `super` keywords

error[E0433]: failed to resolve: there are too many leading `super` keywords
   --> /home/dimanne/devel/scripts/observability/target/debug/build/input-0327159e6708cec6/out/protos/tetragon.rs:616:62
    |
616 |     pub effective: ::std::vec::Vec<::protobuf::EnumOrUnknown<super::capabilities::CapabilitiesType>>,
    |                                                              ^^^^^ there are too many leading `super` keywords

This is my build.rs:

fn main() {
   protobuf_codegen::Codegen::new()
      .pure()
      .cargo_out_dir("protos")
      .includes(["src/"])
      .input("src/tetragon.proto")
      .input("src/capabilities.proto")
      .run_from_script();
}

DimanNe avatar Sep 21 '23 23:09 DimanNe

@DimanNe Not sure if you are still facing the issue. The following build.rs works for me in rust 1.71.1. I placed both capabilities.proto and tetragon.proto under protos folder like so.

File Structure

.
├── Cargo.lock
├── Cargo.toml
├── build.rs
├── src
│   ├── gen
│   ├── lib.rs
│   └── protos
└── target
    ├── debug
    └── .. 

fn main() {
    protobuf_codegen::Codegen::new()
        .pure()
        .out_dir("src/gen")
        .includes(["src/protos"])
        .inputs(&[
            "src/protos/tetragon.proto",
            "src/protos/tetragon/capabilities.proto",
        ])
        .run_from_script();
}

If still facing the issue. Try cargo cache -a or hard delete of target folder itself.

vaikzs avatar Oct 09 '23 08:10 vaikzs

@DimanNe The problem you're facing is not from the build.rs, it's from your src/main.rs or wherever you include the protobuf code.

You need to include the mod.rs file not the <name of protobuf>.rs file.

include!(concat!(env!("OUT_DIR"), "/protos/mod.rs"));

Ideally this should be added to the example. There are even some hacks to work around this floating around: https://dev.to/elshize/protobuf-code-generation-in-rust-1e35

SoftwareApe avatar Apr 05 '24 14:04 SoftwareApe

I confirm I have this issue as well.

marie-bnl avatar Jul 12 '24 14:07 marie-bnl

I confirm I have this issue as well.

Did you check my comment? I think it's mostly a documentation, not a technical issue.

SoftwareApe avatar Jul 12 '24 14:07 SoftwareApe

Oh, I had checked your comment but for some reason I missed the important part.

marie-bnl avatar Jul 12 '24 17:07 marie-bnl