Skip to content
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

no_std support? #4

Open
xobs opened this issue May 4, 2021 · 9 comments
Open

no_std support? #4

xobs opened this issue May 4, 2021 · 9 comments
Assignees

Comments

@xobs
Copy link

xobs commented May 4, 2021

Will this library ever add no_std support?

I ask because it's not in the Non Goals section of the README, yet it does not appear to have any allocations or use any features from libstd.

@dfrg
Copy link
Owner

dfrg commented May 4, 2021

Shaping and scaling unfortunately do require heap allocations due to indeterminate memory requirements or upper bounds that are too large for stack allocation.

That said, the crate could be core+alloc, but certain components of the underlying path engine require floating point intrinsics that are currently unavailable in core. This is a known problem and when it is resolved, I would like to remove the std dependency.

@kirawi
Copy link
Contributor

kirawi commented May 8, 2021

It doesn't seem like there's been any work towards it in the aforementioned issue for ~3 years. It might be worth feature gating it with support for libm or micromath? Not really familiar with this kind of stuff, though. std::io and yazi might still be an issue, but probably solvable with traits.

Edit: Proof of Concept (I won't actually be implementing this, I'm too busy.)

@jackpot51
Copy link
Collaborator

I will be attempting to add this feature.

@jackpot51 jackpot51 self-assigned this Oct 24, 2022
notgull added a commit to forkgull/yazi that referenced this issue Sep 5, 2023
This commit adds a default "std" feature that can be disabled to run
this crate in no_std environments. This allows for Zlib compression or
decompression to happen on embedded systems.

Rel: dfrg/swash#4

This is a breaking change, as anyone who is already importing yazi with
"default-features = false" and using the From<io::Error> impl on
yazi::Error will have their build break after this commit.

Signed-off-by: John Nunley <[email protected]>
notgull added a commit to forkgull/zeno that referenced this issue Sep 5, 2023
This commit adds two new features: "std" (which is enabled by default)
and "libm". When "std" is enabled, floating point intrinsics are used
from libstd. When "libm" is enabled, it brings in the pure Rust libm
implementation to handle floating point instrinsics in software mode.

By disabling the "std" feature and enabling "libm", this crate can be
effectively used on no_std platforms, like embedded systems.

This is a breaking change, as it adds an "std" default feature that,
when disabled without enabling "libm", causes a compile error. Users who
are currently using zeno with "default-features = false" without
preparation will have their compilation break.

Rel: dfrg/swash#4

Signed-off-by: John Nunley <[email protected]>
@lylythechosenone
Copy link

@jackpot51 Are you on this?

It does seem like it'll be a while before math-in-core is stable. I think it would certainly be worth using something like libm in the mean time.

As for std::io, what's the status on that? I know we won't be getting core::io for a long time (mainly due to std::io::Error), so some alternative approach would likely be useful. Assuming it's only used in the loader, I think delegating to an external loader, like rustybuzz and many other crates do, could actually be worthwhile. For example, ttf-parser, which is used in rustybuzz, already supports no_std.

yazi does now support no_std (as seen in this thread).

@notgull
Copy link

notgull commented Feb 20, 2024

I was working on it but got distracted by other things. I can take another crack at it if it's important to you.

@lylythechosenone
Copy link

I was actually thinking about using swash for early console rendering inside of my OS, so I'd love it if you could add support. I can also try to help out with anything, as I have lots of experience with no_std (see said OS).

@dfrg
Copy link
Owner

dfrg commented Feb 21, 2024

Thanks to @notgull, all dependencies should support no_std now. Doing so for swash is mostly grunt work that involves integrating libm and importing alloc::vec::Vec where required. I don’t really have time to do it myself but I’m happy to accept a PR.

@lylythechosenone
Copy link

Something I've seen in a lot of other crates is simply extern crate alloc as std;. This allows you to keep the old code that uses std, and simply switch it out for alloc in no_std.

@lylythechosenone
Copy link

Wow, I totally forgot about this. I'd love to try to get something like that done this week, if the story is still the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants