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

Support no_std #19

Closed
LegNeato opened this issue Dec 18, 2023 · 6 comments
Closed

Support no_std #19

LegNeato opened this issue Dec 18, 2023 · 6 comments

Comments

@LegNeato
Copy link

LegNeato commented Dec 18, 2023

For embedded and rust-gpu, it would be nice to have std be an optional feature that is turned on by default.

I'm not sure if this is possible / how much standard is needed but from a high level it appears to be a lot of math and lookup tables.

@grim7reaper
Copy link
Contributor

Agreed

That's something I wanted to do at the beginning but then left on the side due to lack of time.

Outside of the geometry-related algorithms (which relies on collections and memory allocation) it should be relatively straightforward indeed.

For some functions maybe we could propose an alternative API where the caller provides preallocated memory (which is the API of the C implementation).

@LegNeato
Copy link
Author

LegNeato commented Jan 1, 2024

FWIW I poked at this a bit and found and fixed an issue with a dep on no_std:

carbotaniuman/auto_ops#17

Not sure I'll have time to go all the way though.

@grim7reaper
Copy link
Contributor

grim7reaper commented Jan 2, 2024

Thanks.

Any help is appreciated, and even if you don't have time to go through everything, I'll pick it up eventually 🙂

I should have some spare time in the upcoming months, so I'll probably look either at that and/or at the new polyfill algo they implemented recently (I'm curious to see how it performs compared to my optimized version of the current algo)

@grim7reaper
Copy link
Contributor

Little update: I have a working no_std version 😀
100% of the core library is available, but the optional geo feature still requires std (as I expected).
It may be possible to lift this restriction in the future, but that's a way bigger task as it involves either having a no_std version of the Rust geo library (or re-implementing the subset of functions I need, but I would rather avoid this...).

The code still need a little bit of cleanup & documentation, but it's looking good 🙂
It will likely land in the following weeks.

And about that:

it appears to be a lot of math

Surprisingly enough, this proved to be an hindrance 😅

@LegNeato
Copy link
Author

Wow, that was quick!

@grim7reaper
Copy link
Contributor

Yay, on one hand it was way easier than expected (thanks to the alloc crate mainly).

On the other hand, the lack of math functions in core was unexpected and added some extra roundabouts.

grim7reaper added a commit that referenced this issue Jan 28, 2024
How it was done
===============

First step was to replace the references to the `std` crate by `core` or
`alloc` when possible.
Which was always the case, except for the `Error` trait which isn't
available in `core` on stable[1].

Another change, that may impact the performance a bit, was to replace
the usage of Hash{Map,Set} by the B-Tree variant, since the hash-based
one aren't available in core (due to a lack of a secure random number
generator).
There should be no visible impact on default build, since we're still
using hashtable when `std` is enabled (which is the default behavior).
Maybe I should give a shot to `hashbrown` to bring back the hashtable
version into `no-std` as well.

The last change was a bit more annoying (and surprising): most of the
math functions aren't available in core[2].
So I've implemented a fallback using `libm` when `std` isn't enabled.
Note that due to Cargo limitation[3] `libm` is always pulled as a
dependency, but it won't be linked unless necessary thanks to
conditional compilation.

Known limitations
================

Cannot use the `geo` feature without `std`, mainly because the `geo`
crate itself isn't `no-std` (as well as a bunch of its dependencies I
guess).

--------

[1]: rust-lang/rust#103765
[2]: rust-lang/rfcs#2505
[3]: rust-lang/cargo#1839

Closes: #19
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

2 participants