Fix WASM build

This commit is contained in:
Pascal Engélibert 2022-08-24 11:31:17 +02:00
parent 972cd26876
commit ce37ddd0bd
7 changed files with 38 additions and 203 deletions

176
Cargo.lock generated
View file

@ -1301,121 +1301,6 @@ dependencies = [
"windows",
]
[[package]]
name = "cranelift"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd96bba738454eb373087df6d6891b18009361123fef90930def4978e3837448"
dependencies = [
"cranelift-codegen",
"cranelift-frontend",
]
[[package]]
name = "cranelift-bforest"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "529ffacce2249ac60edba2941672dfedf3d96558b415d0d8083cd007456e0f55"
dependencies = [
"cranelift-entity",
]
[[package]]
name = "cranelift-codegen"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "427d105f617efc8cb55f8d036a7fded2e227892d8780b4985e5551f8d27c4a92"
dependencies = [
"cranelift-bforest",
"cranelift-codegen-meta",
"cranelift-codegen-shared",
"cranelift-entity",
"cranelift-isle",
"gimli",
"log",
"regalloc2",
"smallvec",
"target-lexicon",
]
[[package]]
name = "cranelift-codegen-meta"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "551674bed85b838d45358e3eab4f0ffaa6790c70dc08184204b9a54b41cdb7d1"
dependencies = [
"cranelift-codegen-shared",
]
[[package]]
name = "cranelift-codegen-shared"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b3a63ae57498c3eb495360944a33571754241e15e47e3bcae6082f40fec5866"
[[package]]
name = "cranelift-entity"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11aa8aa624c72cc1c94ea3d0739fa61248260b5b14d3646f51593a88d67f3e6e"
[[package]]
name = "cranelift-frontend"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "544ee8f4d1c9559c9aa6d46e7aaeac4a13856d620561094f35527356c7d21bd0"
dependencies = [
"cranelift-codegen",
"log",
"smallvec",
"target-lexicon",
]
[[package]]
name = "cranelift-isle"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed16b14363d929b8c37e3c557d0a7396791b383ecc302141643c054343170aad"
[[package]]
name = "cranelift-jit"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0308e7418208639fb96c1a3dc04955fa41c4bc92dfce9106635185f71d5caf46"
dependencies = [
"anyhow",
"cranelift-codegen",
"cranelift-entity",
"cranelift-module",
"cranelift-native",
"libc",
"log",
"region",
"target-lexicon",
"windows-sys",
]
[[package]]
name = "cranelift-module"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76979aac10dbcf0c222cd5902565bc93597ac30bbe9d879a2aa5f2402d1561f2"
dependencies = [
"anyhow",
"cranelift-codegen",
]
[[package]]
name = "cranelift-native"
version = "0.86.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51617cf8744634f2ed3c989c3c40cd6444f63377c6d994adab0d85807f3eb682"
dependencies = [
"cranelift-codegen",
"libc",
"target-lexicon",
]
[[package]]
name = "crc32fast"
version = "1.3.2"
@ -1854,15 +1739,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "gimli"
version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d"
dependencies = [
"indexmap",
]
[[package]]
name = "glam"
version = "0.21.3"
@ -2058,7 +1934,6 @@ dependencies = [
"serde",
"serde_json",
"synfx-dsp",
"synfx-dsp-jit",
"triple_buffer",
]
@ -3189,18 +3064,6 @@ dependencies = [
"bitflags",
]
[[package]]
name = "regalloc2"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d43a209257d978ef079f3d446331d0f1794f5e0fc19b306a199983857833a779"
dependencies = [
"fxhash",
"log",
"slice-group-by",
"smallvec",
]
[[package]]
name = "regex"
version = "1.6.0"
@ -3227,18 +3090,6 @@ version = "0.6.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
[[package]]
name = "region"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877e54ea2adcd70d80e9179344c97f93ef0dffd6b03e1f4529e6e83ab2fa9ae0"
dependencies = [
"bitflags",
"libc",
"mach",
"winapi",
]
[[package]]
name = "renderdoc-sys"
version = "0.7.1"
@ -3402,12 +3253,6 @@ dependencies = [
"autocfg",
]
[[package]]
name = "slice-group-by"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03b634d87b960ab1a38c4fe143b508576f075e7c978bfad18217645ebfdfa2ec"
[[package]]
name = "slotmap"
version = "1.0.6"
@ -3491,21 +3336,6 @@ dependencies = [
"num-traits",
]
[[package]]
name = "synfx-dsp-jit"
version = "0.5.3"
source = "git+https://github.com/WeirdConstructor/synfx-dsp-jit#f199ec697292ed59e92976d7404d6988e0a8d6b0"
dependencies = [
"anyhow",
"cranelift",
"cranelift-codegen",
"cranelift-jit",
"cranelift-module",
"cranelift-native",
"ringbuf",
"synfx-dsp",
]
[[package]]
name = "taffy"
version = "0.1.0"
@ -3519,12 +3349,6 @@ dependencies = [
"typenum",
]
[[package]]
name = "target-lexicon"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c02424087780c9b71cc96799eaeddff35af2bc513278cda5c99fc1f5d026d3c1"
[[package]]
name = "termcolor"
version = "1.1.3"

