From 805d50ead47573507948756c6b1ada7b8342dc1b Mon Sep 17 00:00:00 2001 From: Waridley Date: Tue, 1 Sep 2020 19:02:11 -0500 Subject: [PATCH] Feature to disable libloading (#363) esp. helpful for wasm target Made default only for `bevy` crate --- Cargo.toml | 10 +++++++++- crates/bevy_app/Cargo.toml | 5 ++++- crates/bevy_app/src/app_builder.rs | 5 ++++- crates/bevy_app/src/plugin.rs | 2 ++ crates/bevy_core/Cargo.toml | 3 +++ crates/bevy_type_registry/Cargo.toml | 3 +++ 6 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e18cdb2c78f5b..70a986c04f156 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,17 @@ readme = "README.md" exclude = ["assets/**/*", "tools/**/*", ".github/**/*", "crates/**/*"] [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"] 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) png = ["bevy_render/png"] diff --git a/crates/bevy_app/Cargo.toml b/crates/bevy_app/Cargo.toml index 713560ba553fd..649631edff396 100644 --- a/crates/bevy_app/Cargo.toml +++ b/crates/bevy_app/Cargo.toml @@ -9,6 +9,9 @@ repository = "https://github.com/bevyengine/bevy" license = "MIT" keywords = ["bevy"] +[features] +dynamic_plugins = ["libloading"] + [dependencies] # bevy 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" } # other -libloading = "0.6" +libloading = { version = "0.6", optional = true } log = { version = "0.4", features = ["release_max_level_info"] } serde = { version = "1.0", features = ["derive"]} diff --git a/crates/bevy_app/src/app_builder.rs b/crates/bevy_app/src/app_builder.rs index f83e5f8beeaee..1ec4f0a837134 100644 --- a/crates/bevy_app/src/app_builder.rs +++ b/crates/bevy_app/src/app_builder.rs @@ -1,7 +1,9 @@ +#[cfg(feature = "dynamic_plugins")] +use crate::plugin::dynamically_load_plugin; use crate::{ app::{App, AppExit}, event::Events, - plugin::{dynamically_load_plugin, Plugin}, + plugin::Plugin, stage, startup_stage, }; use bevy_ecs::{FromResources, IntoQuerySystem, Resources, System, World}; @@ -220,6 +222,7 @@ impl AppBuilder { self } + #[cfg(feature = "dynamic_plugins")] pub fn load_plugin(&mut self, path: &str) -> &mut Self { let (_lib, plugin) = dynamically_load_plugin(path); log::debug!("loaded plugin: {}", plugin.name()); diff --git a/crates/bevy_app/src/plugin.rs b/crates/bevy_app/src/plugin.rs index 628ac5f8d2b91..d97a7be21a11c 100644 --- a/crates/bevy_app/src/plugin.rs +++ b/crates/bevy_app/src/plugin.rs @@ -1,4 +1,5 @@ use crate::AppBuilder; +#[cfg(feature = "dynamic_plugins")] use libloading::{Library, Symbol}; use std::any::Any; @@ -14,6 +15,7 @@ pub trait Plugin: Any + Send + Sync { 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. pub fn dynamically_load_plugin(path: &str) -> (Library, Box) { let lib = Library::new(path).unwrap(); diff --git a/crates/bevy_core/Cargo.toml b/crates/bevy_core/Cargo.toml index 12c84f6ef0e24..de398c21d9478 100644 --- a/crates/bevy_core/Cargo.toml +++ b/crates/bevy_core/Cargo.toml @@ -9,6 +9,9 @@ repository = "https://github.com/bevyengine/bevy" license = "MIT" keywords = ["bevy"] +[features] +dynamic_plugins = ["bevy_app/dynamic_plugins", "bevy_type_registry/dynamic_plugins"] + [dependencies] bevy_app = { path = "../bevy_app", version = "0.1" } bevy_derive = { path = "../bevy_derive", version = "0.1" } diff --git a/crates/bevy_type_registry/Cargo.toml b/crates/bevy_type_registry/Cargo.toml index 011647736bd3a..2642ceb2fcdb4 100644 --- a/crates/bevy_type_registry/Cargo.toml +++ b/crates/bevy_type_registry/Cargo.toml @@ -9,6 +9,9 @@ repository = "https://github.com/bevyengine/bevy" license = "MIT" keywords = ["bevy"] +[features] +dynamic_plugins = ["bevy_app/dynamic_plugins"] + [dependencies] # bevy bevy_app = { path = "../bevy_app", version = "0.1" }