Skip to content

Plugin: derive HOST_WIT_VERSION from WIT file at build time #327

@crippledgeek

Description

@crippledgeek

Follow-up to PR D-2 (merge 81f150f).

`HOST_WIT_VERSION` is currently a hardcoded `pub const &str` at `crates/rdlp-plugin/src/loader.rs:30`, with a doc-comment instructing the maintainer to keep it in sync with `package rdlp:plugin@X.Y.Z;` in the three .wit files. D-2's commit message already noted this is a foot-gun: a future WIT bump that forgets to update the const will silently accept incompatible plugins.

The drift-detection test (`host_constant_matches_current_contract`) catches it at test time, but only because the test pins `(0, 4, 0)` literally. The right fix is to remove the hand-maintained const entirely.

Approach options

  1. `build.rs` parses the WIT file at compile time and writes the version into a generated module. Simplest. Requires a build script in `rdlp-plugin`.

  2. Macro that `include_str!`s the WIT and regex-extracts the version at `const fn` evaluation. No build script. Slightly more magic.

  3. Procedural macro wrapping the bindgen output to expose the package version it parsed.

Option 1 is the cleanest. The build script reads e.g. `crates/rdlp-plugin/wit/extractor.wit`, finds the first line `package rdlp:plugin@X.Y.Z;`, emits `OUT_DIR/wit_version.rs` with `pub const HOST_WIT_VERSION: &str = "X.Y.Z";`. `loader.rs` then `include!`s it.

Acceptance criteria

  • A WIT package version bump in any of the three .wit files requires zero changes to `loader.rs`.
  • The drift-detection test no longer needs literal version pinning (or it stays, but only as a sanity check that the parse worked).
  • `cargo build -p rdlp-plugin` rebuilds the const when the WIT file changes (rerun-if-changed).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestplugin-systemPlugin system architecture and implementation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions