Help enabling `no-std` feature in a crate

Hi :slight_smile:

I got a crate:

that depends of the num crate:

and i want enable a feature in my crate for compile in a no-std environment, for this in the Cargo.toml I have:

num = { version = "0.4", default-features = false}

no-std = ["num/libm"]
default = ["num/std"]

also in

#![cfg_attr(all(feature = "no-std"), no_std)]

this seems to work fine, but testing in a non-std environment I have an error, for example in the following test repo:

i have:

path = "/home/elsuizo/Repos/static-math"
features = ["no-std"]

with the following error:

  --> /home/elsuizo/.cargo/registry/src/
21 | extern crate std;
   | ^^^^^^^^^^^^^^^^^ can't find crate
   = note: the `thumbv7em-none-eabihf` target may not be installed

looking in that lines of code in the num-traits repo:

#[cfg(feature = "std")]
extern crate std;

It seems to not have the flag properly enabled, but I don't know more to try. Any help is welcome. Thanks in advance

It’s better to have an std feature that enables std, and make it a default feature.

1 Like

This leaves the default features of static-math enabled, which in turn enables std in num.

1 Like

yeah!!! the correct declaration was: :blush:

default-features = false
path = "/home/elsuizo/Repos/static-math"
features = ["no-std"]

this is correctly specified in the documentation:

Note: This may not ensure the default features are disabled. If another dependency includes flate2 without specifying default-features = false, then the default features will be enabled. See feature unification below for more details.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.