From f4c89c6cb1038f40b806224ff62b11410dd1b0ee Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 13 Dec 2021 22:25:10 +0100 Subject: [PATCH] ci: test on windows targets (#682) * ci: test on windows targets * make ipc optional * fix: only activate ipc on unix families * add cfg * only check default members * no parallel limits Co-authored-by: Georgios Konstantopoulos --- .github/workflows/ci.yml | 49 +++++++++++++++++++ Cargo.lock | 4 +- Cargo.toml | 4 ++ ethers-providers/Cargo.toml | 2 +- ethers-providers/src/provider.rs | 3 +- ethers-providers/src/transports/ipc.rs | 67 ++++++++------------------ ethers-providers/src/transports/mod.rs | 10 ++-- 7 files changed, 81 insertions(+), 58 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 899b08d3..d9e04466 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -222,3 +222,52 @@ jobs: run: | export PATH=$HOME/bin:$PATH ./scripts/examples.sh + + windows-build: + runs-on: windows-latest + name: (${{ matrix.target }}, ${{ matrix.cfg_release_channel }}) + env: + CFG_RELEASE_CHANNEL: ${{ matrix.cfg_release_channel }} + strategy: + fail-fast: false + matrix: + target: [ + i686-pc-windows-gnu, + i686-pc-windows-msvc, + x86_64-pc-windows-gnu, + x86_64-pc-windows-msvc, + ] + cfg_release_channel: [nightly] + + steps: + - name: checkout + uses: actions/checkout@v2 + + # Run build + - name: Install Rustup using win.rustup.rs + run: | + # disable download progress bar + $ProgressPreference = "SilentlyContinue" + Invoke-WebRequest https://win.rustup.rs/ -OutFile rustup-init.exe + .\rustup-init.exe -y --default-host=x86_64-pc-windows-msvc --default-toolchain=none + del rustup-init.exe + rustup target add ${{ matrix.target }} + shell: powershell + + - name: Add mingw32 to path for i686-gnu + run: | + echo "C:\msys64\mingw32\bin" >> $GITHUB_PATH + if: matrix.target == 'i686-pc-windows-gnu' && matrix.channel == 'nightly' + shell: bash + + - name: Add mingw64 to path for x86_64-gnu + run: echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH + if: matrix.target == 'x86_64-pc-windows-gnu' && matrix.channel == 'nightly' + shell: bash + + - name: build + run: | + rustc -Vv + cargo -V + cargo check --all-features + shell: cmd \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 7ff8ba4a..b6ebb0a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3306,9 +3306,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "svm-rs" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a5e16a3a87cca053bcab26e5de589ccb5779f84dda466f96eead79a98d7de7c" +checksum = "8733662d7e2c4bc2bdc5ca4102c7f8b13d1c3c12fb767089de07c2c3df3cd03d" dependencies = [ "anyhow", "cfg-if 1.0.0", diff --git a/Cargo.toml b/Cargo.toml index 60fa90bd..08804377 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,8 +91,12 @@ ethers-etherscan = { version = "^0.2.0", default-features = false, path = "./eth [dev-dependencies] ethers-contract = { version = "^0.6.0", default-features = false, path = "./ethers-contract", features = ["abigen", "eip712"] } +ethers-providers = { version = "^0.6.0", default-features = false, path = "./ethers-providers", features = ["ws"] } + +[target.'cfg(target_family = "unix")'.dev-dependencies] ethers-providers = { version = "^0.6.0", default-features = false, path = "./ethers-providers", features = ["ws", "ipc"] } + anyhow = "1.0.39" rand = "0.8.4" serde = { version = "1.0.124", features = ["derive"] } diff --git a/ethers-providers/Cargo.toml b/ethers-providers/Cargo.toml index c2d7e164..4cc71f87 100644 --- a/ethers-providers/Cargo.toml +++ b/ethers-providers/Cargo.toml @@ -58,7 +58,7 @@ tokio = { version = "1.5", default-features = false, features = ["rt", "macros"] tempfile = "3.2.0" [features] -default = ["ws", "ipc", "rustls"] +default = ["ws", "rustls"] celo = ["ethers-core/celo"] ws = ["tokio", "tokio-tungstenite"] ipc = ["tokio", "tokio/io-util", "tokio-util", "bytes"] diff --git a/ethers-providers/src/provider.rs b/ethers-providers/src/provider.rs index c4b152ed..d2a3a090 100644 --- a/ethers-providers/src/provider.rs +++ b/ethers-providers/src/provider.rs @@ -949,8 +949,7 @@ impl Provider { } } -#[cfg(not(target_arch = "wasm32"))] -#[cfg(feature = "ipc")] +#[cfg(all(target_family = "unix", feature = "ipc"))] impl Provider { /// Direct connection to an IPC socket. pub async fn connect_ipc(path: impl AsRef) -> Result { diff --git a/ethers-providers/src/transports/ipc.rs b/ethers-providers/src/transports/ipc.rs index ae8d234f..079f0ad9 100644 --- a/ethers-providers/src/transports/ipc.rs +++ b/ethers-providers/src/transports/ipc.rs @@ -10,11 +10,13 @@ use futures_channel::mpsc; use futures_util::stream::{Fuse, StreamExt}; use oneshot::error::RecvError; use serde::{de::DeserializeOwned, Serialize}; -use std::sync::atomic::Ordering; use std::{ collections::HashMap, path::Path, - sync::{atomic::AtomicU64, Arc}, + sync::{ + atomic::{AtomicU64, Ordering}, + Arc, + }, }; use thiserror::Error; use tokio::{ @@ -37,18 +39,9 @@ type Subscription = mpsc::UnboundedSender; #[derive(Debug)] enum TransportMessage { - Request { - id: u64, - request: String, - sender: Pending, - }, - Subscribe { - id: U256, - sink: Subscription, - }, - Unsubscribe { - id: U256, - }, + Request { id: u64, request: String, sender: Pending }, + Subscribe { id: U256, sink: Subscription }, + Unsubscribe { id: U256 }, } impl Ipc { @@ -112,10 +105,7 @@ impl PubsubClient for Ipc { fn subscribe>(&self, id: T) -> Result { let (sink, stream) = mpsc::unbounded(); - self.send(TransportMessage::Subscribe { - id: id.into(), - sink, - })?; + self.send(TransportMessage::Subscribe { id: id.into(), sink })?; Ok(stream) } @@ -157,12 +147,9 @@ where let f = async move { let mut read_buffer = Vec::new(); loop { - let closed = self - .process(&mut read_buffer) - .await - .expect("WS Server panic"); + let closed = self.process(&mut read_buffer).await.expect("WS Server panic"); if closed && self.pending.is_empty() { - break; + break } } }; @@ -197,11 +184,7 @@ where async fn handle_request(&mut self, msg: TransportMessage) -> Result<(), IpcError> { match msg { - TransportMessage::Request { - id, - request, - sender, - } => { + TransportMessage::Request { id, request, sender } => { if self.pending.insert(id, sender).is_some() { warn!("Replacing a pending request with id {:?}", id); } @@ -218,10 +201,7 @@ where } TransportMessage::Unsubscribe { id } => { if self.subscriptions.remove(&id).is_none() { - warn!( - "Unsubscribing from non-existent subscription with id {:?}", - id - ); + warn!("Unsubscribing from non-existent subscription with id {:?}", id); } } }; @@ -287,7 +267,8 @@ where } /// Sends JSON response through the channel based on the ID in that response. - /// This handles RPC calls with only one response, and the channel entry is dropped after sending. + /// This handles RPC calls with only one response, and the channel entry is dropped after + /// sending. fn respond(&mut self, output: Response) -> Result<(), IpcError> { let id = output.id; @@ -338,7 +319,10 @@ impl From for ProviderError { #[cfg(not(feature = "celo"))] mod test { use super::*; - use ethers_core::{utils::Geth, types::{Block, TxHash, U256}}; + use ethers_core::{ + types::{Block, TxHash, U256}, + utils::Geth, + }; use tempfile::NamedTempFile; #[tokio::test] @@ -366,11 +350,7 @@ mod test { // Subscribing requires sending the sub request and then subscribing to // the returned sub_id - let block_num: u64 = ipc - .request::<_, U256>("eth_blockNumber", ()) - .await - .unwrap() - .as_u64(); + let block_num: u64 = ipc.request::<_, U256>("eth_blockNumber", ()).await.unwrap().as_u64(); let mut blocks = Vec::new(); for _ in 0..3 { let item = stream.next().await.unwrap(); @@ -378,13 +358,6 @@ mod test { blocks.push(block.number.unwrap_or_default().as_u64()); } let offset = blocks[0] - block_num; - assert_eq!( - blocks, - &[ - block_num + offset, - block_num + offset + 1, - block_num + offset + 2 - ] - ) + assert_eq!(blocks, &[block_num + offset, block_num + offset + 1, block_num + offset + 2]) } } diff --git a/ethers-providers/src/transports/mod.rs b/ethers-providers/src/transports/mod.rs index bc642c77..d5ef0255 100644 --- a/ethers-providers/src/transports/mod.rs +++ b/ethers-providers/src/transports/mod.rs @@ -16,12 +16,10 @@ macro_rules! if_not_wasm { )*} } -if_not_wasm! { - #[cfg(feature = "ipc")] - mod ipc; - #[cfg(feature = "ipc")] - pub use ipc::Ipc; -} +#[cfg(all(target_family = "unix", feature = "ipc"))] +mod ipc; +#[cfg(all(target_family = "unix", feature = "ipc"))] +pub use ipc::Ipc; mod http; pub use http::{ClientError as HttpClientError, Provider as Http};