mgba-emu / mgba

mGBA Game Boy Advance Emulator
https://mgba.io/
Mozilla Public License 2.0
5.63k stars 771 forks source link

WebAssembly support #1296

Open nelsonxb opened 5 years ago

nelsonxb commented 5 years ago

Hey there. I'm curious if anyone has tried running mGBA under WebAssembly, since I might have a use case for such a thing (in the somewhat distant future). If so... how did it go?

If not, I'm keen for a bit of pioneering (though I'm pretty busy over the next couple of months, but should have time after that).

Is anyone able to forsee any potential issues off the bat?

endrift commented 5 years ago

This is actually on the roadmap for mGBA 0.8, but I haven't tried it yet.

nelsonxb commented 5 years ago

Sweet! I'll follow up if I get the time to look into it. I'm comfortable with C myself, so if I get to it first then I'm happy to submit patches if need be.

torch2424 commented 5 years ago

Also, would be stoked on this! ๐Ÿ˜€ Let me know if you need help on the JS side of things!

macabeus commented 4 years ago

Just a tip if someone arrive here by google...

I'm wrapping the emulator on web app gbajs into a React component, so you'll can embed it on your project. I'm doing it because I need a GBA emulator that runs on browser, and gbajs was the unique option that I found.

image

I think that on the next weeks I'll launch this package, react-gbajs.


Edit: package published ๐ŸŽ‰

www.github.com/macabeus/react-gbajs

endrift commented 3 years ago

I have this mostly done but I'm still missing a decent frontend.

patrickcorrigan commented 3 years ago

@endrift Is there a branch or a commit I could test out :) I don't need much of a front end. Just want to mess around. What's the performance like?

endrift commented 3 years ago

Branch is here: https://github.com/endrift/mgba/tree/feature/wasm but it's been a while since I toyed with it so I don't remember.

patrickcorrigan commented 3 years ago

Sweet. I just cloned it. How do I build it? I tried cmake -DCMAKE_TOOLCHAIN_FILE=../src/platform/wasm .. and got


CMake Error at src/platform/wasm/CMakeLists.txt:11 (set_target_properties):
  set_target_properties called with incorrect number of arguments.
Call Stack (most recent call first):
  CMakeFiles/3.15.2/CMakeSystem.cmake:6 (include)
  CMakeLists.txt:10 (project)

-- The C compiler identification is AppleClang 12.0.0.12000032
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
/usr/bin/cc
CMake Error at /Users/patrickcorrigan/Documents/GitHub/mgba/src/platform/wasm/CMakeLists.txt:11 (set_target_pro
perties):
  set_target_properties called with incorrect number of arguments.
Call Stack (most recent call first):
  /Users/patrickcorrigan/Documents/GitHub/mgba/CMakeFiles/3.15.2/CMakeSystem.cmake:6 (include)
  /Users/patrickcorrigan/Documents/GitHub/mgba/CMakeFiles/CMakeTmp/CMakeLists.txt:3 (project)

CMake Error at /opt/local/share/cmake-3.15/Modules/CMakeTestCCompiler.cmake:44 (try_compile):
  Failed to configure test project build system.
Call Stack (most recent call first):
  CMakeLists.txt:10 (project)

-- Configuring incomplete, errors occurred!
See also "/Users/patrickcorrigan/Documents/GitHub/mgba/CMakeFiles/CMakeOutput.log".
See also "/Users/patrickcorrigan/Documents/GitHub/mgba/CMakeFiles/CMakeError.log".```
endrift commented 3 years ago

You'll need emscripten, but beyond that I don't know. I use a Docker image to build it (which is publicly available--https://hub.docker.com/r/mgba/wasm), but if you're on macOS Docker is a pain.

patrickcorrigan commented 3 years ago

Awesome. I installed virtual box and have a ubuntu image running. I can get the docker container to the point where it complains about emscripten

I get this error.

shared:ERROR: '/emsdk_portable/clang/tag-e1.39.4/build_tag-e1.39.4_64/bin/clang -target asmjs-unknown-emscripten -D__EMSCRIPTEN_major__=1 -D__EMSCRIPTEN_minor__=39 -D__EMSCRIPTEN_tiny__=4 -D_LIBCPP_ABI_VERSION=2 -Werror=implicit-function-declaration -Xclang -nostdsysteminc -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/include/libcxx -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/lib/libcxxabi/include -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/include/compat -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/include -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/include/libc -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/lib/libc/musl/arch/emscripten -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/local/include -DBUILD_GL -DENABLE_SCRIPTING -DHAVE_CHMOD -DHAVE_CRC32 -DHAVE_LOCALE -DHAVE_LOCALTIME_R -DHAVE_SETLOCALE -DHAVE_STRDUP -DHAVE_STRNDUP -DHAVE_STRTOF_L -DHAVE_UMASK -DM_CORE_GB -DM_CORE_GBA -DUSE_DEBUGGERS -DUSE_GDB_STUB -DUSE_LZMA -DUSE_PNG -DUSE_PTHREADS -DUSE_SQLITE3 -DUSE_ZLIB -D_7ZIP_PPMD_SUPPPORT -I/home/mgba/src/src -I/home/mgba/src/include -I/home/mgba/src/src/third-party/zlib -I/home/mgba/src/build-wasm/zlib -I/home/mgba/src/src/third-party/libpng -I/home/mgba/src/build-wasm/libpng -I/home/mgba/src/src/third-party/sqlite3 -I/home/mgba/src/src/third-party/lzma -Wall -Wextra -Wno-missing-field-initializers -std=c99 -pthread -DNDEBUG -O2 -c -DEMSCRIPTEN -D__EMSCRIPTEN_PTHREADS__=1 -mllvm -disable-llvm-optzns /home/mgba/src/src/core/cheats.c -Xclang -disable-O0-optnone -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/include/SDL -c -o CMakeFiles/mgba.dir/src/core/cheats.c.o -emit-llvm' failed (1)
CMakeFiles/mgba.dir/build.make:88: recipe for target 'CMakeFiles/mgba.dir/src/core/cheats.c.o' failed

Can you remember how you installed emscripten? I tried installing it globally on the host ubuntu machine. Looks like I need to put it in /emsdk_portable/???

Update - Nevermind I cloned the repo but forgot to check out the correct branch :)

patrickcorrigan commented 3 years ago

So I have the docker image running to this point now

error: invalid argument '-std=c++03' not allowed with 'C'
-- Symbol prefix:
-- Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE)
-- Checking for one of the modules 'sdl2'
-- Could NOT find SDL2 (missing:  SDL2_LIBRARIES SDL2_INCLUDE_DIRS)
-- Could NOT find SDL (missing:  SDL_LIBRARY) (found suitable version "1.3.0", minimum required is "1.2")
-- Build type: Release
-- Platforms:
--      Game Boy Advance: ON
--      Game Boy: ON
-- Features:
--      Debuggers: ON
--      Screenshot/advanced savestate support: ON
--      ZIP support: minizip (included)
--      7-Zip support: ON
--      ELF loading support: OFF
--      OpenGL support: OpenGL, OpenGL|ES 2
-- Frontends:
--      Qt:
--      SDL (2): ON
--      Profiling: OFF
--      Test harness: OFF
--      Test suite: OFF
--      Video test suite: OFF
--      Python bindings: OFF
--      Examples: OFF
-- Cores:
--      Libretro core: OFF
-- Libraries:
--      Static: ON
--      Shared: OFF
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
OPENGLES2_LIBRARY
    linked by target "mgba" in directory /home/mgba/src

-- Configuring incomplete, errors occurred!
See also "/home/mgba/src/build-wasm/CMakeFiles/CMakeOutput.log".
See also "/home/mgba/src/build-wasm/CMakeFiles/CMakeError.log".

Any ideas? Sorry I'm mostly a web developer

brainard52 commented 3 years ago

So I have the docker image running to this point now


error: invalid argument '-std=c++03' not allowed with 'C'

Looks like it's trying to build mgba with a C++ standard. Try -std=c11 instead. I don't know whether that's what the code was written to conform with, but it's a start.

-- Symbol prefix: -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)

This should do the trick: sudo apt update && sudo apt install pkg-config

-- Checking for one of the modules 'sdl2' -- Could NOT find SDL2 (missing: SDL2_LIBRARIES SDL2_INCLUDE_DIRS) -- Could NOT find SDL (missing: SDL_LIBRARY) (found suitable version "1.3.0", minimum required is "1.2")

This should work for this one: sudo apt update && sudo apt install libsdl2 libsdl2-dev libsdl1.2-dev

-- Build type: Release -- Platforms: -- Game Boy Advance: ON -- Game Boy: ON -- Features: -- Debuggers: ON -- Screenshot/advanced savestate support: ON -- ZIP support: minizip (included) -- 7-Zip support: ON -- ELF loading support: OFF -- OpenGL support: OpenGL, OpenGL|ES 2 -- Frontends: -- Qt: -- SDL (2): ON -- Profiling: OFF -- Test harness: OFF -- Test suite: OFF -- Video test suite: OFF -- Python bindings: OFF -- Examples: OFF -- Cores: -- Libretro core: OFF -- Libraries: -- Static: ON -- Shared: OFF CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: OPENGLES2_LIBRARY linked by target "mgba" in directory /home/mgba/src

-- Configuring incomplete, errors occurred! See also "/home/mgba/src/build-wasm/CMakeFiles/CMakeOutput.log". See also "/home/mgba/src/build-wasm/CMakeFiles/CMakeError.log".



Any ideas? Sorry I'm mostly a web developer

Hopefully this helps

endrift commented 3 years ago

Looks like it's trying to build mgba with a C++ standard. Try -std=c11 instead. I don't know whether that's what the code was written to conform with, but it's a start.

Whatever is telling it to use a C++ standard isn't coming from mGBA's code, so tracking down where that's coming from would be the real issue here.

-- Symbol prefix: -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)

This should do the trick: sudo apt update && sudo apt install pkg-config

This isn't needed. It's not an error and none of the things found with pkg-config would be used here anyway.

-- Checking for one of the modules 'sdl2' -- Could NOT find SDL2 (missing: SDL2_LIBRARIES SDL2_INCLUDE_DIRS) -- Could NOT find SDL (missing: SDL_LIBRARY) (found suitable version "1.3.0", minimum required is "1.2")

This should work for this one: sudo apt update && sudo apt install libsdl2 libsdl2-dev libsdl1.2-dev

This is the webassembly build, a native version of SDL isn't going to help here.

endrift commented 3 years ago

I've pushed a fix for the GLESv2 issue, it actually builds now despite the warnings.

patrickcorrigan commented 3 years ago

That's awesome! Are you building using the docker image?

endrift commented 3 years ago

Yup.

patrickcorrigan commented 3 years ago

Building using you latest push and the docker image I now get this.

docker run --rm -t -v $PWD:/home/mgba/src  mgba/wasm
-- Checking for one of the modules 'libedit'
CMake Warning at CMakeLists.txt:144 (message):
  Requested module libedit missing for feature USE_EDITLINE.  Feature
  disabled.
Call Stack (most recent call first):
  CMakeLists.txt:407 (find_feature)

-- Checking for one of the modules 'libavcodec'
CMake Warning at CMakeLists.txt:144 (message):
  Requested module libavcodec missing for feature USE_FFMPEG.  Feature
  disabled.
Call Stack (most recent call first):
  CMakeLists.txt:434 (find_feature)

-- Checking for one of the modules 'ZLIB'
CMake Warning at CMakeLists.txt:144 (message):
  Requested module ZLIB missing for feature USE_ZLIB.  Feature disabled.
Call Stack (most recent call first):
  CMakeLists.txt:435 (find_feature)

-- Checking for one of the modules 'minizip'
CMake Warning at CMakeLists.txt:144 (message):
  Requested module minizip missing for feature USE_MINIZIP.  Feature
  disabled.
Call Stack (most recent call first):
  CMakeLists.txt:436 (find_feature)

-- Checking for one of the modules 'PNG'
CMake Warning at CMakeLists.txt:144 (message):
  Requested module PNG missing for feature USE_PNG.  Feature disabled.
Call Stack (most recent call first):
  CMakeLists.txt:437 (find_feature)

-- Checking for one of the modules 'libzip'
CMake Warning at CMakeLists.txt:144 (message):
  Requested module libzip missing for feature USE_LIBZIP.  Feature disabled.
Call Stack (most recent call first):
  CMakeLists.txt:438 (find_feature)

-- Checking for one of the modules 'MagickWand'
CMake Warning at CMakeLists.txt:144 (message):
  Requested module MagickWand missing for feature USE_MAGICK.  Feature
  disabled.
Call Stack (most recent call first):
  CMakeLists.txt:439 (find_feature)

-- Checking for one of the modules 'epoxy'
CMake Warning at CMakeLists.txt:144 (message):
  Requested module epoxy missing for feature USE_EPOXY.  Feature disabled.
Call Stack (most recent call first):
  CMakeLists.txt:440 (find_feature)

-- Checking for one of the modules 'sqlite3'
CMake Warning at CMakeLists.txt:144 (message):
  Requested module sqlite3 missing for feature USE_SQLITE3.  Feature
  disabled.
Call Stack (most recent call first):
  CMakeLists.txt:442 (find_feature)

-- Checking for one of the modules 'libelf'
CMake Warning at CMakeLists.txt:144 (message):
  Requested module libelf missing for feature USE_ELF.  Feature disabled.
Call Stack (most recent call first):
  CMakeLists.txt:443 (find_feature)

CMake Warning (dev) at src/third-party/zlib/CMakeLists.txt:186 (add_library):
  ADD_LIBRARY called with SHARED option but the target platform does not
  support dynamic linking.  Building a STATIC library instead.  This may lead
  to problems.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:799 (add_library):
  ADD_LIBRARY called with SHARED option but the target platform does not
  support dynamic linking.  Building a STATIC library instead.  This may lead
  to problems.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Checking for one of the modules 'sdl2'
-- Could NOT find SDL (missing:  SDL_LIBRARY) (found suitable version "1.3.0", minimum required is "1.2")
CMake Warning at src/platform/qt/CMakeLists.txt:25 (find_package):
  By not providing "FindQt5Multimedia.cmake" in CMAKE_MODULE_PATH this
  project has asked CMake to find a package configuration file provided by
  "Qt5Multimedia", but CMake did not find one.

  Could not find a package configuration file provided by "Qt5Multimedia"
  with any of the following names:

    Qt5MultimediaConfig.cmake
    qt5multimedia-config.cmake

  Add the installation prefix of "Qt5Multimedia" to CMAKE_PREFIX_PATH or set
  "Qt5Multimedia_DIR" to a directory containing one of the above files.  If
  "Qt5Multimedia" provides a separate development package or SDK, be sure it
  has been installed.

CMake Warning at src/platform/qt/CMakeLists.txt:26 (find_package):
  By not providing "FindQt5OpenGL.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "Qt5OpenGL", but CMake did not find one.

  Could not find a package configuration file provided by "Qt5OpenGL" with
  any of the following names:

    Qt5OpenGLConfig.cmake
    qt5opengl-config.cmake

  Add the installation prefix of "Qt5OpenGL" to CMAKE_PREFIX_PATH or set
  "Qt5OpenGL_DIR" to a directory containing one of the above files.  If
  "Qt5OpenGL" provides a separate development package or SDK, be sure it has
  been installed.

CMake Warning at src/platform/qt/CMakeLists.txt:27 (find_package):
  By not providing "FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "Qt5Widgets", but CMake did not find one.

  Could not find a package configuration file provided by "Qt5Widgets" with
  any of the following names:

    Qt5WidgetsConfig.cmake
    qt5widgets-config.cmake

  Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH or set
  "Qt5Widgets_DIR" to a directory containing one of the above files.  If
  "Qt5Widgets" provides a separate development package or SDK, be sure it has
  been installed.

CMake Warning at src/platform/qt/CMakeLists.txt:35 (message):
  Cannot find Qt modules

-- Build type: Release
-- Platforms:
--  Game Boy Advance: ON
--  Game Boy: ON
-- Features:
--  Debuggers: ON
--  CLI debugger: OFF
--  GDB stub: ON
--  Video recording: OFF
--  GIF recording: OFF
--  Screenshot/advanced savestate support: ON
--  ZIP support: minizip (included)
--  7-Zip support: ON
--  SQLite3 game database: ON
--  ELF loading support: OFF
--  OpenGL support: OpenGL
-- Frontends:
--  Qt: ON
--  SDL (2): ON
--  Profiling: OFF
--  Test harness: OFF
--  Test suite: OFF
--  Python bindings: OFF
--  Examples: OFF
-- Cores:
--  Libretro core: OFF
-- Libraries:
--  Static: OFF
--  Shared: ON
-- Configuring done
CMake Warning (dev) at src/third-party/libpng/CMakeLists.txt:130 (add_library):
  Policy CMP0003 should be set before this line.  Add code such as

    if(COMMAND cmake_policy)
      cmake_policy(SET CMP0003 NEW)
    endif(COMMAND cmake_policy)

  as early as possible but after the most recent call to
  cmake_minimum_required or cmake_policy(VERSION).  This warning appears
  because target "png16_static" links to some libraries for which the linker
  must search:

    m

  and other libraries with known full path:

    /home/mgba/src/build-wasm/zlib/libz.a

  CMake is adding directories in the second list to the linker search path in
  case they are needed to find libraries from the first list (for backwards
  compatibility with CMake 2.4).  Set policy CMP0003 to OLD or NEW to enable
  or disable this behavior explicitly.  Run "cmake --help-policy CMP0003" for
  more information.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done
-- Build files have been written to: /home/mgba/src/build-wasm
[  0%] Built target version-info
[  8%] Built target zlibstatic
[ 16%] Built target png16_static
[ 16%] Building C object CMakeFiles/mgba.dir/src/core/cheats.c.o
In file included from /home/mgba/src/src/core/cheats.c:8:
In file included from /home/mgba/src/include/mgba/core/core.h:15:
/home/mgba/src/include/mgba/core/directories.h:17:16: error: use of undeclared identifier 'PATH_MAX'
        char baseName[PATH_MAX];
                      ^
/home/mgba/src/src/core/cheats.c:77:15: error: implicit declaration of function 'strdup' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                set->name = strdup(name);
                            ^
/home/mgba/src/src/core/cheats.c:77:13: warning: incompatible integer to pointer conversion assigning to 'char *' from 'int' [-Wint-conversion]
                set->name = strdup(name);
                          ^ ~~~~~~~~~~~~
/home/mgba/src/src/core/cheats.c:103:15: error: implicit declaration of function 'strdup' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                set->name = strdup(name);
                            ^
/home/mgba/src/src/core/cheats.c:103:13: warning: incompatible integer to pointer conversion assigning to 'char *' from 'int' [-Wint-conversion]
                set->name = strdup(name);
                          ^ ~~~~~~~~~~~~
/home/mgba/src/src/core/cheats.c:111:35: error: implicit declaration of function 'strdup' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        *StringListAppend(&set->lines) = strdup(line);
                                         ^
/home/mgba/src/src/core/cheats.c:111:33: warning: incompatible integer to pointer conversion assigning to 'char *' from 'int' [-Wint-conversion]
        *StringListAppend(&set->lines) = strdup(line);
                                       ^ ~~~~~~~~~~~~
/home/mgba/src/src/core/cheats.c:189:37: error: implicit declaration of function 'strdup' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                        *StringListAppend(&directives) = strdup(&cheat[i]);
                                                         ^
/home/mgba/src/src/core/cheats.c:189:35: warning: incompatible integer to pointer conversion assigning to 'char *' from 'int' [-Wint-conversion]
                        *StringListAppend(&directives) = strdup(&cheat[i]);
                                                       ^ ~~~~~~~~~~~~~~~~~
4 warnings and 5 errors generated.
shared:ERROR: '/emsdk_portable/clang/tag-e1.39.4/build_tag-e1.39.4_64/bin/clang -target asmjs-unknown-emscripten -D__EMSCRIPTEN_major__=1 -D__EMSCRIPTEN_minor__=39 -D__EMSCRIPTEN_tiny__=4 -D_LIBCPP_ABI_VERSION=2 -Werror=implicit-function-declaration -Xclang -nostdsysteminc -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/include/libcxx -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/lib/libcxxabi/include -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/include/compat -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/include -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/include/libc -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/lib/libc/musl/arch/emscripten -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/local/include -DBUILD_GL -DENABLE_SCRIPTING -DHAVE_CHMOD -DHAVE_CRC32 -DHAVE_LOCALE -DHAVE_LOCALTIME_R -DHAVE_SETLOCALE -DHAVE_STRDUP -DHAVE_STRNDUP -DHAVE_STRTOF_L -DHAVE_UMASK -DM_CORE_GB -DM_CORE_GBA -DUSE_DEBUGGERS -DUSE_GDB_STUB -DUSE_LZMA -DUSE_PNG -DUSE_PTHREADS -DUSE_SQLITE3 -DUSE_ZLIB -D_7ZIP_PPMD_SUPPPORT -I/home/mgba/src/src -I/home/mgba/src/include -I/home/mgba/src/src/third-party/zlib -I/home/mgba/src/build-wasm/zlib -I/home/mgba/src/src/third-party/libpng -I/home/mgba/src/build-wasm/libpng -I/home/mgba/src/src/third-party/sqlite3 -I/home/mgba/src/src/third-party/lzma -Wall -Wextra -Wno-missing-field-initializers -std=c99 -pthread -DNDEBUG -O2 -c -DEMSCRIPTEN -D__EMSCRIPTEN_PTHREADS__=1 -mllvm -disable-llvm-optzns /home/mgba/src/src/core/cheats.c -Xclang -disable-O0-optnone -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/include/SDL -c -o CMakeFiles/mgba.dir/src/core/cheats.c.o -emit-llvm' failed (1)
CMakeFiles/mgba.dir/build.make:88: recipe for target 'CMakeFiles/mgba.dir/src/core/cheats.c.o' failed
make[2]: *** [CMakeFiles/mgba.dir/src/core/cheats.c.o] Error 1
CMakeFiles/Makefile2:106: recipe for target 'CMakeFiles/mgba.dir/all' failed
make[1]: *** [CMakeFiles/mgba.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
endrift commented 3 years ago

Try deleting the build-wasm dir and trying again.

patrickcorrigan commented 3 years ago

Deleted it. Weird. Now it hangs looking for strdup

patrickcorrigan commented 3 years ago

Would you be able to post the output of the build just so I can mess around with the project. I'll keep trying to get the docker build going in the meantime.

endrift commented 3 years ago

Sure thing, here's the build with an example index.html that does some loading. I'd love to merge the branch but I need a bit more than just an example page for testing it...

build.zip

patrickcorrigan commented 3 years ago

Thanks, @endrift. I really appreciate it :)

patrickcorrigan commented 3 years ago

It works! (Your build output. Not my build) I'd love to be able to help out. I was hoping I could help fill out the remain methods in the js file and build a ui

endrift commented 3 years ago

A simple frontend for a demo (which I'll end up putting up on the site of course) that works with controllers and phone, plus a good list of functions that need to be exposed, are about all that's preventing this from being merged.

patrickcorrigan commented 3 years ago

Got it building :) Going to mess around with exporting functions :) Thanks for your help @endrift

andychase commented 3 years ago

There are some forks of gbajs that had various frontends. I tried some of them, some were made for mobile, some not. None of them are amazing in all situations I donโ€™t think. Why not start with the one you had for gbajs?

patrickcorrigan commented 3 years ago

@andychase, That's what I thought too so I made one https://www.youtube.com/watch?v=3K9iYbJ-1lQ

macabeus commented 3 years ago

Hey, I made a React wrapper of gbajs: https://github.com/macabeus/react-gbajs It is still at the beginning of the development, but it already works fine and I'm using it on my personagel project. Contributions are welcome.

whatwewant commented 3 years ago

@andychase, That's what I thought too so I made one https://www.youtube.com/watch?v=3K9iYbJ-1lQ

Could you share the example code ?

Dimkar3000 commented 3 years ago

Hello, I tried today to build the project under windows using the latest docker 'mgba/wasm' image. I encountered some problem that I would like to report.

The first one was that PkgConfig seams to not be install on the image. I am not sure if I am doing something wrong or I am supposed to run it with some flags or environmental variables but... out of the box it doen't work. Cmake seam to be able to work without it but it will probably crash for me in a later stage.

I later encounter a wrong compiler flag, I tried to compile with c++03 and it failed. After some debug, I found out this comes from zlib. I fixed it by manually setting CMAKE_CXX_STANDARD to 11 in the to CMakeLists.txt

Next I got this error: CMake Error at CMakeLists.txt:866 (install): install TARGETS given no ARCHIVE DESTINATION for static library target "mgba".

I changed that line to: install(TARGETS ${BINARY_NAME} ARCHIVE DESTINATION ${LIBDIR} LIBRARY DESTINATION ${LIBDIR} COMPONENT ${BINARY_NAME}-dev NAMELINK_ONLY) It seams to fix it.

After that the compilation started. It never finished no matter what I did, probably because of the missing pkgconfig or something. Currently I am getting a lot of compilation error about missing strdup, strcpy and the last was about the uselocale() function. Since these are all supposed to be there probably my setup is wrong.

I used the latest commit of the master and wsl2 on Windows to do so, here is my final output: `-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Checking for one of the modules 'libavcodec' CMake Warning at src/platform/cmake/FindFeature.cmake:51 (message): Requested module libavcodec missing for feature USE_FFMPEG. Feature disabled. Call Stack (most recent call first): CMakeLists.txt:477 (find_feature)

-- Checking for one of the modules 'ZLIB' CMake Warning at src/platform/cmake/FindFeature.cmake:51 (message): Requested module ZLIB missing for feature USE_ZLIB. Feature disabled. Call Stack (most recent call first): CMakeLists.txt:479 (find_feature)

-- Checking for one of the modules 'minizip' CMake Warning at src/platform/cmake/FindFeature.cmake:51 (message): Requested module minizip missing for feature USE_MINIZIP. Feature disabled. Call Stack (most recent call first): CMakeLists.txt:480 (find_feature)

-- Checking for one of the modules 'PNG' CMake Warning at src/platform/cmake/FindFeature.cmake:51 (message): Requested module PNG missing for feature USE_PNG. Feature disabled. Call Stack (most recent call first): CMakeLists.txt:481 (find_feature)

-- Checking for one of the modules 'libzip' CMake Warning at src/platform/cmake/FindFeature.cmake:51 (message): Requested module libzip missing for feature USE_LIBZIP. Feature disabled. Call Stack (most recent call first): CMakeLists.txt:482 (find_feature)

-- Checking for one of the modules 'epoxy' CMake Warning at src/platform/cmake/FindFeature.cmake:51 (message): Requested module epoxy missing for feature USE_EPOXY. Feature disabled. Call Stack (most recent call first): CMakeLists.txt:483 (find_feature)

