-
Notifications
You must be signed in to change notification settings - Fork 717
no_std tech demo for removing std::io and some std aliases to core/alloc #2137
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
base: main
Are you sure you want to change the base?
no_std tech demo for removing std::io and some std aliases to core/alloc #2137
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2137 +/- ##
==========================================
- Coverage 94.64% 94.63% -0.01%
==========================================
Files 102 102
Lines 23416 23430 +14
==========================================
+ Hits 22161 22172 +11
- Misses 1255 1258 +3 ☔ View full report in Codecov by Sentry. |
So what is the use case for this exactly? Why not use the unbuffered API, which should not depend on |
8000
Well, it is kinda niche I know, but I'm using it with smoltcp under a custom kernel written in Rust. So while I have to run under no_std, I do have ample amount of memory so that buffered APIs are affordable. What is still not affordable is a large kernel size, though, and surprisingly the unbuffered API actually enlarged the kernel binary size compared to buffered API. |
I think it would be interesting to dig into that more. |
Alas, this is just a tech demo showing the possibility of how much work we needed to do to enable the no_std with buffered API, but until rust-lang/rfcs#2262 is moving forward, I would still suggest the following few things: Make our own std::io::Error equivalent, make a minimal shim for Read/Write and isolate more real platform dependent stuff |
Why is a PR to the rustls project the right shape for "just a tech demo"? |
Of course, for discussion and figure out better ways to improve it. Instead of just talking it out as an issue or in the discussion tab (which wasn't enabled), I think setting up the example first would worth much more. |
I made I may be able to make a fork with this kind of support if it is not wanted here. I really like this idea, wonder how much interest there is from the user community. |
I'm not sure this approach is leading to good results. It's been open for some months now and there hasn't been any significant discussion. I would be more inclined to review the current implementation for providing feedback if the commit history were cleaned up and it was passing CI. However, in general for a task that touches a lot of Rustls I'm a little bit skeptical it's the right idea to dive into a specific solution without first articulating the problem clearly and weighing the available options. IME having maintainer buy-in on the problem & solution will make getting an implementation across the line easier. |
Hmm, should I squash them together, or just like you also questioned, maybe get a new approach? I thought this would be the least invasive way to do it since it mostly mapped with the collection semantics in std... For example, What would be your suggestion to have a more balanced way? |
@stevefan1999-personal I noticed that some recent PRs have been proposed & merged with multiple commits. I think it would really help if you could rebase & organize this into a cleaner & more limited number of commits. I suspect this should be a new feature for no-std, in a similar fashion to how hashbrown is supported for no-std. I think it would be ideal if we could find a way to reduce the amount of code vendored from std::io, especially from std::io::Error. I can think of a couple of ideas:
@stevefan1999-personal / @rustls team I really hope to see this finished and not abandoned or closed out. I think this could prove itself to be really nice for no-std. |
I would love to see the continuation of it, but right now my priorities are my company job, and I also got a paper to do. I will try to spend some time on reviving this, but I won't put in much attention and focus into it yet. After all, this PR serves as a selling point convincing rustls team to adopt no-std for buffered API, but it turns out they still aren't interested in it due to the underlying philosophical problem against the use of external crates for standard library, even if it is proven to be very useful in practice. Anyway, right now, it is an impasse with its implied silent treatment from the rustls team. I guess we will have to wait for the Rust standard library team to settle on the core::io and the error issue around it in order to make a move. In that case we can push to the extreme by pressuring std team linking this PR as related issue. I can do this if you want me to. |
This PR serves as a
no_std
tech demo for removing thestd::io
requirement. As a result, manycfg(feature = "std")
attributes, mostly related tostd::io
inclusion, can be removed. This allows the code that assumed buffered I/O to be compiled in ano_std
environment, as an alternative to unbuffered I/O API if available.This is just an initial evaluation, and incorporated some code from
no_std_io
before as a replacement for the standard I/O functionality. However, other alternatives such asembedded-io
exist and could potentially be explored in the future. The choice ofno_std_io
before for this demo was made based on its simplicity and ease of integration, but we're open to considering other options as we further develop this feature.Right now, this has been further simplified and the
no_std_io
requirement has been eliminated, as I re-introduced a bare minimum ofno_std_io
code that is needed for rustls. However, it usesBox<dyn core::error::Error>
to keep custom error, and may also need to change as discussion goes on.It's important to note that this change doesn't affect the existing functionality for environments where
std
is available. While most of the unit tests should theoretically be compatible without std, but they still neededstd
at the moment for extra platform-specific stuff such as Mutex and Filesystem access.My own private test under
std
shows that it works, but it needs a converter shim to convert types that implementsstd::io::Read
andstd::io::Write
torustls::compat::io::Read
andrustls::compat::io::Write
: