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

0.3 backports #2419

Merged
merged 12 commits into from May 7, 2021
127 changes: 59 additions & 68 deletions .github/workflows/ci.yml
Expand Up @@ -43,7 +43,7 @@ jobs:
matrix:
rust:
# This is the minimum Rust version supported by futures-core, futures-io, futures-sink, futures-task, futures-channel.
# When updating this, the reminder to update the minimum required version of `async-await` feature in README.md.
# When updating this, the reminder to update the minimum required version in .clippy.toml.
- 1.36.0
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -74,8 +74,8 @@ jobs:
matrix:
rust:
# This is the minimum Rust version supported by futures, futures-util, futures-macro, futures-executor, futures-test.
# When updating this, the reminder to update the minimum required version of `async-await` feature in README.md.
- 1.37.0
# When updating this, the reminder to update the minimum required version in README.md.
- 1.41.0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -84,6 +84,8 @@ jobs:
- run: cargo +stable install cargo-hack
# remove dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866
- run: cargo hack --remove-dev-deps --workspace
# Check default features
- run: cargo hack build --workspace --ignore-private
# Check no-default-features
- run: cargo hack build --workspace --exclude futures-test --ignore-private --no-default-features
# Check alloc feature
Expand All @@ -95,22 +97,6 @@ jobs:
# Check thread-pool feature (futures, futures-executor)
- run: cargo hack build -p futures -p futures-executor --no-default-features --features std,thread-pool

async-await-msrv:
name: cargo +${{ matrix.rust }} build
strategy:
matrix:
rust:
# This is the minimum Rust version supported by `async-await` feature.
# When updating this, the reminder to update the minimum required version of `async-await` feature in README.md.
- 1.39.0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
- run: cargo +stable install cargo-hack
- run: cargo hack build --workspace --no-dev-deps

build:
name: cargo +${{ matrix.rust }} build
strategy:
Expand Down Expand Up @@ -141,59 +127,41 @@ jobs:
- run: cargo update -Z minimal-versions
- run: cargo build --workspace --all-features

thumbv6m:
name: cargo build --target thumbv6m-none-eabi
no-std:
name: cargo build --target ${{ matrix.target }}
strategy:
matrix:
target:
- thumbv6m-none-eabi
- thumbv7m-none-eabi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: rustup target add thumbv6m-none-eabi
- run: rustup target add ${{ matrix.target }}
- run: cargo install cargo-hack
# remove dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866
- run: cargo hack --remove-dev-deps --workspace
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv6m-none-eabi \
--no-default-features \
--features unstable,cfg-target-has-atomic
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv6m-none-eabi \
--no-default-features \
--features alloc,unstable,cfg-target-has-atomic
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv6m-none-eabi \
--no-default-features \
--features async-await,unstable,cfg-target-has-atomic

thumbv7m:
name: cargo build --target thumbv7m-none-eabi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: rustup target add thumbv7m-none-eabi
- run: cargo install cargo-hack
# remove dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866
- run: cargo hack --remove-dev-deps --workspace
cargo hack build --manifest-path futures/tests/no-std/Cargo.toml \
--each-feature --optional-deps \
--target ${{ matrix.target }}
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv7m-none-eabi \
cargo hack build --workspace --ignore-private \
--exclude futures-test --exclude futures-macro \
--no-default-features \
--features unstable,cfg-target-has-atomic
--target ${{ matrix.target }}
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv7m-none-eabi \
--no-default-features \
--features alloc
cargo hack build --workspace --ignore-private \
--exclude futures-test --exclude futures-macro \
--no-default-features --features alloc --ignore-unknown-features \
--target ${{ matrix.target }}
- run: |
cargo build --manifest-path futures/Cargo.toml \
--target thumbv7m-none-eabi \
--no-default-features \
--features async-await
cargo hack build --workspace --ignore-private \
--exclude futures-test --exclude futures-macro \
--no-default-features --features async-await,alloc --ignore-unknown-features \
--target ${{ matrix.target }}

bench:
name: cargo bench
Expand Down Expand Up @@ -226,6 +194,19 @@ jobs:
--workspace --exclude futures-test \
--features unstable --ignore-unknown-features

# When this job failed, run ci/no_atomic_cas.sh and commit result changes.
# TODO(taiki-e): Ideally, this should be automated using a bot that creates
# PR when failed, but there is no bandwidth to implement it
# right now...
codegen:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: ci/no_atomic_cas.sh
- run: git diff --exit-code

san:
name: cargo test -Z sanitizer=${{ matrix.sanitizer }}
strategy:
Expand All @@ -247,18 +228,28 @@ jobs:
# `--cfg futures_sanitizer`.
RUSTFLAGS: -D warnings -Z sanitizer=${{ matrix.sanitizer }} --cfg futures_sanitizer

clippy:
name: cargo clippy
# This branch no longer actively developed. Most commits to this
# branch are backporting and should not be blocked by clippy.
# clippy:
# name: cargo clippy
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - name: Install Rust and Clippy
# run: |
# toolchain=nightly-$(curl -sSf https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/clippy)
# rustup set profile minimal
# rustup default "$toolchain"
# rustup component add clippy
# - run: cargo clippy --workspace --all-features --all-targets

fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust and Clippy
run: |
toolchain=nightly-$(curl -sSf https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/clippy)
rustup set profile minimal
rustup default "$toolchain"
rustup component add clippy
- run: cargo clippy --workspace --all-features --all-targets
- name: Install Rust
run: rustup update stable && rustup default stable
- run: tools/fmt.sh

