-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
[Rust] Missing 'use' statements when generating from .fbs that has imports #5589
Comments
@rw FYI this is one of the issues I ran into |
This PR updates the build docker image to generate IPC source based on the flatbuffer specification. Note that the generated files are currently not used in the build (the generated files have a `_generated.rs` suffix so don't overwrite the checked in versions of the files). We cannot fully automate this until google/flatbuffers#5589 is resolved, or we figure out a workaround, but I suggest we merge this current PR since it lays the groundwork. Closes #5738 from andygrove/ARROW-7003 and squashes the following commits: 80abddb <Andy Grove> lint 43f3e89 <Andy Grove> reset workdir 0a186b5 <Andy Grove> lint 6a9c6f0 <Andy Grove> fix docker lint issue b2c9173 <Andy Grove> Generate flatbuffers files in docker build image Authored-by: Andy Grove <andygrove73@gmail.com> Signed-off-by: Andy Grove <andygrove73@gmail.com>
I ran into this as well. I was able to work around it using the |
This issue is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days. |
Any plans of addressing this one? |
I don't think anyone is currently working on it. Also, this could be a duplicate of #6063 |
My workaround was to manually combine all my schemas into one giant file. Not at all ideal, and a maintenance nightmare, but it at least kept me moving forward. |
There's some incompatibility between how C++ and Rust namespaces work that were probably not addressed in the code generator. Specifically, in C++, every file can unilaterally decide to contribute to the any namespace; while in Rust, each file is in its own namespace, named after the filename. I have to think a bit how to best structure this on the flatc side, but |
|
If you're referring to the |
For what its worth, as far as I can tell |
So I think one way to emulate C style namespaces is to have a special new file, say #[allow(unused_imports)]
mod generated {
// Construct Flatbuffers namespace.
pub mod ns1 {
pub use crate::generated::file1_generated::ns1::*;
pub use crate::generated::file2_generated::ns1::*;
pub use crate::generated::file3_generated::ns1::*;
pub mod ns2 {
pub use crate::generated::file1_generated::ns1::ns2::*;
// file2_generated omitted because it doesn't have ns2.
pub use crate::generated::file3_generated::ns1::ns2::*;
}
}
// In practice the generated files won't be inlined, these would be separate files.
mod file1_generated {
pub mod ns1 {
pub mod ns2 {
pub struct Foo;
}
}
}
mod file2_generated {
pub mod ns1 {
pub struct Bar(crate::generated::ns1::ns2::Foo);
}
}
mod file3_generated {
pub mod ns1 {
pub mod ns2 {
pub struct Baz(
crate::generated::ns1::ns2::Foo,
crate::generated::ns1::Bar);
}
}
}
} Problems / Questions:
|
@aardappel can you LGTM the high level changes to
|
Hmm, having this I'd be tempted to go for a simpler solution, that if a schema is being parsed while |
Its definitely a little complex, but I think its the best way to model C++ style namespaces in Rust. It also kind of matches the structure of many rust crates where the root file of the crate,
I'd rather not do that because it'd make it harder for a C++ based project to start using Rust, lol. |
Maybe it should be actually called
It wouldn't be, it just makes it obvious that in these case you need to use You could even invert it, make I am fine with any of these solutions in the end. |
I actually ran into multiple problems with how generated rust needs to be imported to run. In one project I actually have the same code imported twice with types doubled, because it wouldn't work otherwise. Therefore I'm all for a file grouping everything in one place and acting as an entrypoint. I'm even for generating a whole lib crate, if this would make things easier. |
This PR updates the build docker image to generate IPC source based on the flatbuffer specification. Note that the generated files are currently not used in the build (the generated files have a `_generated.rs` suffix so don't overwrite the checked in versions of the files). We cannot fully automate this until google/flatbuffers#5589 is resolved, or we figure out a workaround, but I suggest we merge this current PR since it lays the groundwork. Closes #5738 from andygrove/ARROW-7003 and squashes the following commits: 80abddb9c <Andy Grove> lint 43f3e8931 <Andy Grove> reset workdir 0a186b5ae <Andy Grove> lint 6a9c6f04c <Andy Grove> fix docker lint issue b2c9173ce <Andy Grove> Generate flatbuffers files in docker build image Authored-by: Andy Grove <andygrove73@gmail.com> Signed-off-by: Andy Grove <andygrove73@gmail.com>
This issue is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days. |
Keep this open |
Ok, I finally made time to try a solution. My current plan is to go the way of Go and Csharp and generate types in their own files, which is simpler than what I suggested in #5589 (comment) since it doesn't include the |
I have something of a solution at #6731, which unfortunately will be a bit of a breaking change (see the PR for details). Please take a look and comment! |
Ok, I'm closing this now that #6731 is merged. It will be a while before we next release things but if one of you uses flatbuffers at HEAD, do give it a go! |
When generating code from multiple schema files, the necessary Rust
use
statements are not generated, therefore the generated code does not compile.For example, when generating code for Apache Arrow Tensor.fbs, which includes Schema.fbs, I get the following compilation error:
The workaround is for me to manually add
use crate::ipc::gen::Schema_generated::org::apache::arrow::flatbuf::Type
to the generated code.The text was updated successfully, but these errors were encountered: