forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move dynamic plugin loading to its own optional crate (bevyengine#544)
move dynamic plugin loading to its own crate
- Loading branch information
1 parent
1023f6c
commit cbeaec1
Showing
12 changed files
with
63 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "bevy_dynamic_plugin" | ||
version = "0.2.1" | ||
authors = [ | ||
"Bevy Contributors <[email protected]>", | ||
"Carter Anderson <[email protected]>", | ||
] | ||
edition = "2018" | ||
description = "Provides dynamic plugin loading capabilities for non-wasm platforms" | ||
homepage = "https://bevyengine.org" | ||
repository = "https://github.com/bevyengine/bevy" | ||
license = "MIT" | ||
keywords = ["bevy"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
# bevy | ||
bevy_app = { path = "../bevy_app", version = "0.2.1" } | ||
|
||
# other | ||
log = { version = "0.4", features = ["release_max_level_info"] } | ||
libloading = { version = "0.6" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod loader; | ||
|
||
pub use loader::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use libloading::{Library, Symbol}; | ||
|
||
use bevy_app::{AppBuilder, CreatePlugin, Plugin}; | ||
|
||
/// Dynamically links a plugin a the given path. The plugin must export the [CreatePlugin] function. | ||
pub fn dynamically_load_plugin(path: &str) -> (Library, Box<dyn Plugin>) { | ||
let lib = Library::new(path).unwrap(); | ||
|
||
unsafe { | ||
let func: Symbol<CreatePlugin> = lib.get(b"_create_plugin").unwrap(); | ||
let plugin = Box::from_raw(func()); | ||
(lib, plugin) | ||
} | ||
} | ||
|
||
pub trait DynamicPluginExt { | ||
fn load_plugin(&mut self, path: &str) -> &mut Self; | ||
} | ||
|
||
impl DynamicPluginExt for AppBuilder { | ||
fn load_plugin(&mut self, path: &str) -> &mut Self { | ||
let (_lib, plugin) = dynamically_load_plugin(path); | ||
log::debug!("loaded plugin: {}", plugin.name()); | ||
plugin.build(self); | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters