Expand description
plugin_host submodule — native (Rust) plugin loader (zmodload -R).
Native (Rust) plugin host — extension; no zsh C counterpart.
zsh’s Src/module.c dlopens C .so modules that call addbuiltin
against the shell’s own symbols. zshrs generalises that into a
stable, versioned C ABI (znative crate) so third parties
ship a compiled cdylib and load it at runtime with
zmodload -R <path> — no zshrs recompile, no zsh script glue. This
is the first compiled Unix shell hosting native compiled-language
plugins.
§Where plugin commands resolve
fusevm compiles command names it does not recognise as builtins into
external execution. A freshly-loaded plugin command is therefore
unknown at compile time and arrives at
crate::vm_helper’s execute_external_bg, which consults
[dispatch] BEFORE spawning a process — the same slot zsh uses for
zmodload -ab autoloaded builtins (resolvebuiltin). Plugins thus
resolve after real builtins and functions, before PATH lookup.
§ABI safety
Everything crossing the boundary is #[repr(C)]. The host verifies
the plugin’s abi_version matches znative::ABI_VERSION
before trusting any pointer it returns; a mismatch is refused (a
wrong struct layout would be undefined behaviour). The loaded
libloading::Library is kept alive for the process lifetime — its
Drop is a dlclose, which would invalidate the still-registered
function pointers, so unload explicitly purges the registry first.
Functions§
- dispatch
- Command-resolution hook. Called from
execute_external_bgfor bare command names. ReturnsSome(exit_status)if a plugin ownscmd, elseNone(let PATH lookup proceed). - flush_
pending_ completions - Install any completion wirings that plugins requested but that have not
yet been bound into compsys. Called at the top of the completion
pipeline (
do_completion) — a safe point where compsys itself evals, unlike plugin-init (deep in thezmodloadcall stack, where evaling hangs the VM). Idempotent: each pending entry is installed once, then moved toinstalled_completions. - is_
plugin_ command - True if
nameis a live plugin command. Used where callers want to know whether a name resolves to a plugin without invoking it. - list
(name, version, path)for each loaded plugin, forzmodload -Rlisting. Sorted by name for stable output.- load
- Load a plugin
cdylibfrompath. Returns the plugin’s name on success. Idempotent-ish: loading a plugin whose name is already present is refused (unload first). - unload
- Unload a plugin by name: purge its command registrations FIRST (so no
live function pointer survives), then drop the
Library(dlclose). - zmodload_
rust_ cmd zmodload -Rnative-plugin management, dispatched fromcrate::ported::module::bin_zmodload(kept out ofsrc/ported/because it is a zshrs extension, not a C port).