-- Checking for one of the modules 'SQLite3' -- Checking for one of the modules 'sqlite3' CMake Warning at src/platform/cmake/FindFeature.cmake:51 (message): Requested module SQLite3|sqlite3 missing for feature USE_SQLITE3. Feature disabled. Call Stack (most recent call first): CMakeLists.txt:485 (find_feature)

-- Checking for one of the modules 'libelf' CMake Warning at src/platform/cmake/FindFeature.cmake:51 (message): Requested module libelf missing for feature USE_ELF. Feature disabled. Call Stack (most recent call first): CMakeLists.txt:486 (find_feature)

CMake Warning (dev) at src/third-party/zlib/CMakeLists.txt:186 (add_library): ADD_LIBRARY called with SHARED option but the target platform does not support dynamic linking. Building a STATIC library instead. This may lead to problems. This warning is for project developers. Use -Wno-dev to suppress it.

error: invalid argument '-std=c++03' not allowed with 'C' -- Symbol prefix: CMake Warning (dev) at CMakeLists.txt:844 (add_library): ADD_LIBRARY called with SHARED option but the target platform does not support dynamic linking. Building a STATIC library instead. This may lead to problems. This warning is for project developers. Use -Wno-dev to suppress it.

-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- Checking for one of the modules 'sdl2' -- Could NOT find SDL2 (missing: SDL2_LIBRARIES SDL2_INCLUDE_DIRS) -- Could NOT find SDL (missing: SDL_LIBRARY) (found suitable version "1.3.0", minimum required is "1.2") CMake Warning at src/platform/qt/CMakeLists.txt:25 (find_package): By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "Qt5", but CMake did not find one.

Could not find a package configuration file provided by "Qt5" with any of the following names:

Qt5Config.cmake
qt5-config.cmake

Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR" to a directory containing one of the above files. If "Qt5" provides a separate development package or SDK, be sure it has been installed.

CMake Warning at src/platform/qt/CMakeLists.txt:33 (message): Cannot find Qt modules

-- Build type: Release -- Platforms: -- Game Boy Advance: ON -- Game Boy: ON -- Features: -- Debuggers: OFF -- CLI debugger: OFF -- GDB stub: OFF -- GIF/Video recording: OFF -- Screenshot/advanced savestate support: ON -- ZIP support: minizip (included) -- 7-Zip support: ON -- SQLite3 game database: ON -- ELF loading support: OFF -- Discord Rich Presence support: ON -- OpenGL support: OpenGL, OpenGL|ES 2, OpenGL|ES 3 -- Frontends: -- Qt: ON -- SDL (2): ON -- Profiling: OFF -- Test harness: OFF -- Test suite: OFF -- Video test suite: OFF -- Python bindings: OFF -- Examples: OFF -- Cores: -- Libretro core: OFF -- Libraries: -- Static: OFF -- Shared: ON -- Configuring done -- Generating done -- Build files have been written to: /home/mgba/src/build-wasm [ 0%] Built target mgba-version-info [ 6%] Built target genfiles Scanning dependencies of target zlibstatic [ 6%] Building C object zlib/CMakeFiles/zlibstatic.dir/adler32.o [ 7%] Building C object zlib/CMakeFiles/zlibstatic.dir/compress.o [ 7%] Building C object zlib/CMakeFiles/zlibstatic.dir/crc32.o [ 7%] Building C object zlib/CMakeFiles/zlibstatic.dir/deflate.o [ 8%] Building C object zlib/CMakeFiles/zlibstatic.dir/gzclose.o [ 8%] Building C object zlib/CMakeFiles/zlibstatic.dir/gzlib.o [ 9%] Building C object zlib/CMakeFiles/zlibstatic.dir/gzread.o [ 9%] Building C object zlib/CMakeFiles/zlibstatic.dir/gzwrite.o [ 10%] Building C object zlib/CMakeFiles/zlibstatic.dir/inflate.o /home/mgba/src/src/third-party/zlib/inflate.c:1507:61: warning: shifting a negative signed value is undefined [-Wshift-negative-value] if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;