View file

@ -9,12 +9,16 @@ edition = "2021"
bevy = "0.8.0"
bevy-inspector-egui = "0.12.1"
bevy_rapier2d = "0.16.2"
cpal = "0.14.0"
crossbeam-channel = "0.5.6"
hexodsp = { git = "https://github.com/WeirdConstructor/HexoDSP" }
ticktock = "0.8.0"
rand = "0.8.5"
rand_distr = "0.4.3"
[target."cfg(not(target_arch = \"wasm32\"))".dependencies]
cpal = "0.14.0"
hexodsp = { git = "https://github.com/WeirdConstructor/HexoDSP", default-features = false }
ticktock = "0.8.0"
[target."cfg(target_arch = \"wasm32\")".dependencies]
[profile.dev.package."*"]
opt-level = 3

View file

@ -24,6 +24,8 @@ cargo build --release
### WASM
**Audio does not work in WASM!**
```bash
rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli

View file

@ -1,23 +1,25 @@
// https://github.com/WeirdConstructor/HexoDSP/blob/master/examples/cpal_demo_node_api.rs
use crate::game::AudioMsg;
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use crossbeam_channel::Receiver;
use hexodsp::{matrix_repr::MatrixRepr, *};
use std::io::Read;
use ticktock::Clock;
pub enum AudioMsg {
Color([f32; 3]),
Jump,
}
pub fn setup(event_channel: Receiver<AudioMsg>) {
#[cfg(not(target_arch = "wasm32"))]
let matrix_repr: MatrixRepr = {
let mut buf = String::new();
std::fs::File::open("assets/init.hxy")
.unwrap()
.read_to_string(&mut buf)
.unwrap();
let matrix_repr: MatrixRepr = MatrixRepr::deserialize(&buf).unwrap();
MatrixRepr::deserialize(&buf).unwrap()
};
#[cfg(target_arch = "wasm32")]
let matrix_repr: MatrixRepr = MatrixRepr::deserialize(include_str!("../assets/init.hxy")).unwrap();
let (node_conf, node_exec) = new_node_engine();

View file

@ -1,8 +1,6 @@
#![allow(clippy::precedence)]
#![allow(clippy::too_many_arguments)]
pub use crate::audio::AudioMsg;
use crate::AppState;
use bevy::{
@ -13,6 +11,11 @@ use bevy::{
use bevy_rapier2d::prelude::*;
use std::collections::BTreeSet;
pub enum AudioMsg {
Color([f32; 3]),
Jump,
}
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
pub struct LevelId(pub u32);

View file

@ -1,14 +1,11 @@
#[cfg(not(target_arch = "wasm32"))]
mod audio;
mod game;
mod levels;
mod menu;
mod particle_effect;
use bevy::{
core_pipeline::clear_color::ClearColorConfig,
prelude::*,
render::settings::{WgpuFeatures, WgpuSettings},
};
use bevy::{core_pipeline::clear_color::ClearColorConfig, prelude::*};
use bevy_rapier2d::prelude::*;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
@ -19,16 +16,13 @@ enum AppState {
}
fn main() {
let (audio_event_sender, audio_event_receiver) = crossbeam_channel::bounded(512);
let (audio_event_sender, audio_event_receiver) =
crossbeam_channel::bounded::<game::AudioMsg>(512);
#[cfg(not(target_arch = "wasm32"))]
std::thread::spawn(move || audio::setup(audio_event_receiver));
let mut options = WgpuSettings::default();
options
.features
.set(WgpuFeatures::VERTEX_WRITABLE_STORAGE, true);
App::new()
.insert_resource(options)
.insert_resource(audio_event_sender)
.add_state(AppState::Menu)
.add_plugins(DefaultPlugins)
@ -43,6 +37,9 @@ fn main() {
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
#[cfg(not(target_arch = "wasm32"))]
let font: Handle<Font> = asset_server.load("UacariLegacy-Thin.ttf");
#[cfg(target_arch = "wasm32")]
let font: Handle<Font> = asset_server.load("UacariLegacy-Thin.ttf");
commands.insert_resource(font);

View file

@ -2,7 +2,10 @@ use bevy::{prelude::*, sprite::Mesh2dHandle};
use rand::Rng;
use rand_distr::{Distribution, UnitCircle};
#[cfg(not(target_arch = "wasm32"))]
pub const POOL_COUNT: usize = 100;
#[cfg(target_arch = "wasm32")]
pub const POOL_COUNT: usize = 50;
pub const MIN_VELOCITY: f32 = 10.0;
pub const MAX_VELOCITY: f32 = 100.0;