-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
162 lines (147 loc) · 5.86 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# fcecodec Copyright (C) 2021-2024 Benjamin Futasz <https://github.com/bfut>
#
# You may not redistribute this program without its source code.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
setup.py - adapted from https://github.com/pybind/python_example/blob/master/setup.py
"""
import os
import platform
import pathlib
import re
import setuptools
import sys
import sysconfig
# Available at setup time due to pyproject.toml
from pybind11.setup_helpers import Pybind11Extension, build_ext
if os.environ.get("FCECVERBOSE") is not None:
print(f'FCECVERBOSE={os.environ["FCECVERBOSE"]}')
script_path = pathlib.Path(__file__).parent.resolve()
os.chdir(script_path)
__version__ = re.findall(
r"#define FCECVERS \"(.*)\"",
(script_path / "./src/fcelib/fcelib.h").read_text("utf-8")
)[0]
print(f"VERSION_INFO={__version__}")
long_description = (script_path / "./python/README.md").read_text(encoding="utf-8")
if sys.version_info.minor < 13 or sysconfig.get_config_var("Py_GIL_DISABLED") != 1 or sys._is_gil_enabled() == True:
os.environ["PYMEM_MALLOC"] = ""
if sys.version_info.minor >= 13:
if sysconfig.get_config_var("Py_GIL_DISABLED") == 1 and sys._is_gil_enabled() == False:
print(f'sysconfig.get_config_var("Py_GIL_DISABLED") = {sysconfig.get_config_var("Py_GIL_DISABLED")}')
print(f'sys._is_gil_enabled() = {sys._is_gil_enabled()}')
extra_compile_args = []
if "PYMEM_MALLOC" in os.environ:
print(f'PYMEM_MALLOC={os.environ["PYMEM_MALLOC"]}')
extra_compile_args += [ "-DPYMEM_MALLOC" ]
if "FCELIB_PYTHON_DEBUG" in os.environ:
print(f'FCELIB_PYTHON_DEBUG={os.environ["FCELIB_PYTHON_DEBUG"]}')
extra_compile_args += [ "-FCELIB_PYTHON_DEBUG" ]
if platform.system().lower() == "windows":
extra_compile_args += [
("/D_CRT_NONSTDC_NO_WARNINGS"),
("/wd4267"), # prevents warnings on conversion from size_t to int
("/wd4996"), # prevents warnings on fopen() and other POSIX functions
("/std:c++latest"), ("/Zc:__cplusplus"), # sets __cplusplus
]
else:
extra_compile_args += [
# # debug
# ("-g"),
# ("-Og"),
# ("-O0"),
("-O2"),
# ("-pedantic-errors"),
("-pedantic"),
("-fvisibility=hidden"), # sets the default symbol visibility to hidden
("-Wformat-security"),
("-Wdeprecated-declarations"),
]
if "gcc" in platform.python_compiler().lower():
extra_compile_args += [
("-Wno-unused-parameter"),
("-Wno-missing-field-initializers"),
("-fasynchronous-unwind-tables"),
("-Wall"),
("-Wextra"),
("-Wstack-protector"),
("-Woverlength-strings"),
("-Wpointer-arith"),
("-Wunused-local-typedefs"),
("-Wunused-result"),
("-Wvarargs"),
("-Wvla"),
("-Wwrite-strings"), # ("-Wno-discarded-qualifiers"),
# # https://developers.redhat.com/blog/2018/03/21/compiler-and-linker-flags-gcc
("-D_FORTIFY_SOURCE=2"),
# ("-D_GLIBCXX_ASSERTIONS"), # runtime bounds-checking for C++ strings and containers
# ("-fexceptions"),
# ("-fplugin=annobin"),
("-fstack-clash-protection"),
("-fstack-protector-strong"),
# ("-fcf-protection"),
("-Werror=format-security"),
# ("-Werror=implicit-function-declaration"), # C only
# ("-Wl,-z,defs"),
# ("-Wl,-z,now"),
# ("-Wl,-z,relro"),
]
elif "clang" in platform.python_compiler().lower():
extra_compile_args += [
# ("-Weverything"),
("-Wno-braced-scalar-init"),
("-Wno-deprecated-declarations"),
# ("-Wno-newline-eof"),
]
# The main interface is through Pybind11Extension.
# * You can add cxx_std=11/14/17, and then build_ext can be removed.
# * You can set include_pybind11=false to add the include directory yourself,
# say from a submodule.
#
# Note:
# Sort input source files if you glob sources to ensure bit-for-bit
# reproducible builds (https://github.com/pybind/python_example/pull/53)
ext_modules = [
Pybind11Extension(
"fcecodec",
sorted(["python/fcecodecmodule.cpp"]),
# Example: passing in the version to the compiled code
define_macros=[
# https://github.com/pybind/python_example/issues/12
# https://github.com/pybind/python_example/blob/master/src/main.cpp
("VERSION_INFO", __version__),
("FCECVERBOSE", os.environ.get("FCECVERBOSE", 0)), # 0 if key not set
],
extra_compile_args=extra_compile_args
),
]
setuptools.setup(
name="fcecodec",
version=__version__,
author="Benjamin Futasz",
url="https://github.com/bfut/fcecodec",
license="GPLv2+",
description="FCE decoder/encoder",
long_description=long_description,
long_description_content_type="text/markdown",
ext_modules=ext_modules,
# extras_require={"test": "pytest"},
# # Currently, build_ext only provides an optional "highest supported C++
# # level" feature, but in the future it may provide more features.
cmdclass={"build_ext": build_ext},
zip_safe=False,
python_requires=">=3.10",
)