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

Feature to disable libloading (helpful for WASM support) #363

Merged
merged 1 commit into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
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
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,12 +9,15 @@ repository = "https://github.com/bevyengine/bevy"
license = "MIT"
keywords = ["bevy"]

[features]
dynamic_plugins = ["libloading"]

[dependencies]
# bevy
bevy_derive = { path = "../bevy_derive", version = "0.1" }
bevy_ecs = { path = "../bevy_ecs", 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