Feature to disable libloading (#363)

esp. helpful for wasm target
Made default only for `bevy` crate
This commit is contained in:
Waridley 2020-09-01 19:02:11 -05:00 committed by GitHub
parent 3d6d2431fe
commit 4e587db775
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 3 deletions

View file

@ -13,9 +13,17 @@ readme = "README.md"
exclude = ["assets/**/*", "tools/**/*", ".github/**/*", "crates/**/*"] exclude = ["assets/**/*", "tools/**/*", ".github/**/*", "crates/**/*"]
[features] [features]
default = ["bevy_audio", "bevy_gltf", "bevy_wgpu", "bevy_winit", "png", "hdr", "mp3", "x11"] default = [
"bevy_audio", "bevy_gltf", "bevy_wgpu", "bevy_winit",
"dynamic_plugins", "png", "hdr", "mp3", "x11"
]
profiler = ["bevy_ecs/profiler", "bevy_diagnostic/profiler"] profiler = ["bevy_ecs/profiler", "bevy_diagnostic/profiler"]
wgpu_trace = ["bevy_wgpu/trace"] wgpu_trace = ["bevy_wgpu/trace"]
dynamic_plugins = [
"bevy_core/dynamic_plugins",
"bevy_app/dynamic_plugins",
"bevy_type_registry/dynamic_plugins",
]
# Image format support for texture loading (PNG and HDR are enabled by default) # Image format support for texture loading (PNG and HDR are enabled by default)
png = ["bevy_render/png"] png = ["bevy_render/png"]

View file

@ -9,6 +9,9 @@ repository = "https://github.com/bevyengine/bevy"
license = "MIT" license = "MIT"
keywords = ["bevy"] keywords = ["bevy"]
[features]
dynamic_plugins = ["libloading"]
[dependencies] [dependencies]
# bevy # bevy
bevy_derive = { path = "../bevy_derive", version = "0.1" } bevy_derive = { path = "../bevy_derive", version = "0.1" }
@ -17,6 +20,6 @@ bevy_tasks = { path = "../bevy_tasks", version = "0.1" }
bevy_math = { path = "../bevy_math", version = "0.1" } bevy_math = { path = "../bevy_math", version = "0.1" }
# other # other
libloading = "0.6" libloading = { version = "0.6", optional = true }
log = { version = "0.4", features = ["release_max_level_info"] } log = { version = "0.4", features = ["release_max_level_info"] }
serde = { version = "1.0", features = ["derive"]} serde = { version = "1.0", features = ["derive"]}

View file

@ -1,7 +1,9 @@
#[cfg(feature = "dynamic_plugins")]
use crate::plugin::dynamically_load_plugin;
use crate::{ use crate::{
app::{App, AppExit}, app::{App, AppExit},
event::Events, event::Events,
plugin::{dynamically_load_plugin, Plugin}, plugin::Plugin,
stage, startup_stage, stage, startup_stage,
}; };
use bevy_ecs::{FromResources, IntoQuerySystem, Resources, System, World}; use bevy_ecs::{FromResources, IntoQuerySystem, Resources, System, World};
@ -220,6 +222,7 @@ impl AppBuilder {
self self
} }
#[cfg(feature = "dynamic_plugins")]
pub fn load_plugin(&mut self, path: &str) -> &mut Self { pub fn load_plugin(&mut self, path: &str) -> &mut Self {
let (_lib, plugin) = dynamically_load_plugin(path); let (_lib, plugin) = dynamically_load_plugin(path);
log::debug!("loaded plugin: {}", plugin.name()); log::debug!("loaded plugin: {}", plugin.name());

View file

@ -1,4 +1,5 @@
use crate::AppBuilder; use crate::AppBuilder;
#[cfg(feature = "dynamic_plugins")]
use libloading::{Library, Symbol}; use libloading::{Library, Symbol};
use std::any::Any; use std::any::Any;
@ -14,6 +15,7 @@ pub trait Plugin: Any + Send + Sync {
pub type CreatePlugin = unsafe fn() -> *mut dyn Plugin; pub type CreatePlugin = unsafe fn() -> *mut dyn Plugin;
#[cfg(feature = "dynamic_plugins")]
/// Dynamically links a plugin a the given path. The plugin must export the [CreatePlugin] function. /// 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>) { pub fn dynamically_load_plugin(path: &str) -> (Library, Box<dyn Plugin>) {
let lib = Library::new(path).unwrap(); let lib = Library::new(path).unwrap();

View file

@ -9,6 +9,9 @@ repository = "https://github.com/bevyengine/bevy"
license = "MIT" license = "MIT"
keywords = ["bevy"] keywords = ["bevy"]
[features]
dynamic_plugins = ["bevy_app/dynamic_plugins", "bevy_type_registry/dynamic_plugins"]
[dependencies] [dependencies]
bevy_app = { path = "../bevy_app", version = "0.1" } bevy_app = { path = "../bevy_app", version = "0.1" }
bevy_derive = { path = "../bevy_derive", version = "0.1" } bevy_derive = { path = "../bevy_derive", version = "0.1" }

View file

@ -9,6 +9,9 @@ repository = "https://github.com/bevyengine/bevy"
license = "MIT" license = "MIT"
keywords = ["bevy"] keywords = ["bevy"]
[features]
dynamic_plugins = ["bevy_app/dynamic_plugins"]
[dependencies] [dependencies]
# bevy # bevy
bevy_app = { path = "../bevy_app", version = "0.1" } bevy_app = { path = "../bevy_app", version = "0.1" }