-
Notifications
You must be signed in to change notification settings - Fork 223
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
Add no_std feature #138
Add no_std feature #138
Conversation
Thanks for working on this! |
I've added a commit to resolve the incompatible Result types I mentioned above (mapping the The error produced by building that project is the following:
If we look at the type signature of the parent function, we'll see this: // capnpc/src/codegen.rs:1846
pub fn generate_code<T>(mut inp: T, out_dir: &::std::path::Path) -> ::capnp::Result<()>
where T: ::std::io::Read
{ ... } We see that the If this is indeed what's happening, then either I'm missing a configuration option which can separate these dependencies, or it's a use case which cargo isn't equipped to handle at the moment. |
Does it work if you explicitly specify your target when building, e.g. |
It doesn't seem to help. In my example project (atsam4s16b-examples) I tried building using
I also tried building with |
8cdbfdc
to
cbd158d
Compare
I really think this is a conditional compilation problem. I made a post on the users forum to see if anybody has any suggestions. |
So I think I'm going to start playing with a few alternate strategies to see if I can at least get this to a working state. Some things I think I might try:
Which should allow us to pass
I'll post back with progress once I've tried some of these out. |
cbd158d
to
8408ed4
Compare
Hm, it seems that since I think the ideal-world solution would be some sort of "feature negation", but I don't believe that exists right now. For example, previously I had this:
This would only add
I think this is unfortunately an instance where the accommodations for I think I'll push a revert commit and try something else. |
This reverts commit 8408ed4.
I wonder whether it would help if the (I'm sorry that I still haven't gotten around to giving this pull request as in-depth of a review as it deserves...) |
@dwrensha I have just looked into this, and I have a branch for it on bbqsrc/capnproto-rust that takes an approach of providing a minimal subset of the Read and Write traits just to get things building. I note that due to I am now investigating moving the message serialisation functionality into its own crate. It seems possible that if this is achieved, we could have the message serialisation/deserialisation not require |
@dwrensha so a team at @technocreatives will begin working on splitting the serialization infra into a separate crate next week. We'll make a pull request with the outcome. The goal is to make it possible to use the serialization on microcontrollers like NRF52. Hopefully we'll achieve that. 😄 |
Hm. Eliminating the
I wonder how we could achieve this while minimizing the annoyance to people who don't care about
This approach seems promising to me, and much simpler than using |
I'm looking at https://github.com/technocreatives/capnproto-rust/blob/c331b74f8def6ffc7bccdb2991a85adcf8179f95/capnp/src/serialize.rs#L31, which defines #[cfg(not(feature = "std"))]
pub mod io { ... } I wonder whether it would make more sense for this module to be unconditionally included, and to have the |
Not necessarily. There's a few pragmatic options:
Obviously, there'll be some experimentation here, falling back to option 1 if everything else is wrong. 😄
My current idea is that by default
Thanks for reviewing my experiment! I was thinking the same thing. I just did the bare minimum to get this to compile. We'll review this as a team and try to come up with a really good solution |
Hey! I have some unfortunate news. The team assessed the amount of work that it would take for us to become familiar enough with the codebase to successfully separate out the components, and at this stage it would take us longer than a week, so we're no longer pursuing work in this space. Global allocator is still the best option for now. |
This seems like the nicest solution. Was it ever tried? |
Another potential solution to the capnpc problem has come up. Assuming this is the same issue as you are facing here: rust-lang/cargo#2589 A more capable dependency resolver was added to cargo to address the problem: rust-lang/cargo#7820 |
Thanks for the links, @CameronNemo. I think for now it's probably acceptable for I'm still skeptical of I still like the plan I outlined in #138 (comment). That is, the impl capnp::Read for T where T: std::io::Read { ... }
impl capnp::Write for T where T: std::io::Write { ... } |
I've opened a new pull request for no-std support: #184. I'd be curious to hear anyone's thoughts on it. I'm aiming to include this change in a 0.13 release in about two weeks, once rustc 1.44 is out and we can use |
#184 has landed, incorporating many of the ideas brought up by @nicholastmosher, @bbqsrc, and others. Thanks for the pull request and discussion! Please open new issues if there are any problems. |
And note that with #184, |
Hey there! I've been wanting to have capnproto-rust available on no_std for awhile (per #71), and I've given it a few shots in the past but I think now I'm actually pretty close to nailing it. I wanted to open up a PR to get some feedback on my approach and ask some questions about things I've gotten hung up on.
Things I've done:
no_std
feature flag to thecapnp
crate. This feature is used in a few#[cfg(...)]
conditional compilations around the codebase.core_io
crate as an optional dependency to be included when theno_std
feature flag is set. This crate is mostly autogenerated in that it applies patches against std::io to take out all std usages and replace them using thealloc
crate.std::
within thecapnp
crate to usecore::
instead. In capnp'slib.rs
file, there is a conditional import based on#[cfg(feature = "no_std")]
. Ifno_std
is enabled, then the namecore::
referencescore_io::
items. Ifno_std
is not enabled, thencore::
referencesstd::
items. A similar strategy handles deciding between e.g.std::string
andalloc::string
and betweenstd::str
andalloc::str
.Problems I'm having now:
It seems that everything in the
capnp
crate is now building properly both whenno_std
is enabled and disabled. However, when I add thecapnpc::CompilerCommand::new().file("schema.capnp").run().unwrap();
buildscript to a no_std project of mine, there's an interesting compilation problem.capnp
needs to be compiled as no_std in order to comply with my no_std application, but since that is the case, the std-compiledcapnpc
seems to now be linking against the no_std-compiledcapnp
, whereas I think it should build a separate instance of capnp (std-compiled) to link against. The problem that this creates is that e.g. incapnpc/src/lib.rs:81: let mut p = command.spawn()?;
, thespawn()
call returns aResult
in which the error type isstd::io::Error
. Typically, when capnp is std-compiled, it would implementFrom<std::io::Error> for capnp::Error
. However, since it is linking against the no_std-compiled version of capnp, the implementation that is actually implemented isFrom<core_io::Error> for capnp::Error
. It seems that I can get around this by simply mapping the error each time capnpc deals with anio::Result
, e.g. like this:There are only perhaps five or so instances of this problem, but I figured I should ask if anybody has any suggestions on a strategy to take. I don't think it makes sense to force the no_std requirements to leak up into capnpc, but I also don't necessarily want to destroy ergonomics by forcing the client to use
map_err
everywhere. I think I'll probably work on adding a commit that does do that, just in order to get a working solution together, but any alternative suggestions are certainly welcome!Edit:
I forgot to mention, since the
core_io
crate is built by applying patches against certain builds of std::io, you'll need a fixed version of nightly rust to build it using theno_std
feature. You should be able to satisfy it using this override which corresponds to the last patch of the core_io crate: