generated from dopt-python/py311-cython
81 lines
1.9 KiB
Python
81 lines
1.9 KiB
Python
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from Cython.Build import cythonize
|
|
from Cython.Compiler import Options
|
|
from setuptools import Extension, setup
|
|
|
|
# Cython compilation options
|
|
Options.docstrings = False
|
|
Options.embed_pos_in_docstring = False
|
|
Options.annotate = False
|
|
Options.fast_fail = True
|
|
|
|
OPEN_MP = False
|
|
DEBUG = bool(os.getenv("DOPT_DEBUG", None))
|
|
linetrace_opt: bool = False
|
|
if DEBUG:
|
|
linetrace_opt = True
|
|
|
|
# includes
|
|
OPENSSL_DIR = (Path(__file__).parent / "openssl").resolve()
|
|
assert OPENSSL_DIR.exists()
|
|
openssl_include = OPENSSL_DIR / "include"
|
|
assert openssl_include.exists()
|
|
openssl_lib = OPENSSL_DIR / "lib"
|
|
assert openssl_lib.exists()
|
|
|
|
ext = Extension(
|
|
name="polluck_blockchain.placeholder_native",
|
|
sources=["src/polluck_blockchain/placeholder_native.pyx"],
|
|
include_dirs=[str(openssl_include)],
|
|
library_dirs=[str(openssl_lib)],
|
|
libraries=["libssl", "libcrypto"],
|
|
)
|
|
|
|
|
|
ext_modules = cythonize(
|
|
[
|
|
ext,
|
|
# "src/polluck_blockchain/placeholder.py",
|
|
# "src/polluck_blockchain/placeholder_native.pyx",
|
|
# "src/polluck_blockchain/python_translate.py",
|
|
],
|
|
compiler_directives={
|
|
"language_level": 3,
|
|
"boundscheck": False,
|
|
"wraparound": False,
|
|
"embedsignature": False,
|
|
"annotation_typing": True,
|
|
"linetrace": linetrace_opt,
|
|
},
|
|
)
|
|
|
|
|
|
if DEBUG:
|
|
ext_modules[0].define_macros.append(("CYTHON_TRACE", "1"))
|
|
|
|
compiler_args: list[str] = []
|
|
linker_args: list[str] = []
|
|
|
|
|
|
if sys.platform.startswith("win") and not DEBUG:
|
|
c_args = ["/O2", "/GL", "/Gy"]
|
|
l_args = ["/LTCG", "/OPT:REF", "/OPT:ICF"]
|
|
if OPEN_MP:
|
|
c_args.extend(["/openmp:llvm"])
|
|
l_args.extend(["/openmp:llvm"])
|
|
else:
|
|
c_args = tuple()
|
|
l_args = tuple()
|
|
|
|
compiler_args.extend(c_args)
|
|
linker_args.extend(l_args)
|
|
|
|
for ext in ext_modules:
|
|
ext.extra_compile_args.extend(compiler_args)
|
|
ext.extra_link_args.extend(linker_args)
|
|
|
|
setup(ext_modules=ext_modules)
|