Skip to content
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
2,983 changes: 1,549 additions & 1,434 deletions Cargo.lock

Large diffs are not rendered by default.

33 changes: 22 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,44 @@ readme = "README.md"

[workspace.dependencies]
anyhow = "1.0.99"
bevy = { version = "0.17.2", features = ["serialize"] }
bevy_reflect = "0.17.2"
bevy_transform = { version = "0.17.2", features = [
bevy_asset = "0.18.0"
bevy_app = "0.18.0"
bevy_derive = "0.18.0"
bevy_ecs = "0.18.0"
bevy_log = "0.18.0"
bevy_math = { version = "0.18.0", features = [
"std",
"serialize",
], default-features = false }
bevy_math = { version = "0.17.2", features = [
"std",
bevy_platform = "0.18.0"
bevy_reflect = "0.18.0"
bevy_transform = { version = "0.18.0", features = [
"serialize",
], default-features = false }
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.143"
thiserror = "2.0.16"
wasmtime = { version = "36.0.2", features = ["component-model"] }
wasmtime-wasi = "36.0.2"
wit-bindgen = { version = "0.46.0", features = ["bitflags"] }
wasmtime = { version = "40.0.1", features = ["component-model"] }
wasmtime-wasi = "40.0.1"
wit-bindgen = { version = "0.50.0", features = ["bitflags"] }

[dependencies]
anyhow.workspace = true
bevy.workspace = true
bevy_app.workspace = true
bevy_asset.workspace = true
bevy_derive.workspace = true
bevy_ecs.workspace = true
bevy_log.workspace = true
bevy_platform.workspace = true
bevy_reflect.workspace = true
serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true
wasmtime.workspace = true
wasmtime-wasi.workspace = true

# Enable high optimizations for wasmtime and its transient dependencies
# Drastically improves the speed loading examples (python especially)
# Enable high optimizations for wasmtime and its transient dependencies in dev mode.
# This drastically improves the loading speed for the example mods (python especially)

# Core Wasmtime + internals
[profile.dev.package.wasmtime-environ]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ serde_json = "1.0"

# Import any bevy-sub crates for any components you will be using
# Note: enable the serialize feature to allow using serde
bevy_transform = { version = "0.17.2", features = ["serialize"], default-features = false }
bevy_math = { version = "0.17.2", features = ["serialize"], default-features = false }
bevy_transform = { version = "0.18.0", features = ["serialize"], default-features = false }
bevy_math = { version = "0.18.0", features = ["serialize"], default-features = false }

[lib]
crate-type = ["cdylib"] # necessary for wasm
Expand Down
11 changes: 6 additions & 5 deletions examples/host_example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ repository.workspace = true
readme.workspace = true

[dependencies]
anyhow.workspace = true
bevy = { version = "0.17.2", features = [
# Replace in your own project:
wasvy = { path = "../../" } # wasvy = "0.0"

bevy = { version = "0.18.0", features = [
"wayland",
"dynamic_linking",
"bevy_dev_tools",
] }
bevy_egui = "0.37.0"
bevy-inspector-egui = "0.34.0"
wasvy = { path = "../../" }
bevy_egui = "0.39.0"
bevy-inspector-egui = "0.36.0"
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
# TODO: submit wkg to nix-packages
wkg = pkgs.rustPlatform.buildRustPackage rec {
pname = "wkg";
version = "0.10.0";
version = "0.13.0";

src = pkgs.fetchFromGitHub {
owner = "bytecodealliance";
repo = "wasm-pkg-tools";
rev = "v${version}";
hash = "sha256-VZ+rUZi6o2onMFxK/BMyi6ZjuDS0taJh5w3r33KCZTU=";
hash = "sha256-6adUBw3jtmEq1y+hdnE7EBMgF5KChXr2MtOiSEPi1Ao=";
};

cargoHash = "sha256-dHhJT/edEYagLQoUcXCLPA4fUJdN9ZoOITLpWAH5p/0=";
cargoHash = "sha256-BAHdOrLrSspSN1WsCtglCOQebI39zw6Byj9EgvU3onA=";

nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ pkgs.openssl ];
Expand Down
8 changes: 3 additions & 5 deletions src/access.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use bevy::{
ecs::{entity::Entity, query::FilteredAccess, world::World},
reflect::Reflect,
};
use bevy_ecs::{prelude::*, query::FilteredAccess};
use bevy_reflect::Reflect;

use crate::prelude::{ModSchedules, Sandbox};

Expand Down Expand Up @@ -35,7 +33,7 @@ impl ModAccess {
/// Returns world access to only the entities granted by this access.
///
/// This is used by Wasvy to build mod systems that don't conflict (can run in parallel) between different accesses.
pub fn filtered_access(&self, world: &mut World) -> FilteredAccess {
pub fn filtered_access(&self, world: &World) -> FilteredAccess {
match self {
Self::Sandbox(entity) => world
.get::<Sandbox>(*entity)
Expand Down
9 changes: 4 additions & 5 deletions src/asset.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use anyhow::{Context, Result, anyhow};
use bevy::{
asset::{Asset, AssetId, AssetLoader, Assets, LoadContext, io::Reader},
ecs::{component::Tick, entity::Entity, world::World},
reflect::TypePath,
};
use bevy_asset::{Asset, AssetId, AssetLoader, Assets, LoadContext, io::Reader};
use bevy_ecs::{change_detection::Tick, prelude::*};
use bevy_reflect::TypePath;
use wasmtime::component::{Component, InstancePre, Val};

use crate::{
Expand Down Expand Up @@ -136,6 +134,7 @@ fn call(
}

/// The bevy [`AssetLoader`] for [`ModAsset`]
#[derive(TypePath)]
pub struct ModAssetLoader {
pub(crate) linker: Linker,
}
Expand Down
62 changes: 51 additions & 11 deletions src/cleanup.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use bevy::ecs::prelude::*;
use bevy_ecs::{
prelude::*,
schedule::{ScheduleCleanupPolicy, ScheduleError},
system::SystemState,
};
use bevy_log::prelude::*;
use bevy_platform::collections::{HashMap, HashSet};

use crate::{mods::ModSystemSet, prelude::ModSchedules};

Expand All @@ -22,17 +28,51 @@ impl Command<()> for DisableSystemSet {
}
}

pub(crate) fn disable_system_sets(
mut messages: MessageReader<DisableSystemSet>,
mut schedules: ResMut<Schedules>,
pub(crate) fn disable_mod_system_sets(
world: &mut World,
param: &mut SystemState<MessageReader<DisableSystemSet>>,
) {
for message in messages.read() {
for schedule in message.schedules.0.iter() {
// Quick and dirty way of ensuring systems sets no longer run
// TODO: Next bevy release, remove systems from the schedule
// See: https://github.com/bevyengine/bevy/pull/20298
let sets = message.set.clone().run_if(|| false);
schedules.configure_sets(schedule.schedule_label(), sets);
let mut messages = param.get_mut(world);

// Collect a map of unique bevy schedule labels and the sets that need to be removed from them
let mut remove = HashMap::new();
for DisableSystemSet { set, schedules } in messages.read() {
for schedule in schedules.0.iter() {
remove
.entry(schedule.schedule_label())
.or_insert(HashSet::new())
.insert(set.clone());
}
}

// Remove sets from each schedule
for (label, sets) in remove {
let mut schedules = world
.get_resource_mut::<Schedules>()
.expect("Running in a bevy App");

// We must remove and then re-add the schedule so we can call remove_systems_in_set with exclusive world access
let Some(mut schedule) = schedules.remove(label) else {
continue;
};

for set in sets {
if let Err(error) = schedule.remove_systems_in_set(
set.clone(),
world,
ScheduleCleanupPolicy::RemoveSetAndSystems,
) {
if !matches!(error, ScheduleError::SetNotFound) {
warn!(
"Unable to remove system set {set:?}. Systems from unloaded mods might still be running!\nError: {error}."
);
}
}
}

world
.get_resource_mut::<Schedules>()
.expect("Running in a bevy App")
.insert(schedule);
}
}
24 changes: 12 additions & 12 deletions src/component.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
use std::{alloc::Layout, any::TypeId};

use anyhow::{Result, anyhow};
use bevy::{
ecs::{
component::{ComponentDescriptor, ComponentId},
reflect::ReflectCommandExt,
world::{FilteredEntityMut, FilteredEntityRef},
},
platform::collections::HashMap,
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::{
component::{ComponentDescriptor, ComponentId},
prelude::*,
reflect::{
ReflectFromPtr,
serde::{TypedReflectDeserializer, TypedReflectSerializer},
},
reflect::ReflectCommandExt,
world::{FilteredEntityMut, FilteredEntityRef},
};
use bevy_platform::collections::HashMap;
use bevy_reflect::{
PartialReflect, Reflect, ReflectFromPtr,
serde::{TypedReflectDeserializer, TypedReflectSerializer},
};
use serde::de::DeserializeSeed;

pub type TypePath = String;

/// Registry for storing the components that are registered from WASM assets.
///
/// Note that this is unique per world, not per app like the [AppTypeRegistry](bevy::ecs::reflect::AppTypeRegistry)
/// Note that this is unique per world, not per app like the [AppTypeRegistry](bevy_ecs::reflect::AppTypeRegistry)
#[derive(Default, Clone, Debug, Resource, Deref, DerefMut)]
pub struct WasmComponentRegistry(HashMap<TypePath, ComponentId>);

Expand Down Expand Up @@ -168,6 +167,7 @@ fn get_wasm_component_id(type_path: &str, world: &mut World) -> ComponentId {
}),
true,
WasmComponent::clone_behavior(),
None,
)
};

Expand Down
3 changes: 2 additions & 1 deletion src/engine.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bevy::prelude::*;
use bevy_derive::Deref;
use bevy_ecs::resource::Resource;

use crate::host::WasmHost;

Expand Down
6 changes: 2 additions & 4 deletions src/host/app.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use anyhow::{Result, bail};
use bevy::{
ecs::schedule::{IntoScheduleConfigs, Schedules},
log::warn,
};
use bevy_ecs::prelude::*;
use bevy_log::prelude::*;
use wasmtime::component::Resource;

use crate::{
Expand Down
3 changes: 2 additions & 1 deletion src/host/commands.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{Result, bail};
use bevy::{ecs::hierarchy::ChildOf, log::trace};
use bevy_ecs::prelude::*;
use bevy_log::prelude::*;
use wasmtime::component::Resource;

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion src/host/component.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{Result, bail};
use bevy::ecs::{entity::Entity, world::FilteredEntityRef};
use bevy_ecs::{prelude::*, world::FilteredEntityRef};
use wasmtime::component::Resource;

use crate::{
Expand Down
8 changes: 3 additions & 5 deletions src/host/query.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use anyhow::{Result, bail};
use bevy::ecs::{
component::ComponentId,
query::{FilteredAccess, QueryBuilder},
system::QueryParamBuilder,
world::{FilteredEntityMut, World},
use bevy_ecs::{
component::ComponentId, prelude::*, query::FilteredAccess, system::QueryParamBuilder,
world::FilteredEntityMut,
};
use wasmtime::component::Resource;

Expand Down
Loading