Skip to content

Create Code Generation Plugin System #8

Description

@Kinflou

Create Code Generation Plugin System

Updated 2026-08-30 for accuracy. core now has a minimal built-in
generator, not a todo!() stub: core/src/codelib_gen/{mod.rs,rust.rs}
find_generator("rust", _) returns a synchronous fn(&Vec<FrozenUnit>) -> String that emits structs / enums / traits. There is still no dynamic
loading, ABI, plugin discovery or version negotiation — that substance is what
remains here.

The earlier, more complete design lives in ComlineProject/generation
(code_gen = source-text emission; lib_gen = a buildable crate skeleton;
rust_c_ffi + rust_abi_stable flavors). It is unmigrated — it imports the
removed comline_core::…::basic_storage. Reviving it is part of this issue.

Consumer-facing hook: the code-generation output-config doc specs a
comline.toml [generate] mode = "code" | "lib" | "dylib" that sits on top
of this issue — code = the built-in generator, lib / dylib = lib_gen.

Priority

P1 (High) - Enables language-specific code generation

Labels

  • core
  • codegen
  • plugins
  • P1

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

  • core/src/codelib_gen/mod.rsfind_generator(name, version), hardcoded
    match name { "rust" => … }, returns (fn(&Vec<FrozenUnit>) -> String, ext).
  • core/src/codelib_gen/rust.rsgenerate_rust: structs, enums, trait for
    protocols. Synchronous, in-process, no versioning.
  • ComlineProject/generationcode_gen / lib_gen / rust_c_ffi /
    rust_abi_stable scaffolding, pre-CAS, does not build against current core.
  • No dynamic loading, no ABI boundary, no discovery, no supports_version.

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
  • Migrate / rebuild the ComlineProject/generation generators against
    current core (code_gen text + lib_gen crate/dylib).
  • Build reference Rust generator (extend codelib_gen::rust):
    • Generate Rust structs from schema structs
    • Generate Rust enums from schema enums
    • Generate trait definitions from protocols
    • Emit cross-schema imports as use (currently dropped)
  • 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Priority 1 - HighcodegenCode generationcoreCore system componentpluginsPlugin system

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions