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

Add no-std support #6

Merged
merged 1 commit into from Feb 22, 2023
Merged

Add no-std support #6

merged 1 commit into from Feb 22, 2023

Conversation

danieldg
Copy link
Owner

Fixes #5.

@kesyog, please test this before I release 0.4.4 with it.

@kesyog
Copy link

kesyog commented Feb 21, 2023

Hey, thanks for looking at this so quickly. I took a quick look at the PR and left some comments around the feature flag definition.

Cargo.toml Outdated
@@ -15,6 +15,10 @@ categories = ["rust-patterns", "memory-management"]

[features]
unpin = []
no-std = ['dep:critical-section']
Copy link

Choose a reason for hiding this comment

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

Rather than adding a no-std feature, you should add an std feature and make it a default.

From https://doc.rust-lang.org/cargo/reference/features.html#feature-unification:

If you want to optionally support no_std environments, do not use a no_std feature. Instead, use a std feature that enables std.

An example: https://github.com/matklad/once_cell/blob/master/Cargo.toml

This would allow you to make unpin dependent on std. Right now, enabling both unpin and no-std wouldn't work.

Copy link
Owner Author

Choose a reason for hiding this comment

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

This does not work: you cannot enable a dependency based on the lack of a feature. Renaming the feature to critical-section might be better, however.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Right now, enabling both unpin and no-std wouldn't work.

This actually does work, but demonstrates why the name no-std is misleading: the normal types will continue to use critical-section Mutexes, and the unpin module is also available.

Copy link

Choose a reason for hiding this comment

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

I meant that it wouldn't work because unpin contains std types, but it looks good to me now that unpin depends on std

src/lib.rs Show resolved Hide resolved
@danieldg danieldg force-pushed the no-std branch 2 times, most recently from 127b41e to 1eda4f5 Compare February 22, 2023 00:09
This allows running in a no_std environment.
@kesyog
Copy link

kesyog commented Feb 22, 2023

I didn't do any functional testing but I read through the code and checked that I could build for a no-std target for a test project with:

[dependencies.async-once-cell]
  git = "https://github.com/danieldg/async-once-cell"
  branch = "no-std"
  default-features = false
  features = ["critical-section"]

@danieldg danieldg merged commit 8137239 into master Feb 22, 2023
@danieldg danieldg deleted the no-std branch February 22, 2023 23:28
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.

Add no-std compatibility
2 participants