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

Fix no_std build #368

Merged
merged 5 commits into from
May 11, 2019
Merged

Fix no_std build #368

merged 5 commits into from
May 11, 2019

Conversation

taiki-e
Copy link
Member

@taiki-e taiki-e commented Apr 29, 2019

Closes #364


# Check for no_std environment.
cd .. && cargo run --manifest-path ci/Cargo.toml --bin remove-dev-dependencies */Cargo.toml && cd -
cargo check --target thumbv7m-none-eabi --no-default-features
Copy link
Member Author

Choose a reason for hiding this comment

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

If build with Linux as a target, it will link to std, so it need to specify a target that does not have std.

ci/crossbeam-epoch.sh Outdated Show resolved Hide resolved
@Restioson
Copy link

Restioson commented Apr 29, 2019

I see what you've done here & agree that it's a better solution to what I have done (less breakage)... however, I'm not sure how it handles lazy_static. Lazy_static is available for no_std with the spin_no_std feature (which by the way was originally why I changed the feature to no_std).

@taiki-e
Copy link
Member Author

taiki-e commented Apr 29, 2019

AFAIK the current no_std crossbeam does not depend on lazy_tactic.

The crossbeam currently uses lazy_static in two places:

lazy_static! {
static ref THREAD_INDICES: Mutex<ThreadIndices> = Mutex::new(ThreadIndices {
mapping: HashMap::new(),
free_list: Vec::new(),
next_index: 0,
});
}

lazy_static! {
/// The global data for the default garbage collector.
static ref COLLECTOR: Collector = Collector::new();
}

However, these are both in modules that require std. Also, they seem to be used with features not available on no_std.

use std::panic::{RefUnwindSafe, UnwindSafe};
use std::sync::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard};
use std::sync::{LockResult, PoisonError, TryLockError, TryLockResult};
use std::thread::{self, ThreadId};

thread_local! {
/// The per-thread participant for the default garbage collector.
static HANDLE: LocalHandle = COLLECTOR.register();
}

So I don't think crossbeam needs to think about lazy_static's no_std support.

@taiki-e
Copy link
Member Author

taiki-e commented Apr 29, 2019

Also, I believe many crates in the ecosystem (e.g., serde, futures, itertools) support the no_std environment in the same way as the current crossbeam.

lazy_static supports no_std in the other way as these crates, because it adds spin dependency.
(I think it can be solved by using their own Once and providing no_std support with the same way as the current crossbeam. However, I do not know if the lazy_static developer agrees with this. Also, to not break crates that currently use the spin_no_std feature, it needs to do no_std support on both spin_no_std and no-default-features instead of removing spin_no_std immediately, but I think doing this is not very difficult.)


FYI, you can always use the lazy_static/spin_no_std feature or configure the feature to allow users to opt-in like the following:

[dependencies]
lazy_static = { version = "1", optional = true }
[features]
std = ["lazy_static"]
spin_no_std = ["lazy_static/spin_no_std"]

The point to keep in mind when always using the lazy_static/spin_no_std feature is that it has not been tested on older versions than the latest stable (lazy_static, spin).

crossbeam-epoch/src/lib.rs Outdated Show resolved Hide resolved
@Restioson Restioson mentioned this pull request Apr 29, 2019
@Restioson
Copy link

FYI, you can always use the lazy_static/spin_no_std feature or configure the feature to allow users to opt-in like the following:

Yeah I just didn't want to fragment the options.

@ghost
Copy link

ghost commented Apr 29, 2019

@taiki-e This looks great to me, thanks so much! :)

The only thing left to do is to update the readmes -- check out how we're currently explaining which parts of Crossbeam are available with individual features. We should probably also mention the alloc feature there.

@taiki-e taiki-e force-pushed the no-std branch 2 times, most recently from 8045061 to 61e15de Compare May 1, 2019 06:41
@taiki-e
Copy link
Member Author

taiki-e commented May 1, 2019

@stjepang
I updated readmes and I added e3507f9 so that even targets that do not support CAS(compare-and-swap) operations such as thumv6m can be properly compiled. (Although #![cfg_attr(feature = "nightly", feature(cfg_target_has_atomic))] was originally valid for some crates, errors will occur if this configuration is not propagated.)

Cargo.toml Show resolved Hide resolved
crossbeam-epoch/README.md Outdated Show resolved Hide resolved
@ghost
Copy link

ghost commented May 11, 2019

Thanks again, this looks ready for landing now! :)

bors r+

bors bot added a commit that referenced this pull request May 11, 2019
368: Fix no_std build r=stjepang a=taiki-e

Closes #364

Co-authored-by: Taiki Endo <te316e89@gmail.com>
@bors
Copy link
Contributor

bors bot commented May 11, 2019

Build succeeded

@bors bors bot merged commit dd6212a into crossbeam-rs:master May 11, 2019
@taiki-e taiki-e deleted the no-std branch May 11, 2019 19:29
bors bot added a commit that referenced this pull request May 22, 2020
508: Make std feature to depend on alloc feature r=jeehoonkang a=taiki-e

`alloc` crate is available on 1.36, see #368 (comment) for why it was previously separated.

This is a breaking change proposed in #503.

Co-authored-by: Taiki Endo <te316e89@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants