Skip to content

Commit

Permalink
chore: remove unnecessary dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Jan 30, 2024
1 parent bd3dd65 commit 8ac8dca
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 59 deletions.
63 changes: 26 additions & 37 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,64 +21,52 @@ rustdoc-args = ["--cfg", "docsrs"]
all-features = true

[dependencies]
alloy-primitives = { version = "0.6", features = ["serde", "rand"] }
alloy-primitives = { version = "0.6", features = ["serde"] }
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]
alloy-primitives = { version = "0.6", features = ["serde", "rand"] }
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"
Expand All @@ -104,9 +92,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"]

Expand Down
1 change: 1 addition & 0 deletions src/artifact_output/configurable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
2 changes: 1 addition & 1 deletion src/artifacts/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/artifacts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
1 change: 1 addition & 0 deletions src/buildinfo.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
19 changes: 10 additions & 9 deletions src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<PathBuf> {
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.
Expand Down Expand Up @@ -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 })
}
}
Expand Down
1 change: 1 addition & 0 deletions src/compile/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ impl CompilerSources {
};
}
}

/// Filters out all sources that don't need to be compiled, see [`ArtifactsCache::filter`]
fn filtered<T: ArtifactOutput>(
self,
Expand Down
8 changes: 3 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,16 @@ 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<SolcError>, PathBuf, PathBuf),
#[cfg(feature = "svm-solc")]
#[error(transparent)]
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),
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,9 @@ impl<T: ArtifactOutput> ProjectBuilder<T> {
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,
})
Expand Down
9 changes: 3 additions & 6 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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
Expand Down Expand Up @@ -372,11 +372,8 @@ pub fn library_hash_placeholder(name: impl AsRef<[u8]>) -> String {
///
/// See also <https://docs.soliditylang.org/en/develop/using-the-compiler.html#library-linking>
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
Expand Down

0 comments on commit 8ac8dca

Please sign in to comment.