Is there any way to take executable binary (.exe) and somehow "compile" .wasm

Viewed 997

I'm working on a 2d game in pygame, and I want it to be available on the web. In my head, a fun way to challenge myself is to use web assembly to make the game available on the web. So I'm wondering if there is any way to take executable binary (.exe) and somehow "compile" .wasm if that's still sayable at this point) to

2 Answers

Running a .exe via WebAssembly (WASM) in the browser will be extremely slow and inefficient but is still possible with a Wasm PC emulator ( eg v86 ) + an OS ( eg ReactOS ).

But if you can gain access to game sourcecode then what you could do is using CPython 3.11 which supports WebAssembly target ( with the help of Emscripten a C/C++ compiler targeting WASM ).

Add to that the latest development version of PyGame and minor changes to the game main loop source code.

You can now run directly the game if you pack both sourcecode and assets with the emscripten File Packager instead of a .exe you will have a .wasm (cpython) + one .data (assets+code) and some javascript glue to load them.

Please note that currently there is no straightforward tool to do that at once, but situation will most likely evolve very quickly after release of CPython 3.11.

Personally, I don't have much experience with combining .py and .wasm files, but I do know some stuff regarding running Pygame:

  1. First of all, you can run basic Pygame files here. I scoured the internet in search of an independent Pygame running engine, and this is the only one I could find.
  2. Second, you can use PyInstaller to convert your Pygame file itself to .exe (it packages it nicely, but can't be signed, so some computers might think it's a virus). I have no idea how to run this specifically on the web, but if you can manage to find a web platform that can run it with a window, then you can maybe try and run that .exe with Javascript and connect the .wasm to that.
  3. Third, I'm not sure there's a way to run .exe files with a separate window in web assembly, but I'm not too familiar with wasm.

I hope that helped!

Related