-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Support for Rust programming language #3894
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
CLAs look good, thanks! |
Regarding the refactoring effort going on for the flatbuffers library (to make it simpler and better for you code generator writer and for the flatbuffers library maintainer), it would be great in my opinion, if you could remove the dependency on the TD macro (that forces you to touch the parser file, as well as the files of other code generators) and make the rust code generator self-contained in idl_gen_rust.cpp You would mostly have to define your own GetXType methods |
Sure I will do that. If its going to be self contained should I just implement it entirely in Rust...in a separate repo perhaps? |
Le 02/06/2016 08:52, Joseph Dunne a écrit :
|
include/flatbuffers/idl.h
Outdated
TD(UTYPE, "", uint8_t, byte, byte, byte, uint8, u8) /* begin scalar/int */ \ | ||
TD(BOOL, "bool", uint8_t, boolean,byte, bool, bool, bool) \ | ||
TD(CHAR, "byte", int8_t, byte, int8, sbyte, int8, i8) \ | ||
TD(UCHAR, "ubyte", uint8_t, byte, byte, byte, u8, u8) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You appear to also be changing the Python type?
Also: align columns.
Wow! Looks like great work. I know @rw was working on a Rust port as well, maybe he can help review / suggest improvements or functionality from his port. @Lakedaemon : for now, the TD macro is how all generators work, so that's what this PR should follow as well, until we somehow change it for al generators. |
Thanks for reviewing. I will do the cleanup and refactor and then @rw can take a look |
Great to see this! Let me know when you are ready for review. |
@josephDunne My biggest piece of feedback on this version is that I need to see fuzz testing. The C++, Go, and Python versions all have fuzzers, so there are lots of examples. Let me know if that makes sense to you. Another piece of feedback is that instead of using Otherwise, a quick read of the runtime and generated code raises no red flags at this time, nice work! |
Makes sense. I will add it. Do you mind if its quickcheck tests (assuming quickcheck works on rust stable)? Or do you prefer I copy the approach already in use? Also how do you feel about replacing the generated boiler plate with macros...something like this: table!(Monster, [{hp, 8, 150},
{mana, 10, 100},
{test,, 12, Vec3}
...
]); These macros are then expanded at compile time. In general I dont like adding extra layers of indirection but it would make the CPP generator a lot easier to maintain as most of the work will be done in the rust library. |
^ big fan of macros here ;) |
@gwvo I'm not surprised :p Actually, idl_gen_js.cpp doesn't use the TD macro. They use GenType method that is really easy to understand (I'm a big fan) : Also, the go/python/... folks could also avoid the TD macro by defining static const char ctypename[] inside their idl_gen_**.cpp file, making their GenBasic method easier to understand IMO, idl.h should not contain language specific stuff. I'll fight the TD macro or die in the process. :) |
@josephDunne I'd like to see 1-to-1 equivalency, first. After that, though, QC is great. (My only concern is that QC's default |
@rw 👍 |
I have done some initial refactoring and cleanup. Fuzzing tests are still outstanding. I may only get to this next weekend. I am however using this code as part of a project so its getting some field testing in the mean time :-) some discussion points (@rw?)
fn get_scalar_vector<u32>(buff: &[u8], offset: UOffset) -> &[T] where T: Deref<Target=u32> { .. }
for x in table.get_scalar_vector<u32>(..) {
println!("This is a u32 number: {}", *x)
println!("This is a pointer into the buffer transmuted as some type T: {p}", x);
} Not sure..
|
@josephDunne great progress! Regarding fuzzing, it seems it would be most straightforward to skip QuickCheck for now and use the code from the Go port: https://github.com/google/flatbuffers/blob/master/tests/go_test.go#L283-L426 That uses a simple LCG RNG to drive some serialization cases. Do you think it would be straightforward to port to Rust? Also, do you know if any Rust code makes heap allocations besides the |
Hi all! I'm glad there's still interest in a Rust port. I know it's been a disappointing ride over the last few years for those of you wanting to use FlatBuffers in Rust, and seeing it not come together. About a month ago, I dug in full-time for a few weeks and made another attempt at writing a solid Rust port. As some of you may recall, I've tried this before. This time around, though, my Rust-fu is much better, and I'm doing this out of personal necessity. I want to use FlatBuffers in Rust to develop other software where speed is critical: storing data in a write-ahead transaction log in a NoSQL datastore. Using Rust with FlatBuffers is the optimal choice for that project. Here are some goals of this unpublished WIP port:
Here is the progress so far:
I intend to publish the WIP branch of this in the upcoming weeks so that I can start getting feedback on the user experience of the generated code. Thanks for your patience! |
I have added you as admin on crates.io for the flatbuffers crate. Let me know if you get it |
@rw this is awesome news! can't wait :) |
@rw This is great news! I am wanting to use flatbuffers for the Apache Arrow rust library (we need it for IPC). I would be happy to be an early adopter / tester! |
@rw please don't hesitate to post your WIP branch, even if it's not clean yet. Weeks are precious :) |
@rw Is there any update on this? I'm keen to use this with the Rust version of Apache Arrow so that we can implement the IPC mechanism. I'm happy to be an early adopter/tester. |
Below is a link to an experimental, currently-broken WIP branch. I'm putting the code up here only to show progress for those of you who are curious. (Also, to force myself to develop in the open.) https://github.com/rw/flatbuffers/tree/2018-02--rust The generated code is at https://github.com/rw/flatbuffers/blob/2018-02--rust/tests/rust_usage_test/src/monster_test_generated.rs Please bear with me as I get this into shape. |
Generated code typechecks and is importable as a Rust crate; some wire format tests are starting to pass. |
@rw What is a good way to report issues / discuss this? I'm hitting compilation errors building the project. Do you have a gitter address? |
@andygrove I use the following command:
But, I can't support your usage right now since the core code is in flux. I'm just giving status updates here because it seems a lot of people are waiting for this to land. |
Got 10 byte layout tests passing, and tomorrow I'll be implementing the start/end functions for creating Tables. |
Byte layout tests (from Go and Python) all pass. |
@rw is there a repo where you're making this commits? It seems like the branch associated to this pull request hasn't been updated since August 2017. I'd be keen to help in the development of this feature, if my help is needed. Thanks |
@ChristopherRabotin I believe it's this branch: |
Fuzz test of scalar serialization inside vtables passes. |
Tests pass that verify generated Rust code can correctly interpret the example serialized files created by the C++, Go, Java, and Python test suites. (Except for vector data, since I'm still working on the ergonomics of vectors.) |
Creation of example serialized data (the gold "Monster") in Rust partially passes: library code and generated code can both create correct tables with scalar values, strings, and table unions. |
@rw Thanks for your work! I'm closely tracking your progress and have already made attempts to use it. I wasn't able to get it working last week, but I will try again soon. |
Non-user-visible status update: almost done with a code generator refactor. This is a way to eliminate long-tail bugs, and I can do it now that I'm over most of the conceptual hurdles and can create better abstractions. |
I solved a type system problem: we now lift Flatbuffer Offset traversals into the typesystem. This gets the ergonomics closer to the C++ port (which is a good thing). Proof of concept: https://play.rust-lang.org/?gist=20b4ab8ec5b82c409d431f3658eadd89&version=stable&mode=debug&edition=2015 Edit: improved version: https://play.rust-lang.org/?gist=648af791b28a91cd4c705897c5499eed&version=stable&mode=debug&edition=2015 |
This code is still WIP (I very much need to clean up a lot of things, and rebase) but this branch has all (70+) tests passing. If you're feeling adventurous, try it out: https://github.com/rw/flatbuffers/tree/2018-08-12--all-tests-passing Update: As of commit |
Final checklist before PR:
Edit: we aren't going to do this for this version: "Included/nested generated code imports (the code is generated, but the |
Pull Request submitted: #4898 |
@josephDunne Thank you for your hard work on this in 2016. You helped us start the long journey to getting a Rust port contributed to FlatBuffers. We really appreciate your efforts, and hope you stay involved in the project! Closing in favor of #4898. |
@josephDunne Would you please send me an email about us getting control of the Cargo project? I don't see the notification you mentioned from April. |
This pull request include an implementation of the Flatbuffers runtime for the Rust programming language and Rust code generation via the
flatc
binary.Code is well documented and currently passes a full suite of tests. I do however still need to add a sample and do more benchmark testing. In the meantime I want to get this on the projects radar to discuss.
Thanks!