Skip to content

Commit

Permalink
Use setup-rust-toolchain
Browse files Browse the repository at this point in the history
Signed-off-by: Yilin Chen <[email protected]>
  • Loading branch information
sticnarf committed Jul 27, 2024
1 parent 7d34536 commit d9a20c6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
19 changes: 16 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,31 @@ on:
branches: master

jobs:
build:
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: "1.39.0"
- name: Build
run: |
cargo build --lib --no-default-features --features=tokio
cargo build --lib --no-default-features --features=tokio,tor
cargo build --lib --no-default-features --features=futures-io
cargo build --lib --no-default-features --features=futures-io,tor
cargo build --lib --all-features
test:
strategy:
matrix:
rust: [stable, beta, nightly]
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ matrix.rust }}
components: clippy
override: true
- name: Clippy
run: |
cargo clippy --all-targets --no-default-features --features=tokio -- -D warnings
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ edition = "2018"
[features]
default = ["tokio"]
tor = []
futures-io = ["dep:futures-io"]

[[example]]
name = "chainproxy"
Expand All @@ -41,4 +40,6 @@ futures-executor = "0.3"
futures-util = { version = "0.3", default-features = false, features = ["io"] }
tokio = { version = "1.0", features = ["io-util", "rt-multi-thread", "net"] }
once_cell = "1.2.0"
smol = "2.0.0"
async-net = "2.0.0"
async-executor = "1.5.0"
async-io = "2.0.0"
23 changes: 14 additions & 9 deletions tests/common/futures_utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use async_net::{unix::UnixStream, TcpListener};
use futures_util::{io::copy, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
use once_cell::sync::OnceCell;
use smol::net::{unix::UnixStream, TcpListener};
use std::{
future::Future,
io::{Read, Write},
Expand All @@ -15,15 +15,18 @@ use tokio_socks::{
Result,
};

static EXECUTOR: async_executor::Executor = async_executor::Executor::new();

pub async fn echo_server() -> Result<()> {
let listener = TcpListener::bind(&SocketAddr::from(([0, 0, 0, 0], 10007))).await?;
loop {
let (stream, _) = listener.accept().await?;
smol::spawn(async move {
let (mut reader, mut writer) = stream.split();
copy(&mut reader, &mut writer).await.unwrap();
})
.detach();
EXECUTOR
.spawn(async move {
let (mut reader, mut writer) = stream.split();
copy(&mut reader, &mut writer).await.unwrap();
})
.detach();
}
}

Expand Down Expand Up @@ -70,19 +73,21 @@ impl Runtime {
F: Future<Output = T> + Send + 'static,
T: Send + 'static,
{
smol::spawn(future).detach();
EXECUTOR.spawn(future).detach();
}

pub fn block_on<F, T>(&self, future: F) -> T
where F: Future<Output = T> {
smol::block_on(future)
async_io::block_on(future)
}
}

pub fn runtime() -> &'static Mutex<Runtime> {
static RUNTIME: OnceCell<Mutex<Runtime>> = OnceCell::new();
RUNTIME.get_or_init(|| {
smol::spawn(async { echo_server().await.expect("Unable to bind") }).detach();
EXECUTOR
.spawn(async { echo_server().await.expect("Unable to bind") })
.detach();
Mutex::new(Runtime)
})
}
Expand Down

0 comments on commit d9a20c6

Please sign in to comment.