Skip to content

Commit

Permalink
Feature to disable libloading (#363)
Browse files Browse the repository at this point in the history
esp. helpful for wasm target
Made default only for `bevy` crate
  • Loading branch information
Waridley authored Sep 2, 2020
1 parent 3d6d243 commit 4e587db
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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"]}
5 changes: 4 additions & 1 deletion crates/bevy_app/src/app_builder.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_app/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::AppBuilder;
#[cfg(feature = "dynamic_plugins")]
use libloading::{Library, Symbol};
use std::any::Any;

Expand All @@ -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<dyn Plugin>) {
let lib = Library::new(path).unwrap();
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_type_registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down

0 comments on commit 4e587db

Please sign in to comment.