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

Making std optional. #260

Closed
wants to merge 3 commits into from
Closed

Making std optional. #260

wants to merge 3 commits into from

Conversation

lvella
Copy link

@lvella lvella commented Jul 7, 2023

This PR creates a new cargo feature std, on by default, that can be disabled if the user wants to target an environment with no support for std library.

Motivation

Crate is now supported in a larger number of targets, and is a step into fixing this issue: bluealloy/revm#493.

Solution

This crate doesn't really use any std feature (e.g., threads, IO, file, network). It is a pure computation library, and theoretically it could be pure #![no_std] with no need for a feature to enable "std". But unfortunately I hit into two issues:

  • The fact that thiserror is currently std-only (no_std support on nightly dtolnay/thiserror#211), and the solution to make thiserror no_std depends on a unstable rust feature (Tracking Issue for Error in core rust-lang/rust#103765).
  • Some floating point functions are only available in std (like log2, abs, pow, etc), this is an issue of LLVM relying on the system libraries implementation for these functions. This also happens with memcpy and integer division functions, which LLVM assumes to exist, and is solved by including these functions in compiler_builtins library that can be used by no_std projects. For some reason, the corresponding floating point functions are not in compiler_builtins yet (Tracking issue for f32 and f64 methods in libcore rust-lang/rust#50145). Thus, when std is disabled, this PR disables modules log, pow and root, along with From<f64> and From<f32> implementations, all which relies on the missing floating point functions.

PR Checklist

  • [?] Added Tests
  • [✓] Added Documentation
  • [✓] Updated the changelog

@lvella lvella requested a review from prestwich as a code owner July 7, 2023 15:34
@prestwich
Copy link
Collaborator

The fact that thiserror is currently std-only (dtolnay/thiserror#211), and the solution to make thiserror no_std depends on a unstable rust feature (rust-lang/rust#103765).

Yes, you can't use thiserror, you have to implement core::fmt::Display manually, and then std::error::Error behind a cfg flag. It's a bit of a pain but not so bad.

@Wizdave97
Copy link

The fact that thiserror is currently std-only (dtolnay/thiserror#211), and the solution to make thiserror no_std depends on a unstable rust feature (rust-lang/rust#103765).

Yes, you can't use thiserror, you have to implement core::fmt::Display manually, and then std::error::Error behind a cfg flag. It's a bit of a pain but not so bad.

@lvella @prestwich mind if I finish this up since we need it urgently on our end

@DaniPopes DaniPopes mentioned this pull request Jul 27, 2023
3 tasks
@gakonst
Copy link
Collaborator

gakonst commented Jul 27, 2023

Superseded in #274, we'll get it done today. Thank you.

@gakonst gakonst closed this Jul 27, 2023
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 this pull request may close these issues.

4 participants