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

If the std and no_std features are enabled at the same time the crate fails to compile #22

Open
JSorngard opened this issue Oct 11, 2024 · 4 comments

Comments

@JSorngard
Copy link
Contributor

JSorngard commented Oct 11, 2024

This can be seen by running cargo test -F std,no_std.

This is a problem since if a crate depends on crates A and B that in turn depend on special, and A uses special/std and B uses special/no_std the crate will fail to compile since the compiler assumes that features are additive and will only compile a single version of special with both features enabled.

@IvanUkhov
Copy link
Member

Yes. One has to be careful to keep on propagating the features in dependent crates to leave the choice up to the end user.

@IvanUkhov
Copy link
Member

One could perhaps do the same as what you did in lambert_w:

https://github.com/JSorngard/lambert_w/blob/main/src/elementary.rs#L33

It will favor one over the other if both are enabled. I am just not sure which one should get priority. Spontaneously, I would see that portability (no_std) should take precedence over speed (std).

@JSorngard
Copy link
Contributor Author

JSorngard commented Dec 12, 2024

Yes, it's really tricky!
I think the reason I made std take precendence in lambert_w is because if a crate has two different dependencies that in turn depend on lambert_w, and one of them has enabled the std feature (which is disabled by default), that dependency is most likely not no_std compatible anyway, and so letting no_std take precendence in that situation wont make the crate no_std compatible in turn.

@IvanUkhov
Copy link
Member

Hm, that is a good point! I have changed my mind.

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

No branches or pull requests

2 participants