-
Notifications
You must be signed in to change notification settings - Fork 667
Add no_std
Support
#2462
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?
Add no_std
Support
#2462
Conversation
Brings support for `core::error::Error`
Included in all relevant existing features
Simplifies access to floating point operations in `no_std` contexts.
Highlights when `std` is being used when it doesn't have to be.
Testing against `wasm32v1-none` as a target which is known to not have an implementation of `std`, making compilation a sufficient test for general `no_std` compatibility.
`no-default-features` is separately checked using Clippy
This reverts commit a4f65ef.
Confirmed with |
Verified with `cargo semver-checks check-release --default-features`
Thanks for putting this together! Seeing how much of the crate works with no_std (including Figuring out how to replace As for breaking changes, the plan is for the next major release to be 1.0. We're tracking all the possible/planned changes for that release in #2245. |
Exactly my opinion. I've helped add
I have been experimenting with this issue, and I think there are two paths forward:
I personally think path 1 is the more viable option as it'd keep both internal and external usage of
This would be the ideal, completely agree. But I'm not sure how far away that future is at this point.
Oh well that's good timing! Adding an |
color_quant/#24 adds |
Only works on `no_std` platforms once `color_quant` itself is `no_std`
This is a very big topic so it probably warrants its own thread. Depending on the details, it could require simultaneous breaking changes across a dozen or more crates, many of which aren't controlled by |
Since you've done the std transform in many crates, one central question is how are we to maintain this? As in how does this affect the ability to accept patches and new features.
|
Excellent question. The aspirational solution here is to make the Since the only way to use
Right now, any non-compliant dependencies (including transitively) will be caught at compile time in CI without exception.
After experimenting I do agree that the trait would probably need to be sealed (or potentially marked
It can be a zero-cost option pretty easily. I created
In my experience, no.
I would say that if this is a concern, the normal feature guidelines apply; as long as features are truly additive testing shouldn't be too onerous. |
Absolutely on both fronts. The |
As a proof-of-concept for wider I think the clearest path forward at this point would be to use the same technique employed by This is based on |
I think looking at the QOI codec might give a false impression of the work involved in moving encoding/decoding over to no_std. Others are far more complicated. The TIFF and WebP decoders do a bunch of seeking around the file. The png and tiff crates rely on QOI, by constrast, is a comparatively simple format and already exposes a no_std interface. And if you look into the details, they actually have separate implementations for the std::Read decoder and byte-slice decoder. |
If you want to read over That is, I really like the approach of no_sd support bottom up. I'd welcome your eyeballs on reviewing the fitness of |
@HeroicKatora and @fintelia, I've opened image-gif/#200 to not just add |
Objective
Solution
core::error::Error
libm
andstd
features.std
provides access to thestd
crate and is required for most existing features.libm
activatesnum-traits/libm
, allowing for existingf32
/f64
operations to work withoutstd
.expect
rather thanallow
no_std
CI task which checks againstwasm32v1-none
, a typicalno_std
target. This could be replaced with any other official target that does not havestd
.#[cfg(feature = "std")]
to items which requirestd
to items which require full
f32/
f64` support.ImageError
non_exhaustive
to allow feature gatingImageError::IoError
behindstd
. This isn't strictly required, but it ensures features are truly additive.num_traits::Float
ornum_traits::float::FloatCore
where required forf32
/f64
operations.Notes
no_std
support to any of the format features, as that will require careful consideration around how to decouple fromstd::io
. For example,ciborium-io
(or an equivalent trait local toimage
) could be used as ano_std
-specific feature.core::error::Error
. Instead of the increase, a feature could be added to enable usage ofcore::error::Error
. I opted to just increase MSRV for simplicity. 1.70 to 1.81 isn't too large of a jump IMO.bmp
format looks to be the easiest to make work onno_std
(almost easy enough to consider including in this PR if it wasn't for the open ended nature of how to handle a replacement forstd::io::Write/Read
). That should be the first format to investigate after this PR is potentially merged.