Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: extract artifacts to a separate crate #142

Merged
merged 22 commits into from
Jun 14, 2024
123 changes: 22 additions & 101 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[package]
name = "foundry-compilers"
[workspace]
members = ["crates/*"]
resolver = "2"

[workspace.package]
authors = ["Foundry Maintainers"]
version = "0.7.0"
rust-version = "1.65"
Expand All @@ -13,110 +16,28 @@ keywords = ["foundry", "solidity", "solc", "ethereum", "ethers"]
edition = "2021"
exclude = [".github/", "scripts/", "test-data/"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[package.metadata.playground]
all-features = true

[dependencies]
[workspace.dependencies]
foundry-compilers-artifacts = { path = "crates/artifacts", version = "0.7.0" }
foundry-compilers-artifacts-vyper = { path = "crates/artifacts-vyper", version = "0.7.0" }
foundry-compilers-core = { path = "crates/core", version = "0.7.0" }
serde = { version = "1", features = ["derive", "rc"] }
semver = { version = "1.0", features = ["serde"] }
serde_json = "1.0"
alloy-primitives = { version = "0.7", features = ["serde", "rand"] }
alloy-json-abi = { version = "0.7", features = ["serde_json"] }

solang-parser = { version = "=0.3.3", default-features = false }

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"
tracing = "0.1"
rayon = "1.8"
thiserror = "1"
regex = "1.10"
semver = { version = "1.0", features = ["serde"] }
serde = { version = "1", features = ["derive", "rc"] }
serde_json = "1.0"
thiserror = "1.0"
tracing = "0.1"
walkdir = "2.4"
path-slash = "0.2"
md-5 = "0.10"
yansi = "1.0.1"

# async
futures-util = { version = "0.3", optional = true }
tokio = { version = "1.35", features = ["rt-multi-thread"], optional = true }

# project-util
tempfile = { version = "3.9", optional = true }
fs_extra = { version = "1.3", optional = true }
rand = { version = "0.8", optional = true }

# svm
home = "0.5"
svm = { package = "svm-rs", version = "0.5", default-features = false, optional = true }
svm-builds = { package = "svm-rs-builds", version = "0.5", default-features = false, optional = true }
sha2 = { version = "0.10", default-features = false, optional = true }
itertools = "0.13"
auto_impl = "1"

winnow = "0.6"
dyn-clone = "1"
derivative = "2.2"

[dev-dependencies]
alloy-primitives = { version = "0.7", features = ["serde", "rand"] }
criterion = { version = "0.5", features = ["async_tokio"] }
once_cell = "1.19"
svm = { package = "svm-rs", version = "0.5", default-features = false }
solang-parser = { version = "=0.3.3", default-features = false }
pretty_assertions = "1"
rand = "0.8"
serde_path_to_error = "0.1"
tempfile = "3.9"
tokio = { version = "1.35", features = ["rt-multi-thread", "macros"] }
tracing-subscriber = { version = "0.3", default-features = false, features = [
"env-filter",
"fmt",
] }
reqwest = "0.12"
fd-lock = "4.0.0"

[[bench]]
name = "compile_many"
required-features = ["svm-solc"]
harness = false

[[bench]]
name = "read_all"
required-features = ["project-util", "svm-solc"]
harness = false

[[test]]
name = "project"
path = "tests/project.rs"
required-features = ["full", "project-util", "test-utils"]

[[test]]
name = "mocked"
path = "tests/mocked.rs"
required-features = ["full", "project-util"]

[features]
default = ["rustls"]
test-utils = []

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", "svm-solc"]

rustls = ["svm?/rustls"]
openssl = ["svm?/openssl"]
# async
futures-util = "0.3"
tokio = { version = "1.35", features = ["rt-multi-thread"] }
2 changes: 1 addition & 1 deletion benches/compile_many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn compile_many_benchmark(c: &mut Criterion) {

fn load_compiler_inputs() -> Vec<SolcInput> {
let mut inputs = Vec::new();
for file in std::fs::read_dir(Path::new(&env!("CARGO_MANIFEST_DIR")).join("test-data/in"))
for file in std::fs::read_dir(Path::new(&env!("CARGO_MANIFEST_DIR")).join("../../test-data/in"))
.unwrap()
.take(5)
{
Expand Down
35 changes: 35 additions & 0 deletions crates/artifacts-vyper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "foundry-compilers-artifacts-vyper"
description = "Rust bindings for Vyper JSON artifacts"

version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
exclude.workspace = true

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[package.metadata.playground]
all-features = true

[dependencies]
foundry-compilers-artifacts.workspace = true

serde.workspace = true
alloy-primitives.workspace = true
alloy-json-abi.workspace = true

[target.'cfg(windows)'.dependencies]
path-slash.workspace = true

[dev-dependencies]
serde_path_to_error = "0.1"
pretty_assertions.workspace = true
foundry-compilers-core = { workspace = true, features = ["test-utils"] }
serde_json.workspace = true
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use core::fmt;
use std::path::PathBuf;

use crate::{
artifacts::{error::SourceLocation, Severity},
compilers::CompilationError,
};
use foundry_compilers_artifacts::Severity;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct VyperSourceLocation {
Expand All @@ -25,28 +21,6 @@ pub struct VyperCompilationError {
pub formatted_message: Option<String>,
}

impl CompilationError for VyperCompilationError {
fn is_warning(&self) -> bool {
self.severity.is_warning()
}

fn is_error(&self) -> bool {
self.severity.is_error()
}

fn source_location(&self) -> Option<SourceLocation> {
None
}

fn severity(&self) -> Severity {
self.severity
}

fn error_code(&self) -> Option<u64> {
None
}
}

impl fmt::Display for VyperCompilationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(location) = &self.source_location {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use std::{borrow::Cow, path::Path};
use std::path::Path;

use super::{settings::VyperSettings, VyperLanguage, VYPER_INTERFACE_EXTENSION};
use crate::{
artifacts::{Source, Sources},
compilers::CompilerInput,
};
use semver::Version;
use super::VyperSettings;
use foundry_compilers_artifacts::sources::Sources;
use serde::{Deserialize, Serialize};

/// Extension of Vyper interface file.
pub const VYPER_INTERFACE_EXTENSION: &str = "vyi";

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VyperInput {
pub language: String,
Expand All @@ -16,14 +15,6 @@ pub struct VyperInput {
pub settings: VyperSettings,
}

#[derive(Debug, Clone, Serialize)]
pub struct VyperVersionedInput {
#[serde(flatten)]
pub input: VyperInput,
#[serde(skip)]
pub version: Version,
}

impl VyperInput {
pub fn new(sources: Sources, mut settings: VyperSettings) -> Self {
let mut new_sources = Sources::new();
Expand Down Expand Up @@ -57,41 +48,3 @@ impl VyperInput {
self.settings.strip_prefix(base)
}
}

impl CompilerInput for VyperVersionedInput {
type Settings = VyperSettings;
type Language = VyperLanguage;

fn build(
sources: Sources,
settings: Self::Settings,
_language: Self::Language,
version: Version,
) -> Self {
Self { input: VyperInput::new(sources, settings), version }
}

fn compiler_name(&self) -> Cow<'static, str> {
"Vyper".into()
}

fn strip_prefix(&mut self, base: &Path) {
self.input.strip_prefix(base);
}

fn language(&self) -> Self::Language {
VyperLanguage
}

fn version(&self) -> &Version {
&self.version
}

fn sources(&self) -> impl Iterator<Item = (&Path, &Source)> {
self.input
.sources
.iter()
.chain(self.input.interfaces.iter())
.map(|(path, source)| (path.as_path(), source))
}
}
15 changes: 15 additions & 0 deletions crates/artifacts-vyper/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! Vyper artifact types.

#![cfg_attr(not(test), warn(unused_crate_dependencies))]

mod settings;
pub use settings::{VyperOptimizationMode, VyperSettings};

mod error;
pub use error::VyperCompilationError;

mod input;
pub use input::VyperInput;

mod output;
pub use output::VyperOutput;
Loading
Loading