docs:
name: cargo doc
Expand Down
1 change: 1 addition & 0 deletions .rustfmt.toml
@@ -1 +1,2 @@
use_small_heuristics = "Max"
edition = "2018"
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -13,6 +13,7 @@ members = [

"futures/tests/macro-tests",
"futures/tests/macro-reexport",
"futures/tests/no-std",

"examples/functional",
"examples/imperative",
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -15,8 +15,8 @@
<img alt="Crates.io" src="https://img.shields.io/crates/v/futures.svg">
</a>

<a href="https://blog.rust-lang.org/2019/11/07/Rust-1.39.0.html">
<img alt="Rustc Version" src="https://img.shields.io/badge/rustc-1.39+-lightgray.svg">
<a href="https://www.rust-lang.org">
<img alt="Rustc Version" src="https://img.shields.io/badge/rustc-1.41+-lightgray.svg">
</a>
</p>

Expand Down Expand Up @@ -48,7 +48,7 @@ Now, you can use futures-rs:
use futures::future::Future;
```

The current futures-rs requires Rust 1.39 or later.
The current futures-rs requires Rust 1.41 or later.

### Feature `std`

Expand Down
23 changes: 23 additions & 0 deletions ci/no_atomic_cas.sh
@@ -0,0 +1,23 @@
#!/bin/bash

set -euo pipefail
IFS=$'\n\t'

cd "$(cd "$(dirname "$0")" && pwd)"/..

file="no_atomic_cas.rs"

{
echo "// This file is @generated by $(basename "$0")."
echo "// It is not intended for manual editing."
echo ""
echo "const NO_ATOMIC_CAS_TARGETS: &[&str] = &["
} >"$file"

for target in $(rustc --print target-list); do
res=$(rustc --print target-spec-json -Z unstable-options --target "$target" \
| jq -r "select(.\"atomic-cas\" == false)")
[[ -z "$res" ]] || echo " \"$target\"," >>"$file"
done

echo "];" >>"$file"
9 changes: 4 additions & 5 deletions futures-channel/Cargo.toml
Expand Up @@ -17,11 +17,10 @@ std = ["alloc", "futures-core/std"]
alloc = ["futures-core/alloc"]
sink = ["futures-sink"]

# Unstable features
# These features are outside of the normal semver guarantees and require the
# `unstable` feature as an explicit opt-in to unstable API.
unstable = ["futures-core/unstable"]
cfg-target-has-atomic = ["futures-core/cfg-target-has-atomic"]
# These features are no longer used.
# TODO: remove in the next major version.
unstable = []
cfg-target-has-atomic = []

[dependencies]
futures-core = { path = "../futures-core", version = "0.3.14", default-features = false }
Expand Down
42 changes: 42 additions & 0 deletions futures-channel/build.rs
@@ -0,0 +1,42 @@
#![warn(rust_2018_idioms, single_use_lifetimes)]

use std::env;

include!("no_atomic_cas.rs");

// The rustc-cfg listed below are considered public API, but it is *unstable*
// and outside of the normal semver guarantees:
//
// - `futures_no_atomic_cas`
// Assume the target does not have atomic CAS (compare-and-swap).
// This is usually detected automatically by the build script, but you may
// need to enable it manually when building for custom targets or using
// non-cargo build systems that don't run the build script.
//
// With the exceptions mentioned above, the rustc-cfg strings below are
// *not* public API. Please let us know by opening a GitHub issue if your build
// environment requires some way to enable these cfgs other than by executing
// our build script.
fn main() {
let target = match env::var("TARGET") {
Ok(target) => target,
Err(e) => {
println!(
"cargo:warning={}: unable to get TARGET environment variable: {}",
env!("CARGO_PKG_NAME"),
e
);
return;
}
};

// Note that this is `no_*`, not `has_*`. This allows treating
// `cfg(target_has_atomic = "ptr")` as true when the build script doesn't
// run. This is needed for compatibility with non-cargo build systems that
// don't run the build script.
if NO_ATOMIC_CAS_TARGETS.contains(&&*target) {
println!("cargo:rustc-cfg=futures_no_atomic_cas");
}

println!("cargo:rerun-if-changed=no_atomic_cas.rs");
}
1 change: 1 addition & 0 deletions futures-channel/no_atomic_cas.rs
6 changes: 1 addition & 5 deletions futures-channel/src/lib.rs
Expand Up @@ -11,20 +11,16 @@
//! All items are only available when the `std` or `alloc` feature of this
//! library is activated, and it is activated by default.

#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
// It cannot be included in the published code because this lints have false positives in the minimum required version.
#![cfg_attr(test, warn(single_use_lifetimes))]
#![warn(clippy::all)]
#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]

#[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))]
compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features");

macro_rules! cfg_target_has_atomic {
($($item:item)*) => {$(
#[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
#[cfg(not(futures_no_atomic_cas))]
$item
)*};
}
Expand Down
7 changes: 2 additions & 5 deletions futures-channel/src/lock.rs
Expand Up @@ -6,8 +6,8 @@

use core::cell::UnsafeCell;
use core::ops::{Deref, DerefMut};
use core::sync::atomic::Ordering::SeqCst;
use core::sync::atomic::AtomicBool;
use core::sync::atomic::Ordering::SeqCst;

/// A "mutex" around a value, similar to `std::sync::Mutex<T>`.
///
Expand Down Expand Up @@ -37,10 +37,7 @@ unsafe impl<T: Send> Sync for Lock<T> {}
impl<T> Lock<T> {
/// Creates a new lock around the given value.
pub(crate) fn new(t: T) -> Self {
Self {
locked: AtomicBool::new(false),
data: UnsafeCell::new(t),
}
Self { locked: AtomicBool::new(false), data: UnsafeCell::new(t) }
}

/// Attempts to acquire this lock, returning whether the lock was acquired or
Expand Down