Skip to content

Commit

Permalink
Merge pull request #470 from mhaberler/patch-wasm-example
Browse files Browse the repository at this point in the history
make the CMake_WASM example work again
  • Loading branch information
tobozo authored Nov 10, 2023
2 parents 49eed9c + 53e52cf commit fe3815a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples_for_PC/CMake_WASM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12)
project (lv_wasm)

add_definitions(-DLGFX_SDL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -s USE_SDL=2")
set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -g -s USE_SDL=2")

include_directories(../../../LovyanGFX/src/)

Expand Down
9 changes: 4 additions & 5 deletions examples_for_PC/CMake_WASM/LGFX_WASM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
void setup(void);
void loop(void);

void loopThread(void *arg)
void loopThread(void)
{
lgfx::Panel_sdl::loop();
loop();
lgfx::Panel_sdl::sdl_event_handler();
}

int monitor_hor_res, monitor_ver_res;

int main(int argc, char **argv)
{
setup();
emscripten_set_main_loop_arg(loopThread, NULL, -1, true);
lgfx::Panel_sdl::setup();
emscripten_set_main_loop(loopThread, -1, true);
}
15 changes: 15 additions & 0 deletions examples_for_PC/CMake_WASM/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,19 @@
2. `cd build`
3. `emcmake cmake ..`
4. `emmake make`
5. `http-server`
5. open `index.html` in your browser.

## Notes
this is a debug build: `set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -g -s USE_SDL=2")`
It uses the SDL2 library bundled with the Emscripten SDK so I think the `Install SDL``
is not necessary

### Debugging
I followed the [Debugging WebAssembly with modern tools](https://developer.chrome.com/blog/wasm-debugging-2020/) tutorial and was able to debug at the C source level just fine


Steps:
1. Install Chrome Canary
2. Install the C/C++ DevTools Support (DWARF) as outline
3. serve `index.html` via `http-server` - opening file//wherever/index.html breaks debugging

0 comments on commit fe3815a

Please sign in to comment.