From 98bb3be0943920d29889b2200ea0cdb206d4d7a5 Mon Sep 17 00:00:00 2001 From: "M.Amin Rayej" Date: Tue, 19 Sep 2023 01:46:15 +0330 Subject: [PATCH 1/4] ci: fix ci on tokio-1.20.x (#5999) --- .github/workflows/ci.yml | 23 +++++++++++++++-------- Cargo.lock | 38 ++++++++++++++++++++++++++++++++++++++ tokio/src/future/mod.rs | 1 + 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02f083fd9a4..7c3d2d8a8af 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,7 +71,9 @@ jobs: run: rustup update stable - uses: Swatinem/rust-cache@v1 - name: Install cargo-hack - run: cargo install cargo-hack --version 0.5.26 + uses: taiki-e/install-action@v2 + with: + tool: cargo-hack # Run `tokio` with `full` features. This excludes testing utilities which # can alter the runtime behavior of Tokio. @@ -220,7 +222,7 @@ jobs: with: toolchain: ${{ env.rust_nightly }} override: true - - uses: Swatinem/rust-cache@v1 + # - uses: Swatinem/rust-cache@v1 -> CI failure observed due to insufficient storage space - name: asan run: cargo test --workspace --all-features --target x86_64-unknown-linux-gnu --tests -- --test-threads 1 env: @@ -274,7 +276,9 @@ jobs: override: true - uses: Swatinem/rust-cache@v1 - name: Install cargo-hack - run: cargo install cargo-hack --version 0.5.26 + uses: taiki-e/install-action@v2 + with: + tool: cargo-hack - name: check --each-feature run: cargo hack check --all --each-feature -Z avoid-dev-deps # Try with unstable feature flags @@ -310,7 +314,9 @@ jobs: override: true - uses: Swatinem/rust-cache@v1 - name: Install cargo-hack - run: cargo install cargo-hack --version 0.5.26 + uses: taiki-e/install-action@v2 + with: + tool: cargo-hack - name: "check --all-features -Z minimal-versions" run: | # Remove dev-dependencies from Cargo.toml to prevent the next `cargo update` @@ -408,10 +414,10 @@ jobs: - macos-latest steps: - uses: actions/checkout@v3 - - name: Install Rust ${{ env.rust_stable }} + - name: Install Rust 1.65.0 uses: actions-rs/toolchain@v1 with: - toolchain: ${{ env.rust_stable }} + toolchain: 1.65.0 override: true - uses: Swatinem/rust-cache@v1 - name: Test hyper @@ -462,8 +468,9 @@ jobs: # Install dependencies - name: Install cargo-hack - run: cargo install cargo-hack - + uses: taiki-e/install-action@v2 + with: + tool: cargo-hack - name: Install wasm32-wasi target run: rustup target add wasm32-wasi diff --git a/Cargo.lock b/Cargo.lock index 85d35ddc504..2bfbb9db7eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,44 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "quote" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5907a1b7c277254a8b15170f6e7c97cfa60ee7872a3217663bb81151e48184bb" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "proc-macro2" +version = "1.0.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92de25114670a878b1261c79c9f8f729fb97e95bac93f6312f583c60dd6a1dfe" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" +dependencies = [ + "autocfg", + "cfg-if", + "fastrand", + "redox_syscall", + "rustix", + "windows-sys", +] + [[package]] name = "predicates" version = "1.0.8" diff --git a/tokio/src/future/mod.rs b/tokio/src/future/mod.rs index 084ddc571f5..7c883eb3c34 100644 --- a/tokio/src/future/mod.rs +++ b/tokio/src/future/mod.rs @@ -20,6 +20,7 @@ cfg_sync! { cfg_trace! { mod trace; + #[allow(unused_imports)] pub(crate) use trace::InstrumentedFuture as Future; } From bfa9ea8d9b4cee3d3b7a9222ae4987cbd6c7d6b2 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Sun, 19 Mar 2023 11:49:19 +0100 Subject: [PATCH 2/4] io: use memchr from libc (#5960) --- tokio/Cargo.toml | 3 +- tokio/src/io/util/read_until.rs | 1 + tokio/src/util/memchr.rs | 74 +++++++++++++++++++++++++++++++++ tokio/src/util/mod.rs | 3 ++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 tokio/src/util/memchr.rs diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index e63c09f854d..b9e5934b442 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -42,7 +42,7 @@ full = [ ] fs = [] -io-util = ["memchr", "bytes"] +io-util = ["bytes"] # stdin, stdout, stderr io-std = [] macros = ["tokio-macros"] @@ -108,7 +108,6 @@ pin-project-lite = "0.2.0" # Everything else is optional... bytes = { version = "1.0.0", optional = true } -memchr = { version = "2.2", optional = true } mio = { version = "0.8.1", optional = true, default-features = false } socket2 = { version = "0.4.4", optional = true, features = [ "all" ] } num_cpus = { version = "1.8.0", optional = true } diff --git a/tokio/src/io/util/read_until.rs b/tokio/src/io/util/read_until.rs index 90a0e8a18d5..fb6fb22d9f1 100644 --- a/tokio/src/io/util/read_until.rs +++ b/tokio/src/io/util/read_until.rs @@ -1,4 +1,5 @@ use crate::io::AsyncBufRead; +use crate::util::memchr; use pin_project_lite::pin_project; use std::future::Future; diff --git a/tokio/src/util/memchr.rs b/tokio/src/util/memchr.rs new file mode 100644 index 00000000000..44fd2da3719 --- /dev/null +++ b/tokio/src/util/memchr.rs @@ -0,0 +1,74 @@ +//! Search for a byte in a byte array using libc. +//! +//! When nothing pulls in libc, then just use a trivial implementation. Note +//! that we only depend on libc on unix. + +#[cfg(not(all(unix, feature = "libc")))] +pub(crate) fn memchr(needle: u8, haystack: &[u8]) -> Option { + haystack.iter().position(|val| needle == *val) +} + +#[cfg(all(unix, feature = "libc"))] +pub(crate) fn memchr(needle: u8, haystack: &[u8]) -> Option { + let start = haystack.as_ptr(); + + // SAFETY: `start` is valid for `haystack.len()` bytes. + let ptr = unsafe { libc::memchr(start.cast(), needle as _, haystack.len()) }; + + if ptr.is_null() { + None + } else { + Some(ptr as usize - start as usize) + } +} + +#[cfg(test)] +mod tests { + use super::memchr; + + #[test] + fn memchr_test() { + let haystack = b"123abc456\0\xffabc\n"; + + assert_eq!(memchr(b'1', haystack), Some(0)); + assert_eq!(memchr(b'2', haystack), Some(1)); + assert_eq!(memchr(b'3', haystack), Some(2)); + assert_eq!(memchr(b'4', haystack), Some(6)); + assert_eq!(memchr(b'5', haystack), Some(7)); + assert_eq!(memchr(b'6', haystack), Some(8)); + assert_eq!(memchr(b'7', haystack), None); + assert_eq!(memchr(b'a', haystack), Some(3)); + assert_eq!(memchr(b'b', haystack), Some(4)); + assert_eq!(memchr(b'c', haystack), Some(5)); + assert_eq!(memchr(b'd', haystack), None); + assert_eq!(memchr(b'A', haystack), None); + assert_eq!(memchr(0, haystack), Some(9)); + assert_eq!(memchr(0xff, haystack), Some(10)); + assert_eq!(memchr(0xfe, haystack), None); + assert_eq!(memchr(1, haystack), None); + assert_eq!(memchr(b'\n', haystack), Some(14)); + assert_eq!(memchr(b'\r', haystack), None); + } + + #[test] + fn memchr_all() { + let mut arr = Vec::new(); + for b in 0..=255 { + arr.push(b); + } + for b in 0..=255 { + assert_eq!(memchr(b, &arr), Some(b as usize)); + } + arr.reverse(); + for b in 0..=255 { + assert_eq!(memchr(b, &arr), Some(255 - b as usize)); + } + } + + #[test] + fn memchr_empty() { + for b in 0..=255 { + assert_eq!(memchr(b, b""), None); + } + } +} diff --git a/tokio/src/util/mod.rs b/tokio/src/util/mod.rs index 0d538c147c2..6f8aa38dbc3 100644 --- a/tokio/src/util/mod.rs +++ b/tokio/src/util/mod.rs @@ -90,3 +90,6 @@ pub use self::rand::thread_rng_n; all(unix, feature = "signal") ))] pub(crate) mod error; + +#[cfg(feature = "io-util")] +pub(crate) mod memchr; From 938c7eb0234b93e491de69c86f5d2a30c8663df7 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Fri, 22 Sep 2023 13:44:00 +0200 Subject: [PATCH 3/4] chore: prepare Tokio v1.20.6 (#6024) --- README.md | 2 +- tokio/CHANGELOG.md | 10 ++++++++++ tokio/Cargo.toml | 2 +- tokio/README.md | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2f7126a770b..47791429999 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Make sure you activated the full features of the tokio crate on Cargo.toml: ```toml [dependencies] -tokio = { version = "1.20.5", features = ["full"] } +tokio = { version = "1.20.6", features = ["full"] } ``` Then, on your main.rs: diff --git a/tokio/CHANGELOG.md b/tokio/CHANGELOG.md index d01d91bab24..f641a1a92d7 100644 --- a/tokio/CHANGELOG.md +++ b/tokio/CHANGELOG.md @@ -1,3 +1,13 @@ +# 1.20.6 (September 22, 2023) + +This is a backport of a change from 1.27.0. + +### Changed + +- io: use `memchr` from `libc` ([#5960]) + +[#5960]: https://github.com/tokio-rs/tokio/pull/5960 + # 1.20.5 (May 28, 2023) Forward ports 1.18.6 changes. diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index b9e5934b442..9ebc10ad8b7 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -6,7 +6,7 @@ name = "tokio" # - README.md # - Update CHANGELOG.md. # - Create "v1.0.x" git tag. -version = "1.20.5" +version = "1.20.6" edition = "2018" rust-version = "1.49" authors = ["Tokio Contributors "] diff --git a/tokio/README.md b/tokio/README.md index 2f7126a770b..47791429999 100644 --- a/tokio/README.md +++ b/tokio/README.md @@ -56,7 +56,7 @@ Make sure you activated the full features of the tokio crate on Cargo.toml: ```toml [dependencies] -tokio = { version = "1.20.5", features = ["full"] } +tokio = { version = "1.20.6", features = ["full"] } ``` Then, on your main.rs: From 9ab4ca68ac0016923ca13736f7066fb3c7527308 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Fri, 22 Sep 2023 18:28:38 +0200 Subject: [PATCH 4/4] chore: prepare Tokio v1.25.2 (#6026) --- README.md | 2 +- tokio/CHANGELOG.md | 10 ++++++++++ tokio/Cargo.toml | 2 +- tokio/README.md | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 659a69c8afc..b63b781701a 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Make sure you activated the full features of the tokio crate on Cargo.toml: ```toml [dependencies] -tokio = { version = "1.25.1", features = ["full"] } +tokio = { version = "1.25.2", features = ["full"] } ``` Then, on your main.rs: diff --git a/tokio/CHANGELOG.md b/tokio/CHANGELOG.md index 2cac89ee427..b5cf019f50a 100644 --- a/tokio/CHANGELOG.md +++ b/tokio/CHANGELOG.md @@ -1,3 +1,13 @@ +# 1.25.2 (September 22, 2023) + +Forward ports 1.20.6 changes. + +### Changed + +- io: use `memchr` from `libc` ([#5960]) + +[#5960]: https://github.com/tokio-rs/tokio/pull/5960 + # 1.25.1 (May 28, 2023) Forward ports 1.18.6 changes. diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index 38da82234ad..a0b3b710415 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -6,7 +6,7 @@ name = "tokio" # - README.md # - Update CHANGELOG.md. # - Create "v1.x.y" git tag. -version = "1.25.1" +version = "1.25.2" edition = "2018" rust-version = "1.49" authors = ["Tokio Contributors "] diff --git a/tokio/README.md b/tokio/README.md index 659a69c8afc..b63b781701a 100644 --- a/tokio/README.md +++ b/tokio/README.md @@ -56,7 +56,7 @@ Make sure you activated the full features of the tokio crate on Cargo.toml: ```toml [dependencies] -tokio = { version = "1.25.1", features = ["full"] } +tokio = { version = "1.25.2", features = ["full"] } ``` Then, on your main.rs: