Contributing Guide
Thank you for contributing to cppbolt! This document outlines development workflows, code standards, how to add a language feature end-to-end, and the required pull request checklist.
1. Development Environment & Build
Building the project requires a standard Rust toolchain (2024 edition).
# Build the native CLI compiler (target/release/cppbolt-cli)
cargo build --release
# Run Rust unit and integration tests
cargo test --all-targets
# Run formatting and linting gates
cargo fmt --all -- --check
cargo clippy --all-targets -- -D warnings
2. Running Tests & the Compiler
Running the Corpus Runner
All C++ test suites (positive tests, negative diagnostics, and runtime traps) are managed by cppbolt-testrunner:
# Run all discovered test groups
cargo run --bin cppbolt-testrunner -- target/release/cppbolt-cli
# Run a specific feature group (e.g. c_basics)
cargo run --bin cppbolt-testrunner -- target/release/cppbolt-cli c_basics
For full details on the test categories (variants, independent tests, golden hashes, native oracle gates, and census metrics), see the dedicated Testing System Guide.
Compiling and Running a Sample
Compile a C++ source file using the native CLI:
# Compile C++ source to a WebAssembly binary
cargo run --release --bin cppbolt-cli -- path/to/sample.cpp -o output.wasm
You can run the resulting .wasm binary in Node.js using the test runner shim:
node tests/test_wasm_compiler.js output.wasm
Or test it in the browser playground:
cargo build --release --target wasm32-unknown-unknown --lib
tools/build_site.sh
python3 -m http.server --directory site 8000
3. Adding a New Language Feature End-to-End
When adding a new C++ language feature or expression form to cppbolt, modifications typically flow through each stage of the compiler pipeline:
- Tokens (
src/lexer/):- If the feature introduces new keywords or operators, add variants to
src/lexer/token.rsand update lexer scanning insrc/lexer/mod.rs.
- If the feature introduces new keywords or operators, add variants to
- Abstract Syntax Tree (
src/ast/):- Define corresponding AST nodes in
src/ast/expr.rs,src/ast/stmt.rs,src/ast/decl.rs, orsrc/ast/types.rs. Ensure nodes record line and column positions for diagnostic accuracy.
- Define corresponding AST nodes in
- Parser (
src/parser/):- Add parsing logic in
src/parser/expr.rs,src/parser/stmt.rs, orsrc/parser/decl.rs. - If lifting a restriction on a previously unsupported feature, update
src/parser/unsupported.rs. - Track nesting limits using
self.depth(src/depth.rs) to prevent stack overflow on pathological inputs.
- Add parsing logic in
- Semantic Analysis (
src/sema/):- Implement type checking, name lookup, and conversions in
src/sema/analyze.rs,src/sema/expr.rs, orsrc/sema/lookup.rs. - Synthesize necessary implicit copy/default constructors or record layouts.
- Implement type checking, name lookup, and conversions in
- Code Generation (
src/codegen/):- Lower the typed AST node to WebAssembly bytecodes in
src/codegen/expr.rs,src/codegen/stmt.rs, or dedicated helpers. - Respect stack frame conventions in
src/codegen/function_context.rsand memory layout rules insrc/runtime/memory_layout.rs.
- Lower the typed AST node to WebAssembly bytecodes in
- Corpus Tests (
tests/):- Add positive test cases (
.cppand.expected) intests/<feature_group>/. - Add corresponding anti-overfitting structural tests in
tests/<feature_group>_variant/. - If rejecting invalid syntax, add a negative test (
.cppand.expected_err) intests/negative/. - Update
tests/PASSING.txtand regenerate golden hashes if expected changes are approved:cargo run --release --bin cppbolt-testrunner -- --golden tests/golden.txt target/release/cppbolt-cli
- Add positive test cases (
4. Code Standards & Repository Rules
- No Compiler Logic Modifications Without Tests: Every supported behavior must have a positive corpus test. Every unsupported construct must produce a clean diagnostic, not a crash or panic.
- Panic-Free Policy: Never use
unwrap(),expect(), orpanic!()on code paths that can process user input. UseResult<T, CompileError>. - Function and File Size Limits: Enforced by
src/bin/cppbolt-census.rsand verified bytests/census_fixture.rs:- No function may exceed 80 lines.
- No function may take more than 5 parameters (excluding
self). - No file in
src/may exceed 500 lines.
- Module Tree Reachability: Every Rust source file under
src/must be wired into the crate module tree; verified bytests/module_tree.rs. - Preserve Documentation Integrity: Comments should document invariants, ABI decisions, and memory models, rather than narrating line-by-line changes.
5. Pull Request Checklist
Before submitting a pull request, ensure all of the following items are complete:
-
Tests Pass:
cargo test --all-targetsexits 0. -
Corpus Runner Passes:
cargo run --bin cppbolt-testrunner -- target/release/cppbolt-clireports 0 unexpected failures and 0 manifest violations. -
Code Quality Gates Pass:
cargo fmt --all -- --checkcargo clippy --all-targets -- -D warningscargo run --release --bin cppbolt-censusreports 0 violations.
- Feature Matrix Updated: New features or changed statuses are reflected in Supported C++ with links to test files.
-
Documentation Updated: Relevant mdBook chapters or doc comments (
///,//!) updated. -
ADR Created (if applicable): An Architecture Decision Record was added to
docs/adr/if an architectural, memory model, or ABI decision was made.