Skip to content
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

Emscripten support - compilation #115

Closed
Beuc opened this issue Oct 28, 2018 · 2 comments
Closed

Emscripten support - compilation #115

Beuc opened this issue Oct 28, 2018 · 2 comments

Comments

@Beuc
Copy link
Contributor

@Beuc Beuc commented Oct 28, 2018

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:

  1. Python2 needs to be slightly patched to support static submodules
    (Not related to Pygame_SDL2)

  2. 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.

  1. 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.

I wonder what are your thoughts on this.

@Beuc
Copy link
Contributor Author

@Beuc Beuc commented Nov 19, 2018

I moved out 3. out of pygame_sdl2 so that sub-part is not an immediate issue.

@Beuc
Copy link
Contributor Author

@Beuc Beuc commented Sep 13, 2019

Done -- cf. commits during April.

@Beuc Beuc closed this Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant