From 248837408ff9aac7a539ff7d1201252e76496ad8 Mon Sep 17 00:00:00 2001 From: core Date: Wed, 19 Nov 2025 14:25:12 -0500 Subject: [PATCH] fix: wasm --- Cargo.lock | 122 +++++++------------------- crates/unified/Cargo.toml | 15 ++-- crates/unified/src/main.rs | 18 +++- crates/unified/src/wasm_entrypoint.rs | 15 +++- crates/xtask/src/main.rs | 11 ++- 5 files changed, 76 insertions(+), 105 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 57c7802ce906493b4829b468b23dc3ccbb33a403..c5032e1c81638caa2890c8bb7e738c556a0336e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -819,55 +819,6 @@ dependencies = [ "bevy_internal", ] -[[package]] -name = "bevy-inspector-egui" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3692cbc0a76398ee01dde2c49951c8a92c5373c58e8720a0909e9504d21e9ab" -dependencies = [ - "bevy-inspector-egui-derive", - "bevy_app", - "bevy_asset", - "bevy_camera", - "bevy_color", - "bevy_core_pipeline", - "bevy_ecs", - "bevy_egui", - "bevy_image", - "bevy_light", - "bevy_log", - "bevy_math", - "bevy_mesh", - "bevy_pbr", - "bevy_platform", - "bevy_reflect", - "bevy_render", - "bevy_state", - "bevy_time", - "bevy_utils", - "bevy_window", - "bytemuck", - "disqualified", - "egui 0.33.2", - "fuzzy-matcher", - "image", - "opener", - "smallvec", - "uuid", - "winit", -] - -[[package]] -name = "bevy-inspector-egui-derive" -version = "0.35.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9569b1caad44483de562c6115c773d4311374d1740f5e6e69413d92206363c3" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "bevy_a11y" version = "0.17.2" @@ -1377,6 +1328,7 @@ dependencies = [ "bevy_log", "bevy_math", "bevy_mesh", + "bevy_pbr", "bevy_picking", "bevy_platform", "bevy_post_process", @@ -2199,17 +2151,6 @@ dependencies = [ "piper", ] -[[package]] -name = "bstr" -version = "1.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63044e1ae8e69f3b5a92c736ca6269b8d12fa7efe39bf34ddb06d102cf0e2cab" -dependencies = [ - "memchr", - "regex-automata", - "serde", -] - [[package]] name = "bumpalo" version = "3.19.0" @@ -3951,15 +3892,6 @@ dependencies = [ "slab", ] -[[package]] -name = "fuzzy-matcher" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54614a3312934d066701a80f20f15fa3b56d67ac7722b39eea5b4c9dd1d66c94" -dependencies = [ - "thread_local", -] - [[package]] name = "generational-box" version = "0.7.1" @@ -5308,15 +5240,6 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "610a5acd306ec67f907abe5567859a3c693fb9886eb1f012ab8f2a47bef3db51" -[[package]] -name = "normpath" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf23ab2b905654b4cb177e30b629937b3868311d4e1cba859f899c041046e69b" -dependencies = [ - "windows-sys 0.61.2", -] - [[package]] name = "notify" version = "7.0.0" @@ -5904,17 +5827,6 @@ version = "11.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" -[[package]] -name = "opener" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb9024962ab91e00c89d2a14352a8d0fc1a64346bf96f1839b45c09149564e47" -dependencies = [ - "bstr", - "normpath", - "windows-sys 0.60.2", -] - [[package]] name = "openssl-probe" version = "0.1.6" @@ -7363,7 +7275,6 @@ dependencies = [ "aeronet_websocket", "avian2d", "bevy", - "bevy-inspector-egui", "bevy_common_assets", "bevy_egui", "bevy_replicon", @@ -7379,6 +7290,7 @@ dependencies = [ "tracing-wasm", "url", "wasm-bindgen", + "wgpu 25.0.2", ] [[package]] @@ -8669,6 +8581,7 @@ dependencies = [ "cfg_aliases", "document-features", "hashbrown 0.15.5", + "js-sys", "log", "naga 26.0.0", "portable-atomic", @@ -8676,6 +8589,8 @@ dependencies = [ "raw-window-handle", "smallvec", "static_assertions", + "wasm-bindgen", + "web-sys", "wgpu-core 26.0.1", "wgpu-hal 26.0.6", "wgpu-types 26.0.0", @@ -8707,6 +8622,7 @@ dependencies = [ "thiserror 2.0.17", "wgpu-core-deps-apple 25.0.0", "wgpu-core-deps-emscripten", + "wgpu-core-deps-wasm 25.0.0", "wgpu-core-deps-windows-linux-android 25.0.0", "wgpu-hal 25.0.2", "wgpu-types 25.0.0", @@ -8737,6 +8653,7 @@ dependencies = [ "smallvec", "thiserror 2.0.17", "wgpu-core-deps-apple 26.0.0", + "wgpu-core-deps-wasm 26.0.0", "wgpu-core-deps-windows-linux-android 26.0.0", "wgpu-hal 26.0.6", "wgpu-types 26.0.0", @@ -8769,6 +8686,24 @@ dependencies = [ "wgpu-hal 25.0.2", ] +[[package]] +name = "wgpu-core-deps-wasm" +version = "25.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eca8809ad123f6c7f2c5e01a2c7117c4fdfd02f70bd422ee2533f69dfa98756c" +dependencies = [ + "wgpu-hal 25.0.2", +] + +[[package]] +name = "wgpu-core-deps-wasm" +version = "26.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c03b9f9e1a50686d315fc6debe4980cc45cd37b0e919351917df494e8fdc8885" +dependencies = [ + "wgpu-hal 26.0.6", +] + [[package]] name = "wgpu-core-deps-windows-linux-android" version = "25.0.0" @@ -8850,15 +8785,20 @@ dependencies = [ "cfg-if", "cfg_aliases", "core-graphics-types 0.2.0", + "glow", + "glutin_wgl_sys", "gpu-alloc", "gpu-allocator", "gpu-descriptor", "hashbrown 0.15.5", + "js-sys", + "khronos-egl", "libc", "libloading", "log", "metal 0.32.0", "naga 26.0.0", + "ndk-sys 0.6.0+11769913", "objc", "ordered-float 4.6.0", "parking_lot", @@ -8870,6 +8810,8 @@ dependencies = [ "renderdoc-sys", "smallvec", "thiserror 2.0.17", + "wasm-bindgen", + "web-sys", "wgpu-types 26.0.0", "windows 0.58.0", "windows-core 0.58.0", diff --git a/crates/unified/Cargo.toml b/crates/unified/Cargo.toml index b6b54f999ffcfad43e0023a05be00dce4c36467f..57ebf52e9aa4a4155fc78e5dd7b8861861c32e24 100644 --- a/crates/unified/Cargo.toml +++ b/crates/unified/Cargo.toml @@ -9,8 +9,6 @@ version = "0.1.0" [dependencies] bevy = { version = "0.17", default-features = false, features = [ - "hotpatching", - "dynamic_linking", "serialize", "tonemapping_luts", "bevy_window", @@ -35,7 +33,8 @@ bevy = { version = "0.17", default-features = false, features = [ "bevy_post_process", "bevy_anti_alias", "bevy_sprite_render", - "bevy_ui_render" + "bevy_ui_render", + "webgl2" ] } #bevy_rapier2d = { features = ["serde-serialize", "simd-stable"], git = "https://github.com/Deniskore/bevy_rapier", branch = "bevy-0.17" } @@ -75,9 +74,9 @@ bevy_egui = "0.38" ordered-float = { version = "5", features = ["serde"] } ron = "0.12" -ctrlc = "3.5" +ctrlc = { version = "3.5", optional = true } -bevy-inspector-egui = "0.35" +wgpu = "*" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] @@ -90,8 +89,12 @@ console_error_panic_hook = "0.1" default = ["native", "particle_editor"] native = [ "bevy/file_watcher", + "bevy/hotpatching", + "bevy/dynamic_linking", "aeronet_websocket/server", - "aeronet_replicon/server" + "aeronet_replicon/server", + "ctrlc", + "wgpu/webgl" ] wasm = ["getrandom/wasm_js"] particle_editor = [] diff --git a/crates/unified/src/main.rs b/crates/unified/src/main.rs index 6eae49b2a80c866d480260e5bdf646801f2fc401..0ac024c77fe8dea16ca12a10e64baaef9dfb2aec 100644 --- a/crates/unified/src/main.rs +++ b/crates/unified/src/main.rs @@ -168,6 +168,12 @@ fn run(cli: Cli) -> AppExit { app.run() } +#[cfg(feature = "wasm")] +fn main() { + // noop +} + +#[cfg(feature = "native")] fn main() -> AppExit { let cli = Cli::parse(); @@ -178,14 +184,18 @@ fn main() -> AppExit { .finish() .init(); - ctrlc::set_handler(|| { - info!("caught ^C, ciao!"); - exit(0); - }).unwrap(); + #[cfg(feature = "native")] { + ctrlc::set_handler(|| { + info!("caught ^C, ciao!"); + exit(0); + }).unwrap(); + } match cli { Cli::Client { .. } => { run(cli) }, + #[cfg(feature = "native")] Cli::ParticleEditor { .. } => { run(cli) }, + #[cfg(feature = "native")] Cli::Server { with_client, bind, hotpatching_enabled, .. } => { run(cli) /* diff --git a/crates/unified/src/wasm_entrypoint.rs b/crates/unified/src/wasm_entrypoint.rs index deca128804da9ed87e3c573c7b58264250a0e4f0..6580a583648a752bea013148bccfe32ffe3c4234 100644 --- a/crates/unified/src/wasm_entrypoint.rs +++ b/crates/unified/src/wasm_entrypoint.rs @@ -3,16 +3,29 @@ use crate::shared_plugins::SharedPluginGroup; use aeronet_websocket::client::WebSocketClient; use bevy::app::{App, Startup}; use url::Url; +use bevy::log::LogPlugin; +use bevy::ui::UiPlugin; +use bevy::DefaultPlugins; use wasm_bindgen::prelude::*; +use bevy::prelude::PluginGroup; #[wasm_bindgen] pub fn play(server: &str) -> Result<(), JsValue> { console_error_panic_hook::set_once(); tracing_wasm::set_as_global_default(); + for instance in wgpu::Instance::enabled_backend_features().iter_names() { + bevy::log::debug!(?instance, "available backend"); + } + let mut app = App::new(); + app.add_plugins( + DefaultPlugins.build() + .disable::() + .disable::() + ); app.add_plugins(ClientPluginGroup { - server: server.to_string(), + server: Some(server.to_string()), }); app.add_plugins(SharedPluginGroup); diff --git a/crates/xtask/src/main.rs b/crates/xtask/src/main.rs index 2798e573917e32cafe384132635a814d7f05eea6..e0abba49e3ab778395a8a2040a4ccd35e6d7c347 100644 --- a/crates/xtask/src/main.rs +++ b/crates/xtask/src/main.rs @@ -1,3 +1,5 @@ +#![feature(exit_status_error)] + use colored::Colorize; use notify::{Event, EventKind, RecursiveMode, Watcher}; use std::env::{args, var}; @@ -85,7 +87,7 @@ fn start_server() { let path = path.strip_prefix(Path::new("/")).unwrap(); - let full_path = workspace_dir().join("crates/client").join(path); + let full_path = workspace_dir().join("crates/unified").join(path); let content = match fs::read(full_path.clone()) { Ok(r) => r, @@ -170,7 +172,7 @@ fn main() { std::thread::spawn(start_server); } - try_build_client(); + //try_build_client(); let (tx, rx) = mpsc::channel::>(); // Use recommended_watcher() to automatically select the best implementation @@ -293,7 +295,7 @@ fn main() { let start = Instant::now(); let target = workspace_dir().join("target/"); let unified = workspace_dir().join("crates/unified/"); - exec("cargo", "build --package starkingdoms --lib --target wasm32-unknown-unknown -F wasm --no-default-features"); + exec("cargo", "build --package starkingdoms --target wasm32-unknown-unknown -F wasm --no-default-features"); let wasm_file = target.join("wasm32-unknown-unknown/debug/starkingdoms.wasm"); exec( "wasm-bindgen", @@ -353,5 +355,6 @@ fn exec(program: &str, args: &str) { .spawn() .unwrap() .wait() - .unwrap(); + .unwrap() + .exit_ok().unwrap(); }