Skip to content

Add plugin system (fixes #3562) #5498

Merged
Nutomic merged 36 commits intomainfrom
plugin-system2
Mar 28, 2025
Merged

Add plugin system (fixes #3562) #5498
Nutomic merged 36 commits intomainfrom
plugin-system2

Conversation

@Nutomic
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@Nutomic Nutomic merged commit 4556a94 into main Mar 28, 2025
2 checks passed
@Nothing4You Nothing4You deleted the plugin-system2 branch September 11, 2025 17:34
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