Skip to content

Commit

Permalink
Use cfg(target_has_atomic) on no-std targets
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Dec 8, 2023
1 parent 5e35c12 commit 970e088
Show file tree
Hide file tree
Showing 24 changed files with 89 additions and 333 deletions.
36 changes: 0 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,42 +230,6 @@ jobs:
--workspace --exclude futures-test \
--features unstable --ignore-unknown-features
# When this job failed, run ci/no_atomic_cas.sh and commit result changes.
codegen:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: ci/no_atomic_cas.sh
- run: git add -N . && git diff --exit-code
if: github.repository_owner != 'rust-lang' || github.event_name != 'schedule'
- id: diff
run: |
git config user.name "Taiki Endo"
git config user.email "[email protected]"
git add -N .
if ! git diff --exit-code; then
git add .
git commit -m "Update no_atomic_cas.rs"
echo "::set-output name=success::false"
fi
if: github.repository_owner == 'rust-lang' && github.event_name == 'schedule'
- uses: peter-evans/create-pull-request@v5
with:
title: Update no_atomic_cas.rs
body: |
Auto-generated by [create-pull-request][1]
[Please close and immediately reopen this pull request to run CI.][2]
[1]: https://github.com/peter-evans/create-pull-request
[2]: https://github.com/peter-evans/create-pull-request/blob/HEAD/docs/concepts-guidelines.md#workarounds-to-trigger-further-workflow-runs
branch: update-no-atomic-cas-rs
if: github.repository_owner == 'rust-lang' && github.event_name == 'schedule' && steps.diff.outputs.success == 'false'

miri:
name: cargo miri test
runs-on: ubuntu-latest
Expand Down
31 changes: 0 additions & 31 deletions ci/no_atomic_cas.sh

This file was deleted.

41 changes: 0 additions & 41 deletions futures-channel/build.rs

This file was deleted.

1 change: 0 additions & 1 deletion futures-channel/no_atomic_cas.rs

This file was deleted.

8 changes: 4 additions & 4 deletions futures-channel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
#![allow(clippy::arc_with_non_send_sync)] // false positive https://github.com/rust-lang/rust-clippy/issues/11076
#![allow(clippy::needless_pass_by_ref_mut)]

#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
#[cfg(feature = "alloc")]
mod lock;
#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
#[cfg(feature = "std")]
pub mod mpsc;
#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
#[cfg(feature = "alloc")]
pub mod oneshot;
41 changes: 0 additions & 41 deletions futures-core/build.rs

This file was deleted.

1 change: 0 additions & 1 deletion futures-core/no_atomic_cas.rs

This file was deleted.

7 changes: 5 additions & 2 deletions futures-core/src/task/__internal/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#[cfg(any(not(futures_no_atomic_cas), feature = "portable-atomic"))]
#[cfg_attr(target_os = "none", cfg(any(target_has_atomic = "ptr", feature = "portable-atomic")))]
mod atomic_waker;
#[cfg(any(not(futures_no_atomic_cas), feature = "portable-atomic"))]
#[cfg_attr(
target_os = "none",
cfg(any(target_has_atomic = "ptr", feature = "portable-atomic"))
)]
pub use self::atomic_waker::AtomicWaker;
41 changes: 0 additions & 41 deletions futures-task/build.rs

This file was deleted.

1 change: 0 additions & 1 deletion futures-task/no_atomic_cas.rs

This file was deleted.

12 changes: 6 additions & 6 deletions futures-task/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ extern crate alloc;
mod spawn;
pub use crate::spawn::{LocalSpawn, Spawn, SpawnError};

#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
#[cfg(feature = "alloc")]
mod arc_wake;
#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
#[cfg(feature = "alloc")]
pub use crate::arc_wake::ArcWake;

#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
#[cfg(feature = "alloc")]
mod waker;
#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
#[cfg(feature = "alloc")]
pub use crate::waker::waker;

#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
#[cfg(feature = "alloc")]
mod waker_ref;
#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
#[cfg(feature = "alloc")]
pub use crate::waker_ref::{waker_ref, WakerRef};

Expand Down
4 changes: 2 additions & 2 deletions futures-task/src/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ mod if_alloc {
}
}

#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
impl<Sp: ?Sized + Spawn> Spawn for alloc::sync::Arc<Sp> {
fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> {
(**self).spawn_obj(future)
Expand All @@ -179,7 +179,7 @@ mod if_alloc {
}
}

#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
impl<Sp: ?Sized + LocalSpawn> LocalSpawn for alloc::sync::Arc<Sp> {
fn spawn_local_obj(&self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> {
(**self).spawn_local_obj(future)
Expand Down
41 changes: 0 additions & 41 deletions futures-util/build.rs

This file was deleted.

1 change: 0 additions & 1 deletion futures-util/no_atomic_cas.rs

This file was deleted.

15 changes: 8 additions & 7 deletions futures-util/src/future/join_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use core::task::{Context, Poll};

use super::{assert_future, MaybeDone};

#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
use crate::stream::{Collect, FuturesOrdered, StreamExt};

pub(crate) fn iter_pin_mut<T>(slice: Pin<&mut [T]>) -> impl Iterator<Item = Pin<&mut T>> {
Expand All @@ -31,7 +31,7 @@ where
kind: JoinAllKind<F>,
}

#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
pub(crate) const SMALL: usize = 30;

enum JoinAllKind<F>
Expand All @@ -41,7 +41,7 @@ where
Small {
elems: Pin<Box<[MaybeDone<F>]>>,
},
#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
Big {
fut: Collect<FuturesOrdered<F>, Vec<F::Output>>,
},
Expand All @@ -57,7 +57,7 @@ where
JoinAllKind::Small { ref elems } => {
f.debug_struct("JoinAll").field("elems", elems).finish()
}
#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
JoinAllKind::Big { ref fut, .. } => fmt::Debug::fmt(fut, f),
}
}
Expand Down Expand Up @@ -106,15 +106,16 @@ where
{
let iter = iter.into_iter();

#[cfg(futures_no_atomic_cas)]
#[cfg(target_os = "none")]
#[cfg_attr(target_os = "none", cfg(not(target_has_atomic = "ptr")))]
{
let kind =
JoinAllKind::Small { elems: iter.map(MaybeDone::Future).collect::<Box<[_]>>().into() };

assert_future::<Vec<<I::Item as Future>::Output>, _>(JoinAll { kind })
}

#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
{
let kind = match iter.size_hint().1 {
Some(max) if max <= SMALL => JoinAllKind::Small {
Expand Down Expand Up @@ -153,7 +154,7 @@ where
Poll::Pending
}
}
#[cfg(not(futures_no_atomic_cas))]
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
JoinAllKind::Big { fut } => Pin::new(fut).poll(cx),
}
}
Expand Down
Loading

0 comments on commit 970e088

Please sign in to comment.