1
0
mirror of synced 2024-11-30 16:54:30 +01:00

Check in environment flag to use experimental mypyc compiler instead of cython for some modules.

This commit is contained in:
Jennifer Taylor 2021-05-31 18:15:10 +00:00
parent b1b8b67fe3
commit 4a18f43253

View File

@ -4,6 +4,10 @@ from setuptools import Command, setup
def extensions():
# None of these are required for operating any of the utilities found in this repo.
# They are all present for speed. If you cannot compile arbitrary code or cython,
# run setup.py with "PURE_PYTHON=1" environment variable defined to skip compiling
# extensions. Note that the pure python code will run slower.
if 'PURE_PYTHON' in os.environ:
# We've been asked not to compile extensions.
return []
@ -11,9 +15,74 @@ def extensions():
from setuptools import Extension
from Cython.Build import cythonize
cython_only_code = [
# Alternative, orders of magnitude faster, memory-unsafe version of
# LZ77 which drastically speeds up packet processing time.
Extension(
"bemani.protocol.lz77cpp",
[
"bemani/protocol/lz77cpp.cxx",
],
language="c++",
extra_compile_args=["-std=c++14"],
extra_link_args=["-std=c++14"],
),
# This is a memory-unsafe, orders of magnitude faster threaded implementation
# of the pure python blend code which takes rendering rough animations down
# from over an hour to around a minute.
Extension(
"bemani.format.afp.blend.blendcpp",
[
"bemani/format/afp/blend/blendcpp.pyx",
"bemani/format/afp/blend/blendcppimpl.cxx",
],
language="c++",
extra_compile_args=["-std=c++14"],
extra_link_args=["-std=c++14"],
),
]
if 'EXPERIMENTAL_MYPYC_COMPILER' in os.environ:
from mypyc.build import mypycify
return [
*mypycify(
[
# List of modules that works as compiled mypyc code.
"bemani/protocol",
"bemani/common",
],
),
*cythonize(
[
# Always include code that must be compiled with cython.
*cython_only_code,
# The format module is not ready for mypyc compilation yet, there are some bugs in
# the compiler that prevent us from using it.
Extension(
"bemani.format.dxt",
[
"bemani/format/dxt.py",
]
),
# The types module is not ready for mypyc compilation yet, there are some bugs in
# the compiler that prevent us from using it.
Extension(
"bemani.format.afp.types.generic",
[
"bemani/format/afp/types/generic.py",
]
),
],
language_level=3,
),
]
else:
return [
*cythonize(
[
# Always include code that must be compiled with cython.
*cython_only_code,
# Hot code for anything constructing or parsing a remote game packet.
Extension(
"bemani.protocol.binary",
@ -30,17 +99,6 @@ def extensions():
"bemani/protocol/lz77.py",
]
),
# Alternative, orders of magnitude faster, memory-unsafe version of
# LZ77 which drastically speeds up packet processing time.
Extension(
"bemani.protocol.lz77cpp",
[
"bemani/protocol/lz77cpp.cxx",
],
language="c++",
extra_compile_args=["-std=c++14"],
extra_link_args=["-std=c++14"],
),
# Every single backend service uses this class for construction and
# parsing, so compiling this makes sense.
Extension(
@ -74,19 +132,6 @@ def extensions():
"bemani/protocol/xml.py",
]
),
# This is a memory-unsafe, orders of magnitude faster threaded implementation
# of the pure python blend code which takes rendering rough animations down
# from over an hour to around a minute.
Extension(
"bemani.format.afp.blend.blendcpp",
[
"bemani/format/afp/blend/blendcpp.pyx",
"bemani/format/afp/blend/blendcppimpl.cxx",
],
language="c++",
extra_compile_args=["-std=c++14"],
extra_link_args=["-std=c++14"],
),
# These types include operations such as matrix math and color conversion so
# it is worth it to speed this up when rendering animations.
Extension(
@ -204,10 +249,6 @@ setup(
install_requires=[
req for req in open('requirements.txt').read().split('\n') if len(req) > 0
],
# None of these are required for operating any of the utilities found in this repo.
# They are all present for speed. If you cannot compile arbitrary code or cython,
# remove the ext_modules line and run setuptools again. Everything should work, but
# it will run slower.
ext_modules=extensions(),
cmdclass={
'clean_ext': CleanExtCommand,