From c9c43ce1a64710eb22cfdbef0d361703ac3cf0f5 Mon Sep 17 00:00:00 2001 From: 0xrusowsky <0xrusowsky@proton.me> Date: Mon, 30 Jun 2025 09:22:24 +0200 Subject: [PATCH 1/3] chore: bump solar --- Cargo.toml | 6 ++++++ crates/compilers/src/cache/iface.rs | 2 +- crates/compilers/src/resolver/parse.rs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d2277f869..35ad1cec3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,3 +68,9 @@ futures-util = "0.3" tokio = { version = "1.35", features = ["rt-multi-thread"] } snapbox = "0.6.9" + +[patch.crates-io] +solar-parse = { git = "https://github.com/0xrusowsky/solar", branch = "rusowsky/fn-header-spans" } +solar-sema = { git = "https://github.com/0xrusowsky/solar", branch = "rusowsky/fn-header-spans" } +# solar-ast = { git = "https://github.com/0xrusowsky/solar", branch = "rusowsky/fn-header-spans" } +# solar-interface = { git = "https://github.com/0xrusowsky/solar", branch = "rusowsky/fn-header-spans" } diff --git a/crates/compilers/src/cache/iface.rs b/crates/compilers/src/cache/iface.rs index 8f006ef41..ff29be147 100644 --- a/crates/compilers/src/cache/iface.rs +++ b/crates/compilers/src/cache/iface.rs @@ -38,7 +38,7 @@ pub(crate) fn interface_representation_ast( let is_exposed = match function.kind { // Function with external or public visibility ast::FunctionKind::Function => { - function.header.visibility >= Some(ast::Visibility::Public) + function.header.visibility.map(|v| *v) >= Some(ast::Visibility::Public) } ast::FunctionKind::Constructor | ast::FunctionKind::Fallback diff --git a/crates/compilers/src/resolver/parse.rs b/crates/compilers/src/resolver/parse.rs index 0627bb01c..06c21f95e 100644 --- a/crates/compilers/src/resolver/parse.rs +++ b/crates/compilers/src/resolver/parse.rs @@ -272,7 +272,7 @@ fn library_is_inlined(contract: &ast::ItemContract<'_>) -> bool { }) .all(|f| { !matches!( - f.header.visibility, + f.header.visibility.map(|v| *v), Some(ast::Visibility::Public | ast::Visibility::External) ) }) From 53edca498add84d030ea294fbdd5839d3dbb5d6f Mon Sep 17 00:00:00 2001 From: 0xrusowsky <0xrusowsky@proton.me> Date: Wed, 9 Jul 2025 08:40:50 +0200 Subject: [PATCH 2/3] remove dep patch --- CLAUDE.md | 230 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 6 -- 2 files changed, 230 insertions(+), 6 deletions(-) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 000000000..f0e13f04b --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,230 @@ +# Foundry Compilers - Claude Code Assistant Guide + +This guide provides comprehensive instructions for Claude Code agents working on the Foundry Compilers project. Foundry Compilers is the compilation backend for [Foundry](https://github.com/foundry-rs/foundry), supporting both Solidity and Vyper smart contract compilation. + +## Project Overview + +Foundry Compilers (formerly `ethers-solc`) is a Rust library that provides: +- Multi-language support (Solidity via `solc` and Vyper) +- Compilation management with caching +- Artifact handling and output management +- Source resolution and dependency management +- Build information and metadata handling + +### Key Components + +1. **Core Library** (`crates/compilers/`): Main compilation logic and project management +2. **Artifacts** (`crates/artifacts/`): Data structures for compiler inputs/outputs + - `artifacts/`: Common artifact types + - `solc/`: Solidity-specific artifacts (AST, bytecode, etc.) + - `vyper/`: Vyper-specific artifacts +3. **Core Utilities** (`crates/core/`): Shared utilities and error handling + +## Development Guidelines + +### Environment Setup + +- **Rust Version**: MSRV 1.87 (check `Cargo.toml` for current version) +- **Platform Support**: Linux, macOS, Windows +- **Optional Features**: + - `svm-solc`: Automatic Solc version management + - `project-util`: Testing utilities + +### Code Quality Standards + +#### Formatting +```bash +# Use nightly for formatting +cargo +nightly fmt --all + +# Check formatting without changes +cargo +nightly fmt --all --check +``` + +#### Linting +```bash +# Run clippy with all features +cargo clippy --all-features --all-targets +# CI runs with warnings as errors +RUSTFLAGS="-D warnings" cargo clippy --all-features --all-targets +``` + +#### Testing +```bash +# Run all tests +cargo test --all-features + +# Run doc tests +cargo test --workspace --doc --all-features + +# Run specific test +cargo test test_name --all-features +``` + +### Project Structure + +``` +foundry-compilers/ +├── crates/ +│ ├── compilers/ # Main library +│ │ ├── src/ +│ │ │ ├── compilers/ # Compiler implementations +│ │ │ │ ├── solc/ # Solidity compiler +│ │ │ │ └── vyper/ # Vyper compiler +│ │ │ ├── artifact_output/ # Artifact handling +│ │ │ ├── cache/ # Compilation caching +│ │ │ ├── compile/ # Compilation orchestration +│ │ │ ├── resolver/ # Source resolution +│ │ │ └── lib.rs # Main API +│ │ └── tests/ +│ ├── artifacts/ # Artifact definitions +│ │ ├── artifacts/ # Common artifacts +│ │ ├── solc/ # Solidity-specific +│ │ └── vyper/ # Vyper-specific +│ └── core/ # Core utilities +├── test-data/ # Test fixtures +└── benches/ # Performance benchmarks +``` + +### Key APIs and Patterns + +#### Project Configuration +```rust +use foundry_compilers::{Project, ProjectPathsConfig}; + +// Configure project paths +let paths = ProjectPathsConfig::hardhat(root)?; + +// Build project with settings +let project = Project::builder() + .paths(paths) + .settings(settings) + .build(Default::default())?; + +// Compile project +let output = project.compile()?; +``` + +#### Multi-Compiler Support +The project supports both Solidity and Vyper through the `MultiCompiler`: +- Automatically detects file types (`.sol`, `.vy`, `.yul`) +- Manages compiler-specific settings +- Handles mixed-language projects + +#### Artifact Management +- Configurable output formats via `ArtifactOutput` trait +- Built-in implementations: `ConfigurableArtifacts`, `HardhatArtifacts` +- Support for custom artifact handlers + +### Testing Guidelines + +1. **Unit Tests**: Test individual functions with focused scope +2. **Integration Tests**: Located in `tests/` directory of each crate +3. **Documentation Tests**: Include examples in doc comments +4. **Test Data**: Use fixtures from `test-data/` directory + +Example test pattern: +```rust +#[test] +fn test_compilation() { + let root = utils::canonicalize("../../test-data/sample").unwrap(); + let project = Project::builder() + .paths(ProjectPathsConfig::hardhat(&root).unwrap()) + .build(Default::default()) + .unwrap(); + + let output = project.compile().unwrap(); + assert!(!output.has_compiler_errors()); +} +``` + +### Common Tasks + +#### Adding Compiler Support +1. Implement the `Compiler` trait +2. Add language detection in `Language` trait +3. Update `MultiCompiler` to include new compiler +4. Add artifact types in `artifacts` crate + +#### Modifying AST Handling +- AST definitions in `crates/artifacts/solc/src/ast/` +- Use `#[serde(rename_all = "camelCase")]` for JSON compatibility +- Handle version differences with conditional compilation + +#### Cache Management +- Cache stored in `.foundry_cache/` +- Invalidation based on source content and compiler settings +- See `crates/compilers/src/cache.rs` for implementation + +### Performance Considerations + +1. **Parallel Compilation**: Controlled by `solc_jobs` setting +2. **Caching**: Aggressive caching of compilation results +3. **Sparse Output**: Use `SparseOutputFilter` to limit artifacts +4. **Graph Resolution**: Efficient dependency resolution + +Run benchmarks: +```bash +cargo bench --workspace +``` + +### Error Handling + +- Use `Result` with `SolcError` for all fallible operations +- Provide context with error messages +- Handle compiler-specific errors appropriately + +### Contributing Workflow + +1. **Before Starting**: + - Check existing issues and PRs + - Discuss large changes in an issue first + +2. **Development**: + - Follow conventional commits (feat:, fix:, chore:, etc.) + - Keep commits logically grouped + - Add tests for new functionality + +3. **Submitting PRs**: + - Ensure CI passes (formatting, clippy, tests) + - Update documentation as needed + - Allow edits from maintainers + +### Common Commands Summary + +```bash +# Development +cargo check --all-features +cargo build --all-features +cargo test --all-features + +# Code Quality +cargo +nightly fmt --all +cargo clippy --all-features --all-targets + +# Documentation +cargo doc --all-features --no-deps --open + +# Benchmarks +cargo bench --workspace +``` + +### Debugging Tips + +1. **Enable Tracing**: Set `RUST_LOG=foundry_compilers=trace` +2. **Inspect Cache**: Check `.foundry_cache/solidity-files-cache.json` +3. **Compilation Errors**: Use `output.diagnostics()` for detailed errors +4. **Graph Issues**: Use `Graph::resolve()` to debug dependency problems + +### Important Notes + +- **No Grammar/Spelling PRs**: Focus on functional improvements +- **Breaking Changes**: Clearly mark in commit messages +- **Version Support**: Maintain compatibility with supported Solc/Vyper versions +- **Platform Testing**: Ensure changes work on Linux, macOS, and Windows + +### Resources + +- [API Documentation](https://docs.rs/foundry-compilers) +- [Foundry Book](https://book.getfoundry.sh/) +- [Telegram Dev Chat](https://t.me/foundry_rs) \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 35ad1cec3..d2277f869 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,9 +68,3 @@ futures-util = "0.3" tokio = { version = "1.35", features = ["rt-multi-thread"] } snapbox = "0.6.9" - -[patch.crates-io] -solar-parse = { git = "https://github.com/0xrusowsky/solar", branch = "rusowsky/fn-header-spans" } -solar-sema = { git = "https://github.com/0xrusowsky/solar", branch = "rusowsky/fn-header-spans" } -# solar-ast = { git = "https://github.com/0xrusowsky/solar", branch = "rusowsky/fn-header-spans" } -# solar-interface = { git = "https://github.com/0xrusowsky/solar", branch = "rusowsky/fn-header-spans" } From c8da9f9f9f1e683b04c0e9f4f65b4af61384dd4e Mon Sep 17 00:00:00 2001 From: 0xrusowsky <0xrusowsky@proton.me> Date: Wed, 9 Jul 2025 08:42:46 +0200 Subject: [PATCH 3/3] housekeeping --- CLAUDE.md | 230 ------------------------------------------------------ 1 file changed, 230 deletions(-) delete mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 100644 index f0e13f04b..000000000 --- a/CLAUDE.md +++ /dev/null @@ -1,230 +0,0 @@ -# Foundry Compilers - Claude Code Assistant Guide - -This guide provides comprehensive instructions for Claude Code agents working on the Foundry Compilers project. Foundry Compilers is the compilation backend for [Foundry](https://github.com/foundry-rs/foundry), supporting both Solidity and Vyper smart contract compilation. - -## Project Overview - -Foundry Compilers (formerly `ethers-solc`) is a Rust library that provides: -- Multi-language support (Solidity via `solc` and Vyper) -- Compilation management with caching -- Artifact handling and output management -- Source resolution and dependency management -- Build information and metadata handling - -### Key Components - -1. **Core Library** (`crates/compilers/`): Main compilation logic and project management -2. **Artifacts** (`crates/artifacts/`): Data structures for compiler inputs/outputs - - `artifacts/`: Common artifact types - - `solc/`: Solidity-specific artifacts (AST, bytecode, etc.) - - `vyper/`: Vyper-specific artifacts -3. **Core Utilities** (`crates/core/`): Shared utilities and error handling - -## Development Guidelines - -### Environment Setup - -- **Rust Version**: MSRV 1.87 (check `Cargo.toml` for current version) -- **Platform Support**: Linux, macOS, Windows -- **Optional Features**: - - `svm-solc`: Automatic Solc version management - - `project-util`: Testing utilities - -### Code Quality Standards - -#### Formatting -```bash -# Use nightly for formatting -cargo +nightly fmt --all - -# Check formatting without changes -cargo +nightly fmt --all --check -``` - -#### Linting -```bash -# Run clippy with all features -cargo clippy --all-features --all-targets -# CI runs with warnings as errors -RUSTFLAGS="-D warnings" cargo clippy --all-features --all-targets -``` - -#### Testing -```bash -# Run all tests -cargo test --all-features - -# Run doc tests -cargo test --workspace --doc --all-features - -# Run specific test -cargo test test_name --all-features -``` - -### Project Structure - -``` -foundry-compilers/ -├── crates/ -│ ├── compilers/ # Main library -│ │ ├── src/ -│ │ │ ├── compilers/ # Compiler implementations -│ │ │ │ ├── solc/ # Solidity compiler -│ │ │ │ └── vyper/ # Vyper compiler -│ │ │ ├── artifact_output/ # Artifact handling -│ │ │ ├── cache/ # Compilation caching -│ │ │ ├── compile/ # Compilation orchestration -│ │ │ ├── resolver/ # Source resolution -│ │ │ └── lib.rs # Main API -│ │ └── tests/ -│ ├── artifacts/ # Artifact definitions -│ │ ├── artifacts/ # Common artifacts -│ │ ├── solc/ # Solidity-specific -│ │ └── vyper/ # Vyper-specific -│ └── core/ # Core utilities -├── test-data/ # Test fixtures -└── benches/ # Performance benchmarks -``` - -### Key APIs and Patterns - -#### Project Configuration -```rust -use foundry_compilers::{Project, ProjectPathsConfig}; - -// Configure project paths -let paths = ProjectPathsConfig::hardhat(root)?; - -// Build project with settings -let project = Project::builder() - .paths(paths) - .settings(settings) - .build(Default::default())?; - -// Compile project -let output = project.compile()?; -``` - -#### Multi-Compiler Support -The project supports both Solidity and Vyper through the `MultiCompiler`: -- Automatically detects file types (`.sol`, `.vy`, `.yul`) -- Manages compiler-specific settings -- Handles mixed-language projects - -#### Artifact Management -- Configurable output formats via `ArtifactOutput` trait -- Built-in implementations: `ConfigurableArtifacts`, `HardhatArtifacts` -- Support for custom artifact handlers - -### Testing Guidelines - -1. **Unit Tests**: Test individual functions with focused scope -2. **Integration Tests**: Located in `tests/` directory of each crate -3. **Documentation Tests**: Include examples in doc comments -4. **Test Data**: Use fixtures from `test-data/` directory - -Example test pattern: -```rust -#[test] -fn test_compilation() { - let root = utils::canonicalize("../../test-data/sample").unwrap(); - let project = Project::builder() - .paths(ProjectPathsConfig::hardhat(&root).unwrap()) - .build(Default::default()) - .unwrap(); - - let output = project.compile().unwrap(); - assert!(!output.has_compiler_errors()); -} -``` - -### Common Tasks - -#### Adding Compiler Support -1. Implement the `Compiler` trait -2. Add language detection in `Language` trait -3. Update `MultiCompiler` to include new compiler -4. Add artifact types in `artifacts` crate - -#### Modifying AST Handling -- AST definitions in `crates/artifacts/solc/src/ast/` -- Use `#[serde(rename_all = "camelCase")]` for JSON compatibility -- Handle version differences with conditional compilation - -#### Cache Management -- Cache stored in `.foundry_cache/` -- Invalidation based on source content and compiler settings -- See `crates/compilers/src/cache.rs` for implementation - -### Performance Considerations - -1. **Parallel Compilation**: Controlled by `solc_jobs` setting -2. **Caching**: Aggressive caching of compilation results -3. **Sparse Output**: Use `SparseOutputFilter` to limit artifacts -4. **Graph Resolution**: Efficient dependency resolution - -Run benchmarks: -```bash -cargo bench --workspace -``` - -### Error Handling - -- Use `Result` with `SolcError` for all fallible operations -- Provide context with error messages -- Handle compiler-specific errors appropriately - -### Contributing Workflow - -1. **Before Starting**: - - Check existing issues and PRs - - Discuss large changes in an issue first - -2. **Development**: - - Follow conventional commits (feat:, fix:, chore:, etc.) - - Keep commits logically grouped - - Add tests for new functionality - -3. **Submitting PRs**: - - Ensure CI passes (formatting, clippy, tests) - - Update documentation as needed - - Allow edits from maintainers - -### Common Commands Summary - -```bash -# Development -cargo check --all-features -cargo build --all-features -cargo test --all-features - -# Code Quality -cargo +nightly fmt --all -cargo clippy --all-features --all-targets - -# Documentation -cargo doc --all-features --no-deps --open - -# Benchmarks -cargo bench --workspace -``` - -### Debugging Tips - -1. **Enable Tracing**: Set `RUST_LOG=foundry_compilers=trace` -2. **Inspect Cache**: Check `.foundry_cache/solidity-files-cache.json` -3. **Compilation Errors**: Use `output.diagnostics()` for detailed errors -4. **Graph Issues**: Use `Graph::resolve()` to debug dependency problems - -### Important Notes - -- **No Grammar/Spelling PRs**: Focus on functional improvements -- **Breaking Changes**: Clearly mark in commit messages -- **Version Support**: Maintain compatibility with supported Solc/Vyper versions -- **Platform Testing**: Ensure changes work on Linux, macOS, and Windows - -### Resources - -- [API Documentation](https://docs.rs/foundry-compilers) -- [Foundry Book](https://book.getfoundry.sh/) -- [Telegram Dev Chat](https://t.me/foundry_rs) \ No newline at end of file