Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin system (fixes #3562) #5498

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open

Add plugin system (fixes #3562) #5498

wants to merge 36 commits into from

Conversation

Nutomic
Copy link
Member

@Nutomic Nutomic commented Mar 12, 2025

See LemmyNet/rfcs#8 and #4695. Depends on a work in progress feature of Extism to add plugin pools for concurrency (extism/extism#696).

Todo:

  • Include details about loaded plugins in /api/v4/site
  • Update file structure and metadata details in RFC based on actual implementation
  • Create repo with example plugins
  • Write more example plugins in different languages

@Nutomic Nutomic force-pushed the plugin-system2 branch 2 times, most recently from a21ede2 to 2216744 Compare March 12, 2025 11:42
@Nutomic Nutomic marked this pull request as ready for review March 18, 2025 09:09
@Nutomic
Copy link
Member Author

Nutomic commented Mar 24, 2025

This and the RFC are ready to merge, so that devs can already start to work on plugins.

Comment on lines +34 to +46
for p in plugins.0 {
// TODO: add helper method (requires PoolPlugin to be public)
// https://github.com/extism/extism/pull/696/files#r2003467812
let p = p
.plugin_pool
.get(&(), GET_PLUGIN_TIMEOUT)?
.ok_or(anyhow!("plugin timeout"))?;
if p.plugin().function_exists(name) {
let params: Json<T> = data.clone().into();
p.call::<Json<T>, ()>(name, params)
.map_err(|e| LemmyErrorType::PluginError(e.to_string()))?;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you externalize this to a function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not, because the PoolPlugin type is not public (thats what the todo is for, I left a review comment in the upstream PR so it will hopefully get fixed later). The plugin call can also not be externalized, because the pre hook needs to return data but the post hook not.

*data = res;
let mut plugins = LemmyPlugins::init();
let mut res: Json<T> = data.clone().into();
for p in &mut plugins.0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then no need to copy paste.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants