Skip to content

Create Code Generation Plugin System #8

@Kinflou

Description

@Kinflou

Create Code Generation Plugin System

Priority

P1 (High) - Enables language-specific code generation

Labels

  • core
  • codegen
  • plugins
  • P1

Estimated Effort

3-4 weeks

Description

Build the plugin architecture for code generators. This allows language-specific generators to be developed as separate libraries and loaded dynamically.

Requirements:

  • Stable Rust ABI interface (challenging!)
  • Dynamic library loading
  • Plugin discovery
  • Version compatibility checking

Current State

Location: core/src/codelib_gen.rs

Only interface defined (24 lines), no implementation. Single todo!() for the loader.

TODO References

  • codelib_gen.rs:21 - "Rust ABI Stable code needs to be done, traits and so on and load here"

Technical Challenge

Rust doesn't have a stable ABI by default. Possible solutions:

  1. Use C ABI wrapper (traditional approach)
  2. Use abi_stable crate (Rust-to-Rust stable ABI)
  3. Use process-based plugins (spawn external process)
  4. WebAssembly plugins (WASM runtime)

Need to research and decide on approach.

Acceptance Criteria

  • Plugin API defined with stable ABI
  • Dynamic library loading works cross-platform
  • Plugin discovery from standard paths (~/.comline/plugins/, ./plugins/)
  • Version compatibility enforcement
  • At least 2 reference generators implemented:
    • Rust generator (structs, enums, traits)
    • TypeScript generator (interfaces, types)
  • Plugin development guide written
  • Example third-party plugin works

Tasks

  • Research stable ABI solutions (compare approaches)
  • Design plugin interface (trait definitions)
  • Implement dynamic library loading (using libloading or similar)
  • Create plugin registry/discovery system
  • Add version checking and compatibility validation
  • Build reference Rust generator:
    • Generate Rust structs from schema structs
    • Generate Rust enums from schema enums
    • Generate trait definitions from protocols
  • Build reference TypeScript generator:
    • Generate TS interfaces
    • Generate type definitions
    • Generate RPC client stubs
  • Write plugin development guide
  • Add plugin testing infrastructure
  • Document plugin system architecture

Plugin Interface (Draft)

pub trait Generator {
    fn name(&self) -> &str;
    fn version(&self) -> &str;
    fn supports_version(&self, ir_version: &str) -> bool;
    fn generate(&self, frozen_units: &[FrozenUnit]) -> Result<String>;
}

Dependencies

Blocks

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Priority 1 - HighcodegenCode generationcoreCore system componentpluginsPlugin system

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions