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

restore no_std after diman_lib was split out #77

Merged
merged 9 commits into from
Sep 1, 2024

Conversation

jedbrown
Copy link
Contributor

@jedbrown jedbrown commented Aug 8, 2024

When we added no_std (#60), crates/diman_lib did not yet exist. It's now missing the no_std annotation, which has allowed tests to pass (since the tests are all running for architectures that support std). Rust does not prevent no_std crates from calling crates that use std (this is confusing).

Adding no_std to diman_lib moves the dependency on num-traits into diman_lib and we drop the ratio module when we don't have either std or num-traits-libm (since we need powf for it to work).

I've tested this with --target=nvptx64-nvidia-cuda.

@@ -3,6 +3,8 @@ use core::{
ops::{Div, Mul},
};

use crate::num_traits_reexport::*; // either Float or FloatCore
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a stylistic choice that I have no attachment to. We could instead use Float or FloatCore depending on cfg.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be

#[cfg(feature = "num-traits-libm")]
pub use num_traits::float::Float;

#[cfg(not(feature = "num-traits-libm"))]
pub use num_traits::float::FloatCore;

just to get rid of the warning.

Copy link
Owner

@Tehforsch Tehforsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, not testing no-std after diman_lib was my bad, sorry about that. I didn't realize that one could just use std in dependencies even if the crate is no_std.

Thanks for the fix - from my side this looks good, except for the warning because of the glob import.

crates/diman_lib/Cargo.toml Show resolved Hide resolved
@@ -3,6 +3,8 @@ use core::{
ops::{Div, Mul},
};

use crate::num_traits_reexport::*; // either Float or FloatCore
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be

#[cfg(feature = "num-traits-libm")]
pub use num_traits::float::Float;

#[cfg(not(feature = "num-traits-libm"))]
pub use num_traits::float::FloatCore;

just to get rid of the warning.

jedbrown and others added 4 commits August 15, 2024 21:26
When we added no_std (Tehforsch#60),
crates/diman_lib did not yet exist. It's now missing the no_std
annotation, which has allowed tests to pass (since the tests are all
running for architectures that support std). Rust does not prevent
no_std crates from calling crates that use std (this is confusing).

Adding no_std to diman_lib moves the dependency on num-traits into
diman_lib and we drop the ratio module when we don't have either std or
num-traits-libm (since we need powf for it to work).
These methods are only available when one of these features is enabled.
@Tehforsch
Copy link
Owner

Tehforsch commented Aug 15, 2024

I've fixed a few minor problems that came up and added a no_std build on nvptx64-nvidia-cuda to the CI, to hopefully prevent myself from causing problems like this in the future. Could you just quickly confirm that the new version of this PR works for you? If so I'll merge it and release 0.5.1 containing this and a few other small fixes.

@Tehforsch Tehforsch self-requested a review August 15, 2024 20:39
Copy link
Contributor Author

@jedbrown jedbrown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks. And sorry about the issues in the first version and taking a while to circle back.

Comment on lines +5 to +10
// For some reason, this use statement is never recognized as used
// even when I build the crates with no std, where removing the use
// statement means that powi below cannot be used.
#[allow(unused)]
#[cfg(not(any(feature = "std")))]
use num_traits::float::FloatCore;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minimized version of this issue: rust-lang/rust#127852 (comment)

@Tehforsch
Copy link
Owner

Looks good, thanks. And sorry about the issues in the first version and taking a while to circle back.

No worries!

@Tehforsch Tehforsch merged commit 7db1f67 into Tehforsch:main Sep 1, 2024
3 checks passed
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.

2 participants