I was trying to use this protobuf crate to generate rust files using this build.rs
:
protobuf_codegen::Codegen::new()
.protoc()
.cargo_out_dir("generated_with_native")
.input("src/protos/capabilities.proto")
.include("src/protos")
.run_from_script();
I tried including generated rs code via this:
pub mod proto {
include!(concat!(env!("OUT_DIR"), "/generated_with_native/capabilities.rs"));
}
The problem is that I have got a lot of issues like this:
error: an inner attribute is not permitted in this context
--> /home/dimanne/devel/scripts/observability/target/debug/build/input-20af024046742d76/out/generated_with_native/capabilities.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
I think the crux of the issue is that codegen inserted a bunch of attributes, and then I included them in a another file, and rust is not happy that internal attributes are pulled via include in another file.
What is the correct way to use protobuf in rust?