From 3c48e939e04e93cca18d923a94b2af5960a6c786 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Fri, 8 Nov 2019 13:43:52 +0900 Subject: [PATCH 1/5] fix: Use AtomicUsize for TaskId Closes #141 --- .github/workflows/ci.yml | 33 +++++++++++++++++++++++++++++++++ Cargo.toml | 8 +++++++- src/task/task_id.rs | 9 +++++---- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f519e533..1a0c4323b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -110,6 +110,39 @@ jobs: command: check args: --no-default-features --features alloc --target thumbv7m-none-eabi -Z avoid-dev-deps + cross: + name: Cross compile + runs-on: ubuntu-latest + strategy: + matrix: + target: + - i686-unknown-linux-gnu + - powerpc-unknown-linux-gnu + - powerpc64-unknown-linux-gnu + - mips-unknown-linux-gnu + - arm-linux-androideabi + + steps: + - uses: actions/checkout@master + + - name: Install nightly + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + + - name: Install cross + run: cargo install cross + + - name: check + run: cross check --all --target ${{ matrix.target }} + + - name: check unstable + run: cross check --all --features unstable --target ${{ matrix.target }} + + - name: test + run: cross test --all --features unstable --target ${{ matrix.target }} + check_fmt_and_docs: name: Checking fmt and docs runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index db26625bb..e6e810f47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,6 +67,9 @@ pin-project-lite = { version = "0.1.4", optional = true } pin-utils = { version = "0.1.0-alpha.4", optional = true } slab = { version = "0.4.2", optional = true } +# Devdepencency, but they are not allowed to be optional :/ +surf = { version = "1.0.3", optional = true } + [target.'cfg(not(target_os = "unknown"))'.dependencies] smol = { version = "0.1.1", optional = true } @@ -81,7 +84,6 @@ wasm-bindgen-test = "0.3.10" [dev-dependencies] femme = "1.3.0" rand = "0.7.3" -surf = "1.0.3" tempdir = "0.3.7" futures = "0.3.4" rand_xorshift = "0.2.0" @@ -93,3 +95,7 @@ required-features = ["unstable"] [[example]] name = "tcp-ipv4-and-6-echo" required-features = ["unstable"] + +[[example]] +name = "surf-web" +required-features = ["surf"] \ No newline at end of file diff --git a/src/task/task_id.rs b/src/task/task_id.rs index 67eee154b..92c607c71 100644 --- a/src/task/task_id.rs +++ b/src/task/task_id.rs @@ -1,5 +1,5 @@ use std::fmt; -use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::atomic::{AtomicUsize, Ordering}; /// A unique identifier for a task. /// @@ -13,15 +13,16 @@ use std::sync::atomic::{AtomicU64, Ordering}; /// }) /// ``` #[derive(Eq, PartialEq, Clone, Copy, Hash, Debug)] -pub struct TaskId(pub(crate) u64); +pub struct TaskId(pub(crate) usize); impl TaskId { /// Generates a new `TaskId`. pub(crate) fn generate() -> TaskId { - static COUNTER: AtomicU64 = AtomicU64::new(1); + // TODO: find a good version to emulate u64 atomics on 32 bit systems. + static COUNTER: AtomicUsize = AtomicUsize::new(1); let id = COUNTER.fetch_add(1, Ordering::Relaxed); - if id > u64::max_value() / 2 { + if id > usize::max_value() / 2 { std::process::abort(); } TaskId(id) From 76736da5b519cd37415088023c78fa9d598e7411 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Thu, 7 May 2020 22:36:53 +0200 Subject: [PATCH 2/5] test: disable test dependent on stdin for cross --- tests/io_timeout.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/io_timeout.rs b/tests/io_timeout.rs index fa30a68af..4a61078ac 100644 --- a/tests/io_timeout.rs +++ b/tests/io_timeout.rs @@ -5,7 +5,12 @@ use async_std::task; #[test] #[should_panic(expected = "timed out")] -#[cfg(not(target_os = "unknown"))] +#[cfg(not(any( + target_os = "unknown", + target_arch = "arm", + target_arch = "mips", + target_arch = "powerpc" +)))] fn io_timeout_timedout() { task::block_on(async { io::timeout(Duration::from_secs(1), async { From da08f13d221c8a6baf0728700afbb2e63d1258f7 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Thu, 7 May 2020 22:49:20 +0200 Subject: [PATCH 3/5] fixup --- tests/io_timeout.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/io_timeout.rs b/tests/io_timeout.rs index 4a61078ac..147ffd9f1 100644 --- a/tests/io_timeout.rs +++ b/tests/io_timeout.rs @@ -9,8 +9,9 @@ use async_std::task; target_os = "unknown", target_arch = "arm", target_arch = "mips", - target_arch = "powerpc" -)))] + target_arch = "powerpc", + target_arch = "x86", +)))] // stdin tests fail when running through cross fn io_timeout_timedout() { task::block_on(async { io::timeout(Duration::from_secs(1), async { From e3b82d36563ba3d0871d6a119cba338ef7c1d438 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Thu, 7 May 2020 23:00:23 +0200 Subject: [PATCH 4/5] another cross targetg --- tests/io_timeout.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/io_timeout.rs b/tests/io_timeout.rs index 147ffd9f1..371150693 100644 --- a/tests/io_timeout.rs +++ b/tests/io_timeout.rs @@ -10,6 +10,7 @@ use async_std::task; target_arch = "arm", target_arch = "mips", target_arch = "powerpc", + target_arch = "powerpc64", target_arch = "x86", )))] // stdin tests fail when running through cross fn io_timeout_timedout() { From 468bcf7022f4d430e176da64e4c585509cad1e77 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Thu, 7 May 2020 23:09:34 +0200 Subject: [PATCH 5/5] increase timeout duration --- tests/timeout.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/timeout.rs b/tests/timeout.rs index 8ad358a40..e09acdfe4 100644 --- a/tests/timeout.rs +++ b/tests/timeout.rs @@ -12,7 +12,7 @@ fn timeout_future_many() { task::block_on(async { let futures = (0..100) .map(|i| { - timeout(Duration::from_millis(i * 10), async move { + timeout(Duration::from_millis(i * 20), async move { task::sleep(Duration::from_millis(i)).await; Ok::<(), async_std::future::TimeoutError>(()) })