-
Notifications
You must be signed in to change notification settings - Fork 35
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 no_std? #15
Comments
I theory you are right, zstd could be implemented using none of the std lib. This implementation does use
Iirc this could also be used with only the Dou you have a realworld usecase for |
Inside a wasm blockchain is one example, but I could certainly expect it to be useful in browser contexts - I've not yet had to unzstd something in the browser but I've had to do various other decodings in browser so I think it's just a matter of time before I bump into this in a browser context. |
Right I didn't think about wasm, that is a pretty big thing. If I understand correctly, the only thing that would need to be changed would be the imports of Vec and Hashmap to use the |
At minimum you'd have to replace all Additional challenges:
|
I am a bit sketchy - think there is std wasm and no-std wasm. For std wasm
there might be little to be done.
…On Thu, 1 Jul 2021 at 09:23, CodesInChaos ***@***.***> wrote:
At minimum you'd have to replace all std:: imports by core:: and alloc::.
But it looks like you're using other std features, std::io::Read is a
critical one.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#15 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGEJCEFXTBND6OVMENZFHTTVQQYRANCNFSM4437OJDA>
.
|
Replacing the Hashmap is no problem, it's just used for the dictionary lookup once per zstd stream (and only if a dict is used). I could just make this a Vec or whatever it doesn't really matter for the performance. the std::Error thing should be relatively easy. If I am at that it would probably be worthwhile to convert to something like thiserror. Do you know if it is possible to use thiserror in the context of [no_std] or if it can be applied only conditionally? Making the test use std and make them conditional shouldn't be a big problem. VERBOSE + println! would be better if they were wrapped in a macro anyways. The way it's currently done is a bit ugly. Are the logging macros like info! and warn! a thing in [no_std] environments? |
For the As for the To me the major difficulty is the usage of the |
You are right using the std::io::Read makes it hard to port to no_std. But I really don't want to replace it. Maybe the errorhandling working group will succeed in pushing std::error::Error into libcore at some point? |
Any progress for no_std or wasm? |
Well there is still the issue of std::io::Read/Write being used a lot throughout the codebase. These do not exist in core afaik. I am not really involved in no_std development, so I'd need some help here. Is there some best practice to replace these traits with something more appropriate? If the answer is: we don't use these traits, what API would a no_std user of this crate want, if not Read/Write based? |
I think you could define some simple traits that similar to std::io::Read/Write but could used in no_std. Or just use |
Sure, but I would imagine that the no_std community has some go-to replacement for these traits? Also using the std traits does provide some benefits, so I'd have to conditionally use one or the other trait depending on the std feature which seems complicated. Using Maybe it would be worth to fork this project and see how complicated it would be to just do a no_std version without keeping the benefits of using std and go from there? |
Ok, so I played around with this a little bit. AFAICT the best course of action would be:
Tbh I don't know when and if I will find the motivation to do this. PRs are very much welcome though if you want to attempt this @yjhmelody |
Fine, I will have a try if I have time :). But I have no knowledge about zstd. |
You don't have to, just wanted to let you know :) Actual knowledge about the internals of the zstd format should not be necessary though. |
👋
As far as I know, decoding (and encoding) zstd is in principle a pure CPU operation that does not require any help from the operating system.
As such, it would make sense to me to mark the crate as
#[no_std]
.Pragmatically-speaking, this would mean exposing an API that does not use anything from
std::io
.The existing API (that uses
std::io::Read
) could be put behind anstd
feature-gate, like many crates in the ecosystem do.The text was updated successfully, but these errors were encountered: