Pygame_SDL2 needs few changes to work with Emscripten. I mostly disabled a few thread-related lines for now, and added a call to emscripten_sleep/async (not necessarily the right place to do so).
The main issue I'd like to discuss is compiling Pygame_SDL2 as static modules.
There are a few steps to make this work:
Python2 needs to be slightly patched to support static submodules
(Not related to Pygame_SDL2)
The Cython output needs to be slightly patched to support static submodules
I added something like:
# Fix-up source for static loading
if len(split_name) > 1:
parent_module = '.'.join(split_name[:-1])
parent_module_identifier = parent_module.replace('.', '_')
with open(c_fn, 'r') as f: ccode = f.read()
ccode = re.sub('Py_InitModule4\("([^"]+)"', 'Py_InitModule4("'+parent_module+'.\\1"', ccode)
ccode = re.sub('^__Pyx_PyMODINIT_FUNC init', '__Pyx_PyMODINIT_FUNC init'+parent_module_identifier+'_', ccode, 0, re.MULTILINE) # Cython 0.28.2
ccode = re.sub('^PyMODINIT_FUNC init', 'PyMODINIT_FUNC init'+parent_module_identifier+'_', ccode, 0, re.MULTILINE) # Cython 0.25.2
with open(c_fn, 'w') as f: f.write(ccode)
after the subprocess call to cython.
I need the same for the Ren'Py modules.
Last, I need a way to insert a call to emscripten_sleep conditionally and #include <emscripten.h> (if I keep it in Pygame_SDL2, depending on the performance / maintainability of moving this annoying async call elsewhere).
There's a way to specific values for conditional compilation in Cython, but only through the distutils cython_compile_time_env (e.g. (1)), and not through the command line, which is unfortunate. Alternatively we could implement a mini-preprocessor with a #ifdef/#endif-style syntax in the .pyx file.
(No need for this in Ren'Py modules for now.)
So,
Pygame_SDL2 (and Ren'Py)'s setuplib.py has a pretty specific way to compile Cython modules (compared to other Python libs that use distutils). For 2) this is great because we can easily modify the generate .c script. For 3) this is a blocker because we can't introduce conditional compilation.
Hi,
Pygame_SDL2 needs few changes to work with Emscripten. I mostly disabled a few thread-related lines for now, and added a call to emscripten_sleep/async (not necessarily the right place to do so).
The main issue I'd like to discuss is compiling Pygame_SDL2 as static modules. There are a few steps to make this work:
Python2 needs to be slightly patched to support static submodules (Not related to Pygame_SDL2)
The Cython output needs to be slightly patched to support static submodules I added something like:
after the subprocess call to cython. I need the same for the Ren'Py modules.
Last, I need a way to insert a call to emscripten_sleep conditionally and
#include <emscripten.h>
(if I keep it in Pygame_SDL2, depending on the performance / maintainability of moving this annoying async call elsewhere). There's a way to specific values for conditional compilation in Cython, but only through the distutilscython_compile_time_env
(e.g. (1)), and not through the command line, which is unfortunate. Alternatively we could implement a mini-preprocessor with a#ifdef/#endif
-style syntax in the .pyx file. (No need for this in Ren'Py modules for now.)So, Pygame_SDL2 (and Ren'Py)'s setuplib.py has a pretty specific way to compile Cython modules (compared to other Python libs that use distutils). For 2) this is great because we can easily modify the generate .c script. For 3) this is a blocker because we can't introduce conditional compilation.
I wonder what are your thoughts on this.