1 warning generated.
[ 10%] Building C object zlib/CMakeFiles/zlibstatic.dir/infback.o
[ 10%] Building C object zlib/CMakeFiles/zlibstatic.dir/inftrees.o
[ 12%] Building C object zlib/CMakeFiles/zlibstatic.dir/inffast.o
[ 12%] Building C object zlib/CMakeFiles/zlibstatic.dir/trees.o
[ 13%] Building C object zlib/CMakeFiles/zlibstatic.dir/uncompr.o
[ 13%] Building C object zlib/CMakeFiles/zlibstatic.dir/zutil.o
[ 14%] Linking C static library libz.a
[ 14%] Built target zlibstatic
Scanning dependencies of target png_static
[ 15%] Building C object libpng/CMakeFiles/png_static.dir/png.c.o
[ 15%] Building C object libpng/CMakeFiles/png_static.dir/pngerror.c.o
[ 17%] Building C object libpng/CMakeFiles/png_static.dir/pngget.c.o
[ 17%] Building C object libpng/CMakeFiles/png_static.dir/pngmem.c.o
[ 17%] Building C object libpng/CMakeFiles/png_static.dir/pngpread.c.o
[ 18%] Building C object libpng/CMakeFiles/png_static.dir/pngread.c.o
[ 18%] Building C object libpng/CMakeFiles/png_static.dir/pngrio.c.o
[ 19%] Building C object libpng/CMakeFiles/png_static.dir/pngrtran.c.o
[ 19%] Building C object libpng/CMakeFiles/png_static.dir/pngrutil.c.o
[ 20%] Building C object libpng/CMakeFiles/png_static.dir/pngset.c.o
[ 20%] Building C object libpng/CMakeFiles/png_static.dir/pngtrans.c.o
[ 20%] Building C object libpng/CMakeFiles/png_static.dir/pngwio.c.o
[ 21%] Building C object libpng/CMakeFiles/png_static.dir/pngwrite.c.o
[ 21%] Building C object libpng/CMakeFiles/png_static.dir/pngwtran.c.o
[ 23%] Building C object libpng/CMakeFiles/png_static.dir/pngwutil.c.o
[ 23%] Linking C static library libpng16.a
[ 24%] Built target png_static
[ 24%] Building C object CMakeFiles/mgba.dir/src/util/formatting.c.o
/home/mgba/src/src/util/formatting.c:13:17: error: implicit declaration of function 'uselocale' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        locale_t old = uselocale(locale);
                       ^
/home/mgba/src/src/util/formatting.c:13:17: note: did you mean 'setlocale'?
/emsdk_portable/emscripten/tag-1.39.4/system/include/libc/locale.h:53:7: note: 'setlocale' declared here
char *setlocale (int, const char *);
      ^
/home/mgba/src/src/util/formatting.c:13:11: warning: incompatible integer to pointer conversion initializing 'locale_t' (aka 'struct __locale_struct *') with an expression of type 'int'
      [-Wint-conversion]
        locale_t old = uselocale(locale);
                 ^     ~~~~~~~~~~~~~~~~~
/home/mgba/src/src/util/formatting.c:49:15: error: implicit declaration of function 'newlocale' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        locale_t l = newlocale(LC_NUMERIC_MASK, "C", 0);
                     ^
/home/mgba/src/src/util/formatting.c:49:15: note: did you mean 'setlocale'?
/emsdk_portable/emscripten/tag-1.39.4/system/include/libc/locale.h:53:7: note: 'setlocale' declared here
char *setlocale (int, const char *);
      ^
/home/mgba/src/src/util/formatting.c:49:25: error: use of undeclared identifier 'LC_NUMERIC_MASK'
        locale_t l = newlocale(LC_NUMERIC_MASK, "C", 0);
                               ^
/home/mgba/src/src/util/formatting.c:55:2: error: implicit declaration of function 'freelocale' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        freelocale(l);
        ^
/home/mgba/src/src/util/formatting.c:62:15: error: implicit declaration of function 'newlocale' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        locale_t l = newlocale(LC_NUMERIC_MASK, "C", 0);
                     ^
/home/mgba/src/src/util/formatting.c:62:25: error: use of undeclared identifier 'LC_NUMERIC_MASK'
        locale_t l = newlocale(LC_NUMERIC_MASK, "C", 0);
                               ^
/home/mgba/src/src/util/formatting.c:66:14: error: implicit declaration of function 'strtof_l' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        float res = strtof_l(str, end, l);
                    ^
