-
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
[Rust] Support alloc-only no_std platforms #5366
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). 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 (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
Shoot, I keep forgetting that things that have been stabilized in nightly aren't necessarily stabilized in stable as well 😛 So I see two paths forward:
Thoughts? |
d55d378
to
4ee7bcb
Compare
@jrobsonchase Wow, thanks for submitting this PR! My first concern is ensuring that we work on stable Rust. After that, I'm happy to figure out how to support |
It should be working on stable now via the default I seem to have broken the generator tests. I think there were instructions in the PR guidelines that I skipped over because I wasn't originally planning on making any generator changes 😛 How do I go about making them happy again? |
@jrobsonchase Cool! Here's how you can fix it. There's a big error message in the middle of all the test output:
|
@jrobsonchase Is it feasible to add a new integration test file to this directory, to test this PR's functionality? https://github.com/google/flatbuffers/tree/master/tests/docker/languages |
Sure, I can look into that :) |
@jrobsonchase What do we need to do to get this finished? Thanks for starting it! |
It's ready to go as far as I can tell. The CI failure looks like an unrelated download problem. Maybe travis needs a kick? |
@rw ping |
@jrobsonchase Can you push a noop commit to trigger Travis? Then I'll check the logs to see that your new Dockerfile-based test ran successfully. |
@jrobsonchase Looks like we accidentally let this PR languish, sorry about that! Are you still up for finishing it? |
f381fd7
to
31f8799
Compare
What's left to push this over the line? |
also asking whats left on this? if any help is needed let me know. i'd love to see this on embedded :) |
6290611
to
f116b80
Compare
Missing |
@rw this code is still needed for use in embedded environments. We use a fork in production as a workaround, and ultimately we'd prefer not to. 😉 |
I've been following this issue for years as yes it would be nice to have for embedded. But really I'm actually waiting for the step further than this. The point of flatbuffers is zero copy, presumably zero allocation so its sad that allocation is still such a big part of even this pr. Most embedded code in rust land doesnt even use alloc partly because some allocator bits are still nightly only but mainly because the ecosystem is mostly real time nerds who are trying to avoid the original sin of allocation as much as they can. |
While that may be so, the first step to getting to an alloc-less situation (such as by using |
I think we may want to turn
This may require some minor rethinking of the API, e.g. use result types so we can fail to build a flatbuffer if the builder runs out of memory without just panic/abort. |
4ad0cb7
to
9cfc393
Compare
@rw This is ready for another review |
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.
This looks good! Thanks for working on this. Mostly some remaining nits.
my_game::example::Test::new(100, 101) | ||
][..] | ||
); | ||
} |
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.
Be sure to run rustfmt
on this file (should have a trailing newline).
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.
Perhaps there should be a CI check for formating. Generated files aside, almost everything has changes when cargo fmt
is run.
@jrobsonchase I think there are some more If you run |
There's also the issue that First you want to make the dependency on [dependencies]
smallvec = "1.6.1"
bitflags = "1.2.1"
thiserror = { version = "1.0.23", optional = true }
[features]
default = ["std"]
# Enable the std::error::Error implementation for InvalidFlatbuffer
std = ["thiserror"] Then in // The thiserror crate requires use of libstd.
#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "std")]
use thiserror::Error;
/// Describes how a flatuffer is invalid and, for data errors, roughly where. No extra tracing
/// information is given for DoS detecting errors since it will probably be a lot.
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Error))]
pub enum InvalidFlatbuffer {
#[cfg_attr(feature = "std", error("Missing required field `{required}`.\n{error_trace}"))]
MissingRequiredField {
required: &'static str,
error_trace: ErrorTrace,
},
// etc... This requires that you've made the changes to |
Thanks for the review - seems like things drifted further than I had thought in the time it was left to languish. |
Also re-run generator on sample.
This includes making thiserror optional. Additionally, tests are now run both with and without default features, which will ensure that the runtime continues to build/run without std support.
@josephlr Ready for another look |
@josephlr @jrobsonchase What's the status of this review? |
Does #6989 solve this issue for you? |
Closing seeing #6989 seems to address the same thing. Please reopen if not the case. |
Hi! I'd love to be able to use flatbuffers on embedded systems, and it looks like it wouldn't be hard to support seeing as it's already 90% there.
This adds the
#![no_std]
attribute, changes allstd
imports tocore
, and pullsVec
from thealloc
crate rather thanstd
. I'd also love to see aStaticFlatBufferBuilder
(or some such) that works only with ungrowable buffers, but that'll be a bigger change.For platforms with
std
, this shouldn't change a thing - it just allows it to be used as a dependency forno_std
crates.