Skip to main content

Module dynamic

Module dynamic 

Source
Expand description

Loading plugins built as shared libraries.

A plugin compiled as a shared library (.so, .dylib, .dll) is loaded from a directory at start-up by load_plugins_from_dir. The library and the razeri that loads it then share Rust types: the dialect traits, the registry builder, and every value passed between them. Rust lays those types out the same way on both sides only when both sides are the same build — the same compiler, and the same source of razeri-plugin-api and razeri-plugin-contract. Anything else reads memory the wrong way, and the process crashes rather than failing.

So a plugin says how it was built, in a BuildDeclaration, and says it through a door every compiler reads alike: a C function returning a #[repr(C)] record of C strings and one number. The loader reads that first. A library whose declaration differs from this razeri’s own in any part, or that declares nothing, is refused with a PluginRefusal that names what it was built with and what it needs. Two things of a library run before that answer: its initialisers, which run when it is opened, and the C function that returns its declaration, where it has one. A refused library runs nothing else, so a file in the plugin directory is trusted that far.

A plugin exports its declaration and its registration with one line, export_plugin!. The same line lets the crate be linked into a razeri you build yourself instead, which needs no match at all because there is only one build.

§What else the loader does

  • Panics stay in the plugin: registration runs inside catch_unwind.
  • Libraries stay loaded: a library whose registration ran is never unloaded, because what it registered lives as long as the process. A refused library is unloaded at once; nothing of it was kept.
  • An open directory is named: on Unix, a plugin directory anyone can write to is reported in the log.

Structs§

BuildDeclaration
How a plugin was built: the compiler, and the two plugin crates it was compiled against.

Enums§

BuildPart
One part of a BuildDeclaration, named so a refusal can say which parts differ.
PluginLoadResult
Outcome of loading a single plugin library.
PluginRefusal
Why the loader would not load a plugin library.

Constants§

LINKING_GUIDE
Where a plugin author reads how to link a dialect into a razeri they build — the other way to run a plugin, and the one every refusal offers. It names the page inside the book each release carries, because the book has no public address.
PLUGIN_BUILD_SYMBOL
Symbol name for the function that says how a plugin was built.
PLUGIN_REGISTER_SYMBOL
Symbol name for the plugin registration function.

Functions§

load_plugins_from_dir
Load all plugin shared libraries from dir and register them with builder.
read_declaration⚠
Read a declaration a library exported.

Type Aliases§

BuildDeclarationFn
Type signature for the function that says how a plugin was built.
RegisterPluginFn
Type signature for the plugin registration entry point.