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

[Merged by Bors] - Adapt path type of dynamically_load_plugin #6734

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions crates/bevy_dynamic_plugin/src/loader.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use libloading::{Library, Symbol};
use std::ffi::OsStr;
use thiserror::Error;

use bevy_app::{App, CreatePlugin, Plugin};
Expand All @@ -20,8 +21,8 @@ pub enum DynamicPluginLoadError {
/// The specified plugin must be linked against the exact same libbevy.so as this program.
/// In addition the `_bevy_create_plugin` symbol must not be manually created, but instead created
/// by deriving `DynamicPlugin` on a unit struct implementing [`Plugin`].
pub unsafe fn dynamically_load_plugin(
path: &str,
pub unsafe fn dynamically_load_plugin<P: AsRef<OsStr>>(
path: P,
) -> Result<(Library, Box<dyn Plugin>), DynamicPluginLoadError> {
let lib = Library::new(path).map_err(DynamicPluginLoadError::Library)?;
let func: Symbol<CreatePlugin> = lib
Expand All @@ -35,11 +36,11 @@ pub trait DynamicPluginExt {
/// # Safety
///
/// Same as [`dynamically_load_plugin`].
unsafe fn load_plugin(&mut self, path: &str) -> &mut Self;
unsafe fn load_plugin<P: AsRef<OsStr>>(&mut self, path: P) -> &mut Self;
}

impl DynamicPluginExt for App {
unsafe fn load_plugin(&mut self, path: &str) -> &mut Self {
unsafe fn load_plugin<P: AsRef<OsStr>>(&mut self, path: P) -> &mut Self {
let (lib, plugin) = dynamically_load_plugin(path).unwrap();
std::mem::forget(lib); // Ensure that the library is not automatically unloaded
plugin.build(self);
Expand Down