-
Notifications
You must be signed in to change notification settings - Fork 88
Add the initial CLAUDE.md file
#358
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
Open
xermicus
wants to merge
2
commits into
paritytech:master
Choose a base branch
from
xermicus:cl/claude
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Project Overview | ||
|
|
||
| PolkaVM is a general-purpose RISC-V based virtual machine targeting RV32EM. It provides secure sandboxed execution with both an interpreter and a JIT compiler backend. | ||
|
|
||
| ## Build Commands | ||
|
|
||
| ```bash | ||
| # Build all workspace crates | ||
| cargo build | ||
|
|
||
| # Build with release optimizations | ||
| cargo build --release | ||
|
|
||
| # Run all tests (both dev and release) | ||
| ./ci/jobs/build-and-test.sh | ||
|
|
||
| # Run tests for a specific crate | ||
| cargo test -p polkavm | ||
| cargo test -p polkavm-linker | ||
| cargo test -p polkavm-common | ||
|
|
||
| # Run tests with all features | ||
| cargo test -p polkavm-common --all-features | ||
|
|
||
| # Run a single test | ||
| cargo test -p polkavm -- test_name | ||
|
|
||
| # Linting | ||
| ./ci/jobs/clippy.sh | ||
| cargo clippy -p polkavm | ||
|
|
||
| # Formatting | ||
| cargo fmt --check --all | ||
| cargo fmt --all | ||
| ``` | ||
|
|
||
| ## Guest Programs | ||
|
|
||
| Guest programs (programs that run inside the VM) are in `guest-programs/` and use a separate workspace with nightly Rust: | ||
|
|
||
| ```bash | ||
| cd guest-programs | ||
|
|
||
| # Build guest programs (uses custom RISC-V target) | ||
| cargo build --release | ||
|
|
||
| # The custom target is at: crates/polkavm-linker/targets/legacy/riscv32emac-unknown-none-polkavm.json | ||
| ``` | ||
|
|
||
| Guest programs require nightly Rust (`nightly-2025-05-10`) with `rust-src` component for `-Z build-std`. | ||
|
|
||
| ## Architecture | ||
|
|
||
| ### Core Crates (`crates/`) | ||
|
|
||
| - **polkavm**: Main VM crate with `Engine`, `Module`, `Instance` API. Contains: | ||
| - `interpreter.rs`: Cross-platform interpreter backend | ||
| - `compiler.rs`: JIT compiler (x86_64 Linux/macOS/FreeBSD) | ||
| - `sandbox/`: Process isolation for compiled code | ||
| - `api.rs`: Public API types | ||
| - `linker.rs`: Runtime linking of host functions | ||
|
|
||
| - **polkavm-common**: Shared types and utilities | ||
| - `program.rs`: Program blob format, instruction definitions, parsing | ||
| - `assembler.rs`: Assembly/disassembly support | ||
| - `abi.rs`: VM ABI definitions (memory map, calling conventions) | ||
|
|
||
| - **polkavm-linker**: Offline linker that transforms ELF to PolkaVM format | ||
| - Reads RISC-V ELF files from guest compilation | ||
| - Performs register allocation via regalloc2 | ||
| - Outputs `.polkavm` program blobs | ||
|
|
||
| - **polkavm-zygote**: Linux-only process template for sandboxed execution (separate workspace) | ||
|
|
||
| - **polkavm-derive**: Proc macros for guest programs (`#[polkavm_import]`, `#[polkavm_export]`) | ||
|
|
||
| ### Tools (`tools/`) | ||
|
|
||
| - **polkatool**: CLI for inspecting/disassembling `.polkavm` blobs | ||
| - **spectool**: Generates test vectors for VM specification | ||
| - **gastool**: Gas metering analysis (Linux only) | ||
| - **benchtool**: Performance benchmarking suite | ||
|
|
||
| ### Execution Backends | ||
|
|
||
| The VM supports two backends controlled via `Config::set_backend()` or `POLKAVM_BACKEND` env var: | ||
| - `interpreter`: Cross-platform, always available | ||
| - `compiler`: JIT to native code, requires x86_64 + (Linux | macOS with `generic-sandbox` feature | FreeBSD with `generic-sandbox` feature) | ||
|
|
||
| ### Environment Variables | ||
|
|
||
| - `POLKAVM_BACKEND`: `auto`, `compiler`, `interpreter` | ||
| - `POLKAVM_SANDBOX`: `auto`, `linux`, `generic` | ||
| - `POLKAVM_ALLOW_EXPERIMENTAL`: Enable experimental features | ||
| - `POLKAVM_TRACE_EXECUTION`: Enable execution tracing (for debugging) | ||
|
|
||
| ## Testing | ||
|
|
||
| ```bash | ||
| # Full test suite | ||
| ./ci/jobs/build-and-test.sh | ||
|
|
||
| # Run with execution tracing | ||
| POLKAVM_TRACE_EXECUTION=1 POLKAVM_ALLOW_INSECURE=1 cargo run -p hello-world-host | ||
|
|
||
| # Fuzzing (requires cargo-fuzz) | ||
| cd fuzz | ||
| cargo fuzz run fuzz_polkavm -- -runs=10000 | ||
| ``` | ||
|
|
||
| ## Rust Version | ||
|
|
||
| - Main workspace: Rust 1.86.0 (stable) | ||
| - Guest programs: nightly-2025-05-10 | ||
|
|
||
| ## Key Types | ||
|
|
||
| - `Engine`: VM engine instance, configured via `Config` | ||
| - `Module`: Compiled program, created from `ProgramBlob` | ||
| - `Instance`: Execution instance with memory state | ||
| - `Linker`: Links host functions to module imports | ||
| - `ProgramBlob`: Serialized program format | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not against adding this, but it should be manually edited before committing so that it makes sense. For example:
linker.rs: Runtime linking of host functions' is incorrect and the naming scheme is mostly a historical artifact since I was originally basing this onwasmtime's API, or "Performs register allocation via regalloc2" is a minor detail and gross misrepresentation that will most likely confuse the AI, since register allocation is only done in a very specific case)etc.
If you're not sure about something feel free to just remove it. :P
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought claude may have some logic in what it puts inside this file when generating it. It did actually not too bad in creating the file for
paritytech/revive. Apparently here it's just mainly AI slop.Manually reviewed it and changed a few things. I don't know yet what exactly to put in there and what not. But the file is intended to be changed over time anyways.