Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

WASM Plugins (Experimental)

ghostdep can load community-contributed language plugins compiled as WebAssembly modules.

Status: The WASM host is functional but the plugin API is not yet formally documented. If you’re interested in writing a plugin, the information below should get you started. Expect the API to stabilize in a future release.

Plugin discovery

ghostdep looks for .wasm files in two locations:

  1. plugins/ in your project root
  2. ~/.ghostdep/plugins/

Any .wasm file found is loaded automatically. If loading fails, a warning is printed and the plugin is skipped.

Expected exports

Your WASM module must export these functions:

FunctionSignatureReturns
alloc(len: i32) -> i32Pointer to allocated memory
plugin_name() -> i64Packed ptr:len string
file_extensions() -> i64Comma-separated list
manifest_filenames() -> i64Comma-separated list
parse_manifest(ptr: i32, len: i32) -> i64JSON response
scan_imports(ptr: i32, len: i32) -> i64JSON response
is_stdlib(ptr: i32, len: i32) -> i320 or 1
normalize_import(ptr: i32, len: i32) -> i64Packed ptr:len string
aliases() -> i64JSON object

String passing convention

Strings are passed through WASM linear memory. The host writes input strings using alloc, and reads output strings from packed i64 values where the high 32 bits are the pointer and the low 32 bits are the length.

JSON formats

parse_manifest receives:

{"content": "...", "path": "..."}

And returns an array of:

[{"name": "pkg", "normalized": "pkg", "group": "main"}]

scan_imports receives the same input and returns:

[{"raw": "pkg", "normalized": "pkg", "line": 1, "confidence": "high"}]

aliases returns:

{"import_name": "package_name"}

Error handling

  • If a plugin fails to load, it’s skipped with a warning
  • If a plugin panics during a function call, the file is skipped
  • Plugin errors never crash the main process

Source reference

See src/plugin/wasm_host.rs for the full implementation.