From badbef66b71a8c2b267dfab293fc261353ef1b65 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 13 Nov 2021 23:46:13 +0100 Subject: [PATCH] feat: make reqwest optional but enabled by default --- ethers-contract/ethers-contract-abigen/Cargo.toml | 5 ++++- ethers-contract/ethers-contract-abigen/src/util.rs | 12 +++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ethers-contract/ethers-contract-abigen/Cargo.toml b/ethers-contract/ethers-contract-abigen/Cargo.toml index 34eddb6617..46c0675913 100644 --- a/ethers-contract/ethers-contract-abigen/Cargo.toml +++ b/ethers-contract/ethers-contract-abigen/Cargo.toml @@ -21,7 +21,7 @@ url = "2.1" serde_json = "1.0.61" serde = { version = "1.0.124", features = ["derive"] } hex = { version = "0.4.2", default-features = false, features = ["std"] } -reqwest = { version = "0.11.3", features = ["blocking"] } +reqwest = { version = "0.11.3", features = ["blocking"] , optional = true } once_cell = "1.8.0" cfg-if = "1.0.0" @@ -29,6 +29,9 @@ cfg-if = "1.0.0" # NOTE: this enables wasm compatibility for getrandom indirectly getrandom = { version = "0.2", features = ["js"] } +[features] +default = ["reqwest"] + [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] diff --git a/ethers-contract/ethers-contract-abigen/src/util.rs b/ethers-contract/ethers-contract-abigen/src/util.rs index 2706352a3d..d7b5fc6086 100644 --- a/ethers-contract/ethers-contract-abigen/src/util.rs +++ b/ethers-contract/ethers-contract-abigen/src/util.rs @@ -1,6 +1,7 @@ use ethers_core::types::Address; use anyhow::{anyhow, Result}; +use cfg_if::cfg_if; use inflector::Inflector; use proc_macro2::{Ident, Literal, Span, TokenStream}; use quote::quote; @@ -69,10 +70,15 @@ where Ok(address_str[2..].parse()?) } -#[cfg(not(target_arch = "wasm32"))] /// Perform an HTTP GET request and return the contents of the response. -pub fn http_get(url: &str) -> Result { - Ok(reqwest::blocking::get(url)?.text()?) +pub fn http_get(_url: &str) -> Result { + cfg_if! { + if #[cfg(any(not(target_arch = "wasm32"), not(features = "reqwest")))]{ + Err(anyhow!("HTTP is unsupported")) + } else { + Ok(reqwest::blocking::get(_url)?.text()?) + } + } } #[cfg(test)]