-
-
Notifications
You must be signed in to change notification settings - Fork 794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebAssembly support #1296
Comments
This is actually on the roadmap for mGBA 0.8, but I haven't tried it yet. |
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. |
Also, would be stoked on this! 😀 Let me know if you need help on the JS side of things! |
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 think that on the next weeks I'll launch this package, Edit: package published 🎉 |
I have this mostly done but I'm still missing a decent frontend. |
@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? |
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. |
Sweet. I just cloned it. How do I build it? I tried 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".``` |
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. |
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.
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 :) |
So I have the docker image running to this point now
Any ideas? Sorry I'm mostly a web developer |
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.
This should do the trick:
This should work for this one:
Hopefully this helps |
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.
This isn't needed. It's not an error and none of the things found with pkg-config would be used here anyway.
This is the webassembly build, a native version of SDL isn't going to help here. |
I've pushed a fix for the GLESv2 issue, it actually builds now despite the warnings. |
That's awesome! Are you building using the docker image? |
Yup. |
Building using you latest push and the docker image I now get this.
|
Try deleting the build-wasm dir and trying again. |
Deleted it. Weird. Now it hangs looking for strdup |
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. |
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... |
Thanks, @endrift. I really appreciate it :) |
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 |
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. |
Got it building :) Going to mess around with exporting functions :) Thanks for your help @endrift |
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? |
@andychase, That's what I thought too so I made one https://www.youtube.com/watch?v=3K9iYbJ-1lQ |
Hey, I made a React wrapper of |
Could you share the example code ? |
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: I changed that line to: 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: -- Checking for one of the modules 'ZLIB' -- Checking for one of the modules 'minizip' -- Checking for one of the modules 'PNG' -- Checking for one of the modules 'libzip' -- Checking for one of the modules 'epoxy' -- Checking for one of the modules 'SQLite3' -- Checking for one of the modules 'libelf' CMake Warning (dev) at src/third-party/zlib/CMakeLists.txt:186 (add_library): error: invalid argument '-std=c++03' not allowed with 'C' -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) Could not find a package configuration file provided by "Qt5" with any of
Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR" CMake Warning at src/platform/qt/CMakeLists.txt:33 (message): -- Build type: Release |
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. |
I started working on a website in src/platform/wasm here: https://github.com/josepharhar/mgba/tree/wasm |
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. |
Any updates on this? |
I'm looking for someone who can help make the frontend. JavaScript and I aren't exactly friends. |
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: endrift#2 |
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. |
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.
|
@hug0b I have a functional dockerfile using https://github.com/thenick775/mgba/blob/feature/wasm/src/platform/wasm/docker/Dockerfile |
@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? |
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?
The text was updated successfully, but these errors were encountered: