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

A lot of errors during compilation of generated code #682

Open
DimanNe opened this issue Sep 21, 2023 · 2 comments
Open

A lot of errors during compilation of generated code #682

DimanNe opened this issue Sep 21, 2023 · 2 comments

Comments

@DimanNe
Copy link

DimanNe commented Sep 21, 2023

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();
}
@vaikzs
Copy link
Contributor

vaikzs commented Oct 9, 2023

@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.

@SoftwareApe
Copy link

SoftwareApe commented Apr 5, 2024

@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

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

No branches or pull requests

3 participants