From 0c2583294a95d3ce0dc6dcfdd2852425f0463f75 Mon Sep 17 00:00:00 2001 From: Daniel Bengl Date: Fri, 28 Mar 2025 20:26:52 +0100 Subject: [PATCH] Attempt add WASM --- Cargo.lock | 6 ++++ Cargo.toml | 32 ++++++++++++++++++- build/wasm/index.html | 72 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 build/wasm/index.html diff --git a/Cargo.lock b/Cargo.lock index d3ef22d..06525ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4482,8 +4482,11 @@ dependencies = [ "bincode", "cgmath", "chrono", + "console_error_panic_hook", "egui_plot", + "getrandom 0.2.15", "iyes_perf_ui", + "js-sys", "noise", "rand 0.9.0", "rayon", @@ -4491,6 +4494,9 @@ dependencies = [ "renet_visualizer", "serde", "serde-big-array", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index bd618c4..c603ca4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" rust-version = "1.83.0" [dependencies] -bevy = "0.15.1" +bevy = { version = "0.15.1", features = ["wayland"] } bevy_fps_controller = "0.15.0" bevy_mod_raycast = { git = "https://github.com/CuddlyBunion341/bevy_mod_raycast.git", branch = "main" } bevy_rapier3d = "0.28.0" @@ -26,6 +26,20 @@ renet_visualizer = { git = "https://github.com/CuddlyBunion341/renet.git", featu "bevy", ] } egui_plot = "0.30.0" +getrandom = { version = "0.2", features = ["js"] } + +# WASM specific dependencies +[target.'cfg(target_arch = "wasm32")'.dependencies] +console_error_panic_hook = "0.1.7" +wasm-bindgen = "0.2.92" +wasm-bindgen-futures = "0.4.42" +web-sys = { version = "0.3.69", features = [ + "Document", + "Window", + "Element", + "Location", +]} +js-sys = "0.3.69" [profile.dev.package."*"] opt-level = 3 @@ -33,6 +47,13 @@ opt-level = 3 [profile.release] opt-level = 3 +# WASM optimizations +[profile.wasm-release] +inherits = "release" +opt-level = "z" # Optimize for size +lto = true # Link Time Optimization +codegen-units = 1 # More effective optimizations + [[bin]] name = "client" path = "src/client/main.rs" @@ -41,6 +62,12 @@ path = "src/client/main.rs" name = "server" path = "src/server/main.rs" +# For WASM builds +[lib] +name = "rsmc_wasm" +crate-type = ["cdylib", "rlib"] +path = "src/wasm/lib.rs" + [features] default = ["chat"] dynamic_linking = ["bevy/dynamic_linking"] @@ -63,3 +90,6 @@ physics_debug = [] raycast_debug = [] skip_terrain = [] visual_debug = ["wireframe", "physics_debug", "raycast_debug"] + +# wasm +wasm = ["bevy/webgl2"] diff --git a/build/wasm/index.html b/build/wasm/index.html new file mode 100644 index 0000000..7724889 --- /dev/null +++ b/build/wasm/index.html @@ -0,0 +1,72 @@ + + + + + + RSMC Web + + + +
Loading...
+ +
+

RSMC Web Version

+
+ + + + \ No newline at end of file