libretro / mgba

mGBA Game Boy Advance Emulator
https://mgba.io/
Mozilla Public License 2.0
68 stars 73 forks source link

Emscripten support #226

Closed BinBashBanana closed 3 years ago

BinBashBanana commented 3 years ago

This change allows mGBA to be built for emscripten

BinBashBanana commented 3 years ago

I had to rename it, because otherwise it would conflict with a variable in libretro_emscripten.bc when I tried to link the final file.

endrift commented 3 years ago

No, you cannot rename it. Instead you should define HAVE_STRTOF_L.

BinBashBanana commented 3 years ago

I barely even know C, so I wouldn't know how to do that. What is the branch that supports emscripten?

endrift commented 3 years ago

It's not a C thing, it's just changing this line: DEFINES += -std=gnu99 -DHAVE_LOCALE to this: DEFINES += -std=gnu99 -DHAVE_LOCALE -DHAVE_STRTOF_L

The branch is here fwiw: https://github.com/endrift/mgba/tree/feature/wasm

BinBashBanana commented 3 years ago

Does that go in the makefile in mGBA or in RetroArch?

endrift commented 3 years ago

Makefile.libretro line 390, you added a line right after it.

BinBashBanana commented 3 years ago

I reverted formatting.c and formatting.h, added -DHAVE_STRTOF_L to Makefile.libretro, tried recompiling but got this error:

src/util/formatting.c:67:14: error: implicit declaration of function 'strtof_l' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        float res = strtof_l(str, end, l);
                    ^
src/util/formatting.c:67:14: note: did you mean 'strtof_u'?
src/util/formatting.c:61:7: note: 'strtof_u' declared here
float strtof_u(const char* restrict str, char** restrict end) {
      ^
1 error generated.
endrift commented 3 years ago

You should try also adding -DHAVE_XLOCALE

BinBashBanana commented 3 years ago

It throws the same error.

endrift commented 3 years ago

Try -D_GNU_SOURCE instead of -DHAVE_XLOCALE

endrift commented 3 years ago

Looks good now, thanks

BinBashBanana commented 3 years ago

You beat me to it. :)