Skip to content

Commit 0d5879c

Browse files
committed
Feature to disable libloading
esp. helpful for wasm target
1 parent 93040ef commit 0d5879c

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

crates/bevy_app/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ repository = "https://github.com/bevyengine/bevy"
99
license = "MIT"
1010
keywords = ["bevy"]
1111

12+
[features]
13+
default = ["dynamic_plugins"]
14+
dynamic_plugins = ["libloading"]
15+
1216
[dependencies]
1317
# bevy
1418
bevy_derive = { path = "../bevy_derive", version = "0.1" }
1519
bevy_ecs = { path = "../bevy_ecs", version = "0.1" }
1620

1721
# other
18-
libloading = "0.6"
22+
libloading = { version = "0.6", optional = true }
1923
log = { version = "0.4", features = ["release_max_level_info"] }
2024
serde = { version = "1.0", features = ["derive"]}

crates/bevy_app/src/app_builder.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
#[cfg(feature = "dynamic_plugins")]
2+
use crate::plugin::dynamically_load_plugin;
13
use crate::{
24
app::{App, AppExit},
35
event::Events,
4-
plugin::{dynamically_load_plugin, Plugin},
6+
plugin::Plugin,
57
stage, startup_stage,
68
};
79
use bevy_ecs::{FromResources, IntoQuerySystem, Resources, System, World};
@@ -220,6 +222,7 @@ impl AppBuilder {
220222
self
221223
}
222224

225+
#[cfg(feature = "dynamic_plugins")]
223226
pub fn load_plugin(&mut self, path: &str) -> &mut Self {
224227
let (_lib, plugin) = dynamically_load_plugin(path);
225228
log::debug!("loaded plugin: {}", plugin.name());

crates/bevy_app/src/plugin.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::AppBuilder;
2+
#[cfg(feature = "dynamic_plugins")]
23
use libloading::{Library, Symbol};
34
use std::any::Any;
45

@@ -14,6 +15,7 @@ pub trait Plugin: Any + Send + Sync {
1415

1516
pub type CreatePlugin = unsafe fn() -> *mut dyn Plugin;
1617

18+
#[cfg(feature = "dynamic_plugins")]
1719
/// Dynamically links a plugin a the given path. The plugin must export the [CreatePlugin] function.
1820
pub fn dynamically_load_plugin(path: &str) -> (Library, Box<dyn Plugin>) {
1921
let lib = Library::new(path).unwrap();

crates/bevy_core/Cargo.toml

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ repository = "https://github.com/bevyengine/bevy"
99
license = "MIT"
1010
keywords = ["bevy"]
1111

12+
[features]
13+
default = ["dynamic_plugins"]
14+
dynamic_plugins = ["bevy_app/dynamic_plugins", "bevy_type_registry/dynamic_plugins"]
15+
1216
[dependencies]
13-
bevy_app = { path = "../bevy_app", version = "0.1" }
17+
bevy_app = { path = "../bevy_app", version = "0.1", default_features = false }
1418
bevy_derive = { path = "../bevy_derive", version = "0.1" }
1519
bevy_ecs = { path = "../bevy_ecs", version = "0.1" }
1620
bevy_property = { path = "../bevy_property", version = "0.1" }
17-
bevy_type_registry = { path = "../bevy_type_registry", version = "0.1" }
21+
bevy_type_registry = { path = "../bevy_type_registry", version = "0.1", default_features = false }
1822
bevy_math = { path = "../bevy_math", version = "0.1" }

crates/bevy_type_registry/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ repository = "https://github.com/bevyengine/bevy"
99
license = "MIT"
1010
keywords = ["bevy"]
1111

12+
[features]
13+
default = ["dynamic_plugins"]
14+
dynamic_plugins = ["bevy_app/dynamic_plugins"]
15+
1216
[dependencies]
1317
# bevy
14-
bevy_app = { path = "../bevy_app", version = "0.1" }
18+
bevy_app = { path = "../bevy_app", version = "0.1", default_features = false }
1519
bevy_ecs = { path = "../bevy_ecs", version = "0.1" }
1620
bevy_property = { path = "../bevy_property", version = "0.1" }
1721

0 commit comments

Comments
 (0)