From 72687e3fde523fe49857763d53262a4409e33a73 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Tue, 30 Jan 2024 21:30:35 +0100 Subject: [PATCH] chore: remove unnecessary dependencies --- Cargo.toml | 60 ++++++++++++----------------- src/artifact_output/configurable.rs | 1 + src/artifacts/bytecode.rs | 2 +- src/artifacts/mod.rs | 1 + src/buildinfo.rs | 1 + src/compile/mod.rs | 19 ++++----- src/compile/project.rs | 1 + src/error.rs | 8 ++-- src/lib.rs | 4 +- src/utils.rs | 9 ++--- 10 files changed, 48 insertions(+), 58 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ff012630..deb2cf0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,59 +26,46 @@ alloy-json-abi = { version = "0.6", features = ["serde_json"] } solang-parser = { version = "=0.3.3", default-features = false } -# serde +cfg-if = "1.0.0" +dirs = "5.0" +dunce = "1.0" +md-5 = "0.10" +memmap2 = "0.9" +once_cell = "1.19" +path-slash = "0.2" +rayon = "1.8" +regex = "1.10" +semver = { version = "1.0", features = ["serde"] } serde = { version = "1", features = ["derive", "rc"] } serde_json = "1.0" - -# tracing -tracing = "0.1.37" - -tiny-keccak = { version = "2.0.2", default-features = false } -md-5 = "0.10.5" - -semver = { version = "1.0", features = ["serde"] } -walkdir = "2.3" -once_cell = "1.18" -regex = "1.9" thiserror = "1.0" -hex = { package = "const-hex", version = "1.6", features = ["hex"] } -yansi = "0.5.1" -dirs = "5.0" -glob = "0.3.1" - -num_cpus = "1.16.0" -dunce = "1.0" -rayon = "1.7" -path-slash = "0.2.1" -cfg-if = "1.0.0" -memmap2 = "0.9.0" +tracing = "0.1" +walkdir = "2.4" +yansi = "0.5" # async futures-util = { version = "0.3", optional = true } -tokio = { version = "1.32", features = ["rt-multi-thread"], optional = true } +tokio = { version = "1.35", features = ["rt-multi-thread"], optional = true } # project-util -tempfile = { version = "3.8.0", optional = true } -fs_extra = { version = "1.3.0", optional = true } +tempfile = { version = "3.9", optional = true } +fs_extra = { version = "1.3", optional = true } rand = { version = "0.8", optional = true } # svm -home = "0.5.5" +home = "0.5" svm = { package = "svm-rs", version = "0.3", default-features = false, optional = true } svm-builds = { package = "svm-rs-builds", version = "0.3", default-features = false, optional = true } -sha2 = { version = "0.10.7", default-features = false, optional = true } +sha2 = { version = "0.10", default-features = false, optional = true } [dev-dependencies] criterion = { version = "0.5", features = ["async_tokio"] } -tracing-subscriber = { version = "0.3.17", default-features = false, features = [ - "env-filter", - "fmt", -] } -rand = "0.8" pretty_assertions = "1" -tempfile = "3.8" +rand = "0.8" serde_path_to_error = "0.1" -tokio = { version = "1.32", features = ["rt-multi-thread", "macros"] } +tempfile = "3.9" +tokio = { version = "1.35", features = ["rt-multi-thread", "macros"] } +tracing-subscriber = { version = "0.3", default-features = false, features = ["env-filter", "fmt"] } [[bench]] name = "compile_many" @@ -104,9 +91,10 @@ default = ["rustls"] full = ["async", "svm-solc"] +# Adds extra `async` methods using `tokio` to some types. async = ["dep:futures-util", "dep:tokio", "tokio/fs", "tokio/process", "tokio/io-util"] +# Enables `svm` to auto-detect and manage `solc` builds. svm-solc = ["dep:svm", "dep:svm-builds", "dep:sha2", "dep:tokio"] - # Utilities for creating and testing project workspaces. project-util = ["dep:tempfile", "dep:fs_extra", "dep:rand"] diff --git a/src/artifact_output/configurable.rs b/src/artifact_output/configurable.rs index 42ac9079..60286aec 100644 --- a/src/artifact_output/configurable.rs +++ b/src/artifact_output/configurable.rs @@ -23,6 +23,7 @@ use crate::{ Artifact, ArtifactOutput, SolcConfig, SolcError, SourceFile, }; use alloy_json_abi::JsonAbi; +use alloy_primitives::hex; use serde::{Deserialize, Serialize}; use std::{borrow::Cow, collections::BTreeMap, fs, path::Path}; diff --git a/src/artifacts/bytecode.rs b/src/artifacts/bytecode.rs index 8287f8d4..6651556c 100644 --- a/src/artifacts/bytecode.rs +++ b/src/artifacts/bytecode.rs @@ -5,7 +5,7 @@ use crate::{ sourcemap::{self, SourceMap, SyntaxError}, utils, }; -use alloy_primitives::{Address, Bytes}; +use alloy_primitives::{hex, Address, Bytes}; use serde::{Deserialize, Serialize, Serializer}; use std::collections::BTreeMap; diff --git a/src/artifacts/mod.rs b/src/artifacts/mod.rs index 609b5896..a130979d 100644 --- a/src/artifacts/mod.rs +++ b/src/artifacts/mod.rs @@ -5,6 +5,7 @@ use crate::{ compile::*, error::SolcIoError, remappings::Remapping, utils, ProjectPathsConfig, SolcError, }; +use alloy_primitives::hex; use md5::Digest; use semver::Version; use serde::{de::Visitor, Deserialize, Deserializer, Serialize, Serializer}; diff --git a/src/buildinfo.rs b/src/buildinfo.rs index ab873552..146e0c8d 100644 --- a/src/buildinfo.rs +++ b/src/buildinfo.rs @@ -1,6 +1,7 @@ //! Represents an entire build use crate::{utils, CompilerInput, CompilerOutput, SolcError}; +use alloy_primitives::hex; use md5::Digest; use semver::Version; use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer}; diff --git a/src/compile/mod.rs b/src/compile/mod.rs index 1b558866..5b93ec7f 100644 --- a/src/compile/mod.rs +++ b/src/compile/mod.rs @@ -12,9 +12,12 @@ use std::{ process::{Command, Output, Stdio}, str::FromStr, }; + pub mod many; + pub mod output; pub use output::{contracts, info, sources}; + pub mod project; /// The name of the `solc` binary on the system @@ -217,16 +220,13 @@ impl Solc { /// - `~/.svm` on unix, if it exists /// - $XDG_DATA_HOME (~/.local/share/svm) if the svm folder does not exist. pub fn svm_home() -> Option { - match home::home_dir().map(|dir| dir.join(".svm")) { - Some(dir) => { - if !dir.exists() { - dirs::data_dir().map(|dir| dir.join("svm")) - } else { - Some(dir) - } + if let Some(home_dir) = home::home_dir() { + let home_dot_svm = home_dir.join(".svm"); + if home_dot_svm.exists() { + return Some(home_dot_svm); } - None => dirs::data_dir().map(|dir| dir.join("svm")), } + dirs::data_dir().map(|dir| dir.join("svm")) } /// Returns the `semver::Version` [svm](https://github.com/roynalnaruto/svm-rs)'s `.global_version` is currently set to. @@ -497,9 +497,10 @@ impl Solc { if checksum_calc == checksum_found { Ok(()) } else { + use alloy_primitives::hex; let expected = hex::encode(checksum_found); let detected = hex::encode(checksum_calc); - warn!(target : "solc", "checksum mismatch for {:?}, expected {}, but found {} for file {:?}", version, expected, detected, version_path); + warn!(target: "solc", "checksum mismatch for {:?}, expected {}, but found {} for file {:?}", version, expected, detected, version_path); Err(SolcError::ChecksumMismatch { version, expected, detected, file: version_path }) } } diff --git a/src/compile/project.rs b/src/compile/project.rs index dc5549f0..95944496 100644 --- a/src/compile/project.rs +++ b/src/compile/project.rs @@ -405,6 +405,7 @@ impl CompilerSources { }; } } + /// Filters out all sources that don't need to be compiled, see [`ArtifactsCache::filter`] fn filtered( self, diff --git a/src/error.rs b/src/error.rs index 14f397d1..9248ff23 100644 --- a/src/error.rs +++ b/src/error.rs @@ -51,9 +51,9 @@ pub enum SolcError { #[error("file cannot be resolved due to mismatch of file name case: {error}.\nFound existing file: {existing_file:?}\nPlease check the case of the import.")] ResolveCaseSensitiveFileName { error: SolcIoError, existing_file: PathBuf }, #[error( - r#"{0}. - --> {1:?} - {2:?}"# + "{0}\n\t\ + --> {1}\n\t\ + {2}" )] FailedResolveImport(Box, PathBuf, PathBuf), #[cfg(feature = "svm-solc")] @@ -61,8 +61,6 @@ pub enum SolcError { SvmError(#[from] svm::SolcVmError), #[error("no contracts found at \"{0}\"")] NoContracts(String), - #[error(transparent)] - PatternError(#[from] glob::PatternError), /// General purpose message. #[error("{0}")] Message(String), diff --git a/src/lib.rs b/src/lib.rs index 8a532d0d..89d53a26 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -845,7 +845,9 @@ impl ProjectBuilder { compiler_severity_filter, allowed_paths, include_paths, - solc_jobs: solc_jobs.unwrap_or_else(num_cpus::get), + solc_jobs: solc_jobs + .or_else(|| std::thread::available_parallelism().ok().map(|n| n.get())) + .unwrap_or(1), offline, slash_paths, }) diff --git a/src/utils.rs b/src/utils.rs index 638a968d..3efed38d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,6 +1,7 @@ //! Utility functions use crate::{error::SolcError, SolcIoError}; +use alloy_primitives::{hex, keccak256}; use cfg_if::cfg_if; use once_cell::sync::Lazy; use regex::{Match, Regex}; @@ -13,7 +14,6 @@ use std::{ ops::Range, path::{Component, Path, PathBuf}, }; -use tiny_keccak::{Hasher, Keccak}; use walkdir::WalkDir; /// A regex that matches the import path and identifier of a solidity import @@ -372,11 +372,8 @@ pub fn library_hash_placeholder(name: impl AsRef<[u8]>) -> String { /// /// See also pub fn library_hash(name: impl AsRef<[u8]>) -> [u8; 17] { - let mut output = [0u8; 17]; - let mut hasher = Keccak::v256(); - hasher.update(name.as_ref()); - hasher.finalize(&mut output); - output + let hash = keccak256(name); + hash[..17].try_into().unwrap() } /// Find the common ancestor, if any, between the given paths