From e00e23682c2832b5ee0b85165ab6112c1dc4aca9 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Thu, 23 Feb 2023 15:09:13 +0900 Subject: [PATCH] Fix wasm build --- src/agnostic_interface/raylib_impl.rs | 3 +-- src/lib.rs | 8 +++---- src/original_impl.rs | 30 +++++++++++++-------------- wasm/Makefile | 10 ++++----- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/agnostic_interface/raylib_impl.rs b/src/agnostic_interface/raylib_impl.rs index 5abaf6b..f65d9d9 100644 --- a/src/agnostic_interface/raylib_impl.rs +++ b/src/agnostic_interface/raylib_impl.rs @@ -973,8 +973,7 @@ impl GameInterface for RaylibGame { let path_str = path .to_str() .ok_or_else(|| format!("Failed to convert \"{path:?}\" to str!"))?; - let path_buf: Vec = path_str.as_bytes().into(); - let cstring: CString = CString::from_vec_unchecked(path_buf); + let cstring: CString = CString::from_vec_unchecked(path_str.as_bytes().into()); let sound = ffi::LoadSound(cstring.as_ptr()); let raylib_sound_handler = RaylibSoundHandler { sound: Rc::new(RaylibSound { sound }), diff --git a/src/lib.rs b/src/lib.rs index 554072c..ac930c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,8 +8,8 @@ use faux_quicksilver::Window; use original_impl::GameState; pub struct WasmState { - pub window: Window, - pub game_state: GameState, + pub window: Box, + pub game_state: Box, } impl WasmState { @@ -25,8 +25,8 @@ impl WasmState { #[no_mangle] pub extern "C" fn ld45_initialize() -> *mut ::std::os::raw::c_void { let game_interface = RaylibGame::new_boxed(800, 600); - let mut window = Window::new(game_interface); - let game_state = GameState::new(&mut window).unwrap(); + let mut window = Box::new(Window::new(game_interface)); + let game_state = Box::new(GameState::new(&mut window).unwrap()); Box::into_raw(Box::new(WasmState { window, game_state })) as *mut ::std::os::raw::c_void } diff --git a/src/original_impl.rs b/src/original_impl.rs index 2da4c9b..969071e 100644 --- a/src/original_impl.rs +++ b/src/original_impl.rs @@ -1238,11 +1238,11 @@ impl GameState { s_get.clone(), )?; let s_power_up = String::from("power_up.mp3"); - window.load_sound( - &PathBuf::from_str("static/power_up.mp3") - .map_err(|_| String::from("Failed to load \"static/power_up.mp3\""))?, - s_power_up.clone(), - )?; + //window.load_sound( + // &PathBuf::from_str("static/power_up.mp3") + // .map_err(|_| String::from("Failed to load \"static/power_up.mp3\""))?, + // s_power_up.clone(), + //)?; let s_tap = String::from("tap.mp3"); window.load_sound( &PathBuf::from_str("static/tap.mp3") @@ -1250,17 +1250,17 @@ impl GameState { s_tap.clone(), )?; let s_speak_m = String::from("speak_m.mp3"); - window.load_sound( - &PathBuf::from_str("static/speak_m.mp3") - .map_err(|_| String::from("Failed to load \"static/speak_m.mp3\""))?, - s_speak_m.clone(), - )?; + //window.load_sound( + // &PathBuf::from_str("static/speak_m.mp3") + // .map_err(|_| String::from("Failed to load \"static/speak_m.mp3\""))?, + // s_speak_m.clone(), + //)?; let s_speak_f = String::from("speak_f.mp3"); - window.load_sound( - &PathBuf::from_str("static/speak_f.mp3") - .map_err(|_| String::from("Failed to load \"static/speak_f.mp3\""))?, - s_speak_f.clone(), - )?; + //window.load_sound( + // &PathBuf::from_str("static/speak_f.mp3") + // .map_err(|_| String::from("Failed to load \"static/speak_f.mp3\""))?, + // s_speak_f.clone(), + //)?; let font = String::from("ClearSans-Regular.ttf"); window.load_font( diff --git a/wasm/Makefile b/wasm/Makefile index 743349b..b2b898a 100644 --- a/wasm/Makefile +++ b/wasm/Makefile @@ -1,4 +1,5 @@ -CC = source "${HOME}/git/emsdk/emsdk_env.sh" && emcc +EM_ENV = "${HOME}/git/emsdk/emsdk_env.sh" +CC = source ${EM_ENV} && emcc all: ld45.html @@ -6,10 +7,8 @@ ld45.html: src/main.c ../target/wasm32-unknown-emscripten/release/libld45_lib.a ${CC} -o ld45.html -s USE_GLFW=3 -Iinclude \ -Llib -lraylib \ -L../target/wasm32-unknown-emscripten/release -lld45_lib \ - -sTOTAL_MEMORY=1024MB \ - -sALLOW_MEMORY_GROWTH=1 \ + -sALLOW_MEMORY_GROWTH \ -O2 \ --fsanitize=address \ -sEXPORTED_FUNCTIONS="['_malloc', '_main']" \ -sEXPORTED_RUNTIME_METHODS=ccall,cwrap \ --preload-file ../static src/main.c @@ -19,7 +18,8 @@ ld45.html: src/main.c ../target/wasm32-unknown-emscripten/release/libld45_lib.a #-sWARN_UNALIGNED=1 \ ../target/wasm32-unknown-emscripten/release/libld45_lib.a: ../src/lib.rs - cd ..; source "${HOME}/git/emsdk/emsdk_env.sh"; cargo build --lib --release --target wasm32-unknown-emscripten + cd .. && source ${EM_ENV} && cargo build --lib --release --target wasm32-unknown-emscripten +# cd .. && source ${EM_ENV} && cargo rustc --lib --release --target wasm32-unknown-emscripten -- -C link-args=-Wl,-zstack-size=8388608 .PHONY: clean