/home/mgba/src/src/util/formatting.c:66:14: note: did you mean 'strtof_u'?
/home/mgba/src/src/util/formatting.c:60:7: note: 'strtof_u' declared here
float strtof_u(const char* restrict str, char** restrict end) {
      ^
/home/mgba/src/src/util/formatting.c:68:2: error: implicit declaration of function 'freelocale' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        freelocale(l);
        ^
1 warning and 8 errors generated.
shared:ERROR: '/emsdk_portable/clang/tag-e1.39.4/build_tag-e1.39.4_64/bin/clang -target asmjs-unknown-emscripten -D__EMSCRIPTEN_major__=1 -D__EMSCRIPTEN_minor__=39 -D__EMSCRIPTEN_tiny__=4 -D_LIBCPP_ABI_VERSION=2 -Werror=implicit-function-declaration -Xclang -nostdsysteminc -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/include/libcxx -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/lib/libcxxabi/include -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/include/compat -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/include -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/include/libc -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/lib/libc/musl/arch/emscripten -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/local/include -DBUILD_GL -DBUILD_GLES2 -DBUILD_GLES3 -DDISABLE_THREADING -DENABLE_SCRIPTING -DHAVE_CRC32 -DHAVE_FREELOCALE -DHAVE_FUTIMENS -DHAVE_LOCALE -DHAVE_LOCALTIME_R -DHAVE_NEWLOCALE -DHAVE_PTHREAD_CREATE -DHAVE_SETLOCALE -DHAVE_STRDUP -DHAVE_STRLCPY -DHAVE_STRNDUP -DHAVE_STRTOF_L -DHAVE_USELOCALE -DHAVE_VASPRINTF -DHAVE_XLOCALE -DMGBA_DLL -DM_CORE_GB -DM_CORE_GBA -DUSE_DISCORD_RPC -DUSE_LZMA -DUSE_MINIZIP -DUSE_PNG -DUSE_PTHREADS -DUSE_SQLITE3 -DUSE_ZLIB -D_7ZIP_PPMD_SUPPPORT -I/home/mgba/src/include -I/home/mgba/src/build-wasm/include -I/home/mgba/src/src -I/emsdk_portable/emscripten/tag-1.39.4/system/include -I/home/mgba/src/src/third-party/zlib -I/home/mgba/src/build-wasm/zlib -I/home/mgba/src/src/third-party/libpng -I/home/mgba/src/build-wasm/libpng -I/home/mgba/src/src/third-party/sqlite3 -I/home/mgba/src/src/third-party/zlib/contrib -I/home/mgba/src/src/third-party/lzma -I/home/mgba/src/src/third-party/discord-rpc/include -Wall -Wextra -Wno-missing-field-initializers -Werror=implicit-function-declaration -pthread -DNDEBUG -O2 -std=c99 -c -DEMSCRIPTEN -D__EMSCRIPTEN_PTHREADS__=1 -mllvm -disable-llvm-optzns /home/mgba/src/src/util/formatting.c -Xclang -disable-O0-optnone -Xclang -isystem/emsdk_portable/emscripten/tag-1.39.4/system/include/SDL -c -o CMakeFiles/mgba.dir/src/util/formatting.c.o -emit-llvm' failed (1)
CMakeFiles/mgba.dir/build.make:2138: recipe for target 'CMakeFiles/mgba.dir/src/util/formatting.c.o' failed
make[2]: *** [CMakeFiles/mgba.dir/src/util/formatting.c.o] Error 1
CMakeFiles/Makefile2:106: recipe for target 'CMakeFiles/mgba.dir/all' failed
make[1]: *** [CMakeFiles/mgba.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2`
Dimkar3000 commented 3 years ago

Hello again, I managed to finally build the project using the docker container for the wasm target. The main problem was as always me. I didn't understand how the libraries where loaded and a result everything was broken. After I visited the private branch that @endrift created above, I managed to steal some of his CmakeLists.txt and the platform code from wasm to make it work. I actually now have the main branch compiling for wasm. image

josepharhar commented 1 year ago

I started working on a website in src/platform/wasm here: https://github.com/josepharhar/mgba/tree/wasm I am hosting it here if anyone would like to try it out: https://mgba.jarhar.com/ I am happy to open a PR to endrift/feature/wasm whenever appropriate, but I'll continue polishing it and updating mgba.jarhar.com in the meantime. I was inspired by eclipse emu to make it work well on my smartphone, but I think it should work on desktop too.

Dimkar3000 commented 1 year ago

Since mGBA is a native codebase, a wrapper library that would manage state and simplify usage should be made, independently of a GUI layout. For example:

import mGBA from "mgba.js"

const core = mgba.init();

core.reset()
core.loadGame(filepath)
core.renderToElement(div)

while (true) {
  core.proccessEvents();
  core.step()
 core.render()
}

This ground work will allow the faster development of a GUI when a design that satisfies @endrift is made.

redbrain commented 1 year ago

Any updates on this?

endrift commented 1 year ago

I'm looking for someone who can help make the frontend. JavaScript and I aren't exactly friends.

josepharhar commented 1 year ago

Ok I'm guessing that merging into endrift/feature/wasm is still the preferred option, so I opened a PR there to get things started: https://github.com/endrift/mgba/pull/2

endrift commented 1 year ago

Yeah, that's the right place. I'll take a look a bit later, thanks. I'm probably gonna ask for a lot of cleanup though.

thenick775 commented 1 year ago

Just in case its useful, I've condensed some work from the surrounding community in my mGBA fork (with some custom additions), along with a frontend here

hug0b commented 1 year ago

I think it it would be beneficial to update the wasm build Dockerfile as it seems to be based on an outdated Emscripten version from 2019.

FROM trzeci/emscripten-slim could be changed to FROM emscripten/emsdk:3.1.38 (or whatever version)

Official EMSDK Dockerfile

thenick775 commented 12 months ago

@hug0b I have a functional dockerfile using emscripten/emsdk:3.1.46 here if you'd like to submit a PR on my behalf. You may also need to modify the cmake related build files as shown in my mGBA fork for this to be compatible with the version of libpng used.

https://github.com/thenick775/mgba/blob/feature-wasm-vite-react-es6/src/platform/wasm/docker/Dockerfile

https://github.com/thenick775/mgba/blob/feature/wasm/src/platform/wasm/docker/Dockerfile

thenick775 commented 6 months ago

@endrift a question when you have some time, I'm attempting to get rewind support baked into the wasm output, but am a bit confused on where to start given that everything touching rewind in the QT implementation uses threads.

Do you have any pointers on where I could start to get that built out in the context of the wasm implementation?