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 for #![no_std]? #251

Closed
mitchmindtree opened this issue Jun 15, 2021 · 3 comments · Fixed by #252
Closed

Support for #![no_std]? #251

mitchmindtree opened this issue Jun 15, 2021 · 3 comments · Fixed by #252
Assignees

Comments

@mitchmindtree
Copy link

Hi there! I'm wondering if there is any interest in support for #![no_std] in noise?

I often come across use cases where I'd like to use noise functions in #![no_std] environments. So far these have included:

  • embedded devices for art installations
  • embedded audio projects
  • rust-gpu shaders
  • writing libraries which aim to support the above

I haven't taken a close look yet to get an idea of how much work would be involved, but I'm curious to get thoughts!

@Razaekel
Copy link
Owner

Razaekel commented Jun 16, 2021

Thank you for the question! I had occasionally wondered about making the library no_std compatible, but never really had the motivation to go do it.

It didn't take too long to hammer it into shape. Check out the no-std branch. It still defaults to including std, so turn off the default features so that it doesn't include std.

@mitchmindtree
Copy link
Author

Nice one, thanks for the quick branch!

I haven't tested the functionality, but depending on the feature/no-std in a downstream no_std crate with default-features = false appears to work nicely 👍

Any chance of seeing this land in 0.7?

@kpreid
Copy link

kpreid commented Aug 13, 2021

It looks like noise is still indirectly depending on std, through the default features of rand and num-traits. Disabling those default features and building on a std-less target (cargo check --target thumbv6m-none-eabi) reveals further constraints:

  • The version of rand needs to be upgraded or it will depend on std via getrandom even with default features off.
  • num_traits::Float and num_traits::Real don't exist without std; num_traits::float::FloatCore is mostly an adequate replacement.
  • sqrt(), sin() and cos() are not available without std. This could be addressed by disabling certain noise functions and other items (but Worley noise can't be constructed without distance_functions::euclidean, which uses sqrt), or the libm crate offers software replacements that could be used.
  • Floats don't implement num_traits::MulAdd. Some of the conditionals for target_os = "emscripten" already help with this if modified to also cover not(feature = "std").

As you might imagine from the length of this list, I gave fixing them a try, but there's it's not a strictly backwards compatible change, so I thought I'd provide this report and ask whether I should send PRs with the incomplete but straightforward parts.

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

Successfully merging a pull request may close this issue.

3 participants