feat(plugin): load external cdylib plugins at runtime (phase 2)
Move BuiltinPlugin into ocs_plugin_api (host feature) so out-of-tree crates can implement it, and add export_plugin! to emit the two C symbols a cdylib exposes: ocs_plugin_api_version (checked first, so an ABI-incompatible build never runs) and ocs_plugin_register -> boxed BuiltinPlugin. The host loads every compatible package from the plugins folder at startup via libloading (desktop only), keeps the library resident for the session, and merges its ribbon tab + command dispatch into the same paths as built-ins (honouring enable/disable). The Plugin Manager shows external packages with a Loaded / incompatible status. Approach B: the plugin hands back a boxed trait object, assuming a matching toolchain + ocs_plugin_api version (the version symbol enforces the latter). crates/ocs_example_plugin is the reference cdylib. Part of the #100 extensibility epic (phase 2). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
f6219a9609
commit
29c71be101
14 changed files with 402 additions and 36 deletions
|
|
@ -2,21 +2,8 @@
|
|||
// access) and implements the stable `HostApi` contract plugins target.
|
||||
|
||||
pub(crate) use crate::app::plugin_host::HostSession;
|
||||
/// The stable runtime surface a plugin's `dispatch` receives.
|
||||
pub use ocs_plugin_api::host::HostApi;
|
||||
|
||||
use crate::modules::CadModule;
|
||||
|
||||
use super::manifest::PluginManifest;
|
||||
|
||||
/// Add-on package entry point (phase 1: in-tree, in-process).
|
||||
///
|
||||
/// One `PluginRegistration` per package — ribbon tab, manifest, and command
|
||||
/// dispatch are owned here. `dispatch` receives `&mut dyn HostApi` (the stable
|
||||
/// `ocs_plugin_api` contract), not the host's concrete session type. See
|
||||
/// `docs/plugin-architecture.md`.
|
||||
pub trait BuiltinPlugin: Send + Sync {
|
||||
fn manifest(&self) -> &'static PluginManifest;
|
||||
fn ribbon(&self) -> Box<dyn CadModule>;
|
||||
fn dispatch(&self, host: &mut dyn HostApi, cmd: &str) -> bool;
|
||||
}
|
||||
/// The stable contract types a plugin targets. `BuiltinPlugin` (the package
|
||||
/// entry point) and `HostApi` (the runtime surface its `dispatch` receives)
|
||||
/// both live in `ocs_plugin_api` so in-tree and out-of-tree add-ons implement
|
||||
/// the same trait. See `docs/plugin-architecture.md`.
|
||||
pub use ocs_plugin_api::host::{BuiltinPlugin, HostApi};
|
||||
Loading…
Reference in a new issue