-
Notifications
You must be signed in to change notification settings - Fork 527
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
Make prost a no_std
compatible library, and prost-build able to gen…
#215
Conversation
Hi -- would love feedback on this experimental patch. Are you guys interested in supporting We are currently using There seem to be very few if any good serialization libs in rust that will work in |
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.
Hi @danburkert I realized that the |
fyi: our one thing worth mentioning is, in discussion in that PR, |
I'm fine with bumping the MSRV to 1.36; I consider both that and moving to a new breaking change of bytes to be a breaking change for |
35869fc
to
1fe73c0
Compare
@danburkert so one thing worth noting is, that's going to require some changes in It's not actually clear to me why Would you like to see a separate PR that gets rid of |
That's interesting. I can't tell from that PR or the linked issue what the motivation there is. If I recall correctly, the |
…erate `no_std` code The alternative is to get collections types from `core` and `alloc`. In the `no_std` mode in `prost_build`, we force it to always use BTreeMap since HashMap was not stabilized in `alloc::collections` library. The functionality is identical and the only incompatibilities in the interface are that we cannot use `std::error::Error` or `std::io::Error` in `no_std` mode because these types have not been moved to `alloc` and there is no alternative. This also uprevs `bytes` dependency to 0.5, and fixes up breakage after IntoBuf api is removed in `bytes` crate. Note that for now, we put a patch to `bytes` to pin to a specific commit in master, since bytes `0.5` is not released yet.
I think I think treating slice this way as |
Gotcha. It appears that's only the case of the 0.5.x branch, in which case I think you'll be forced to make the change inline with this PR. The tests pass |
yeah so what I'm finding is |
Hi @danburkert -- So I need some feedback from you on the following. When doing code-gen, after this PR, we hope to support both So my approach was:
One subtlety here is, is it important that users that consume Is it acceptable to require that all users of prost will write A second issue I've run into is that, the configuration feature on I'm not sure if proc-macro crates CAN be configured with features. There is a rust issue here: rust-lang/rust#54863 They seem to say that we should just have two versions of the proc macro and the user selects. I'm trying to figure out if there's a simple way to get this to work, if I've overlooked something, etc. Finally, in order to test that the We are likely going to start using this in tree, but I'm going to come back to this and try to iterate to make the best possible patch to go upstream. Let me know if there's anything about the direction, the way I changed the tests, etc. that you want to see work differently, and esp. if you see a good way to deal with the prost-derive configuration issue. If it's acceptable to require users of prost to do I think these are the only remaining development issues -- modulo the cfg stuff working in prost-derive, the |
Fyi: I also posted this issue on |
…rive as a workaround for feature-unification issues
@danburkert as a temporary work around so that we can use prost in our project, what I have done is: The purpose of this is that it allows It doesn't actually matter for our build that In the meantime we can proceed with using Would love any feedback |
I'll go back and answer the thread fully, but WRT failure, I'd also be open to just removing it. I don't think it's adding much value to the derive crate, I mostly used it as an experiment to see what it could do, and it doesn't seem to pull a lot of weight, at least in the derive context. Just replacing it with something like |
@danburkert I've reviewed what happened in tests crate in more detail -- it appears that during merge resolution, all upstream (prost) changes to I'm going to push a commit that nukes both of those crates, then I think you should tell me what if any "alloc" configuration test coverage there should be and we'll develop that from the ground up as needed. It's possible that the answer is none because there are no additional configuration options now, in prost-derive and prost-build |
prost-types/src/protobuf.rs
Outdated
@@ -992,10 +992,10 @@ pub struct Any { | |||
/// used with implementation specific semantics. | |||
/// | |||
#[prost(string, tag="1")] | |||
pub type_url: std::string::String, | |||
pub type_url: ::alloc::string::String, |
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.
Hmm its possible this should not have the leading ::
and thats why I was getting build failures without extern crate alloc
in the protobuf crate
This allows simplifying tests a bit, removing unnecessary `extern crate alloc;`
I removed leading I had been under the impression that when using rust macros, identifiers outside of the macro e.g. to the standard library are supposed to be fully qualified, because macro expansion can occur at any possible scope, so you either use e.g. https://doc.rust-lang.org/reference/macros-by-example.html#hygiene However maybe this doesn't actually apply for proc-macros? Since they are more like code-gen than macros? I'm not totally sure, we're reaching the limits of my understanding of rust. I'm considering trying to remove @tarcieri I suspect you might know this better than me :) |
@cbeck88 yeah, it's probably safer to use absolute paths in that case so as to avoid clashing with other things that might be in local scope |
but if i use absolute paths, does that mean that all prost users (even std users) must do like
IDK, I'm willing to try removing even the leading |
You could re-export the types you need via |
Ooh, that sounds good |
Yeah I think that sounds reasonable. See e.g. how |
…ost-derive This allows to remove `extern crate alloc;` from `protobuf` crate, and I think it means that users who don't care about `no_std` don't have to write `extern crate alloc;` to use prost
@danburkert i ran our project against this revision of prost and all tests are passing lmk if you see anything you want to be different! thanks |
could we merge this already? :P |
Would love to see it merged as well! |
…erate
no_std
codeThe alternative is to get collections types from
core
andalloc
.In the
no_std
mode inprost_build
, we force it to always use BTreeMapsince HashMap was not stabilized in
alloc::collections
library.The functionality is identical and the only incompatibilities in the interface
are that we cannot use
std::error::Error
orstd::io::Error
inno_std
modebecause these types have not been moved to
alloc
and there is no alternative.