Skip to content

Commit 9390009

Browse files
committed
Cleanup setup.py to build windows via cmake, similar to the chiapos cleanup
1 parent d42c1e5 commit 9390009

File tree

1 file changed

+19
-133
lines changed

1 file changed

+19
-133
lines changed

setup.py

+19-133
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def build_extension(self, ext):
116116
cmake_args += [
117117
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format(cfg.upper(), extdir)
118118
]
119-
if sys.maxsize > 2 ** 32:
119+
if sys.maxsize > 2**32:
120120
cmake_args += ["-A", "x64"]
121121
build_args += ["--", "/m"]
122122
else:
@@ -131,136 +131,22 @@ def build_extension(self, ext):
131131
subprocess.check_call(["cmake", "--build", "."] + build_args)
132132

133133

134-
class get_pybind_include(object):
135-
"""Helper class to determine the pybind11 include path
136-
137-
The purpose of this class is to postpone importing pybind11
138-
until it is actually installed, so that the ``get_include()``
139-
method can be invoked."""
140-
141-
def __init__(self, user=False):
142-
self.user = user
143-
144-
def __str__(self):
145-
import pybind11
146-
147-
return pybind11.get_include(self.user)
148-
149-
150-
ext_modules = [
151-
Extension(
152-
"chiavdf",
153-
sorted(
154-
[
155-
"src/python_bindings/fastvdf.cpp",
156-
"src/refcode/lzcnt.c",
157-
]
158-
),
159-
include_dirs=[
160-
# Path to pybind11 headers
161-
get_pybind_include(),
162-
get_pybind_include(user=True),
163-
"mpir_gc_x64",
164-
],
165-
library_dirs=["mpir_gc_x64"],
166-
libraries=["mpir"],
167-
language="c++",
134+
build.sub_commands.append(("build_hook", lambda x: True)) # type: ignore
135+
install.sub_commands.append(("install_hook", lambda x: True))
136+
137+
setup(
138+
name="chiavdf",
139+
author="Florin Chirica",
140+
author_email="[email protected]",
141+
description="Chia vdf verification (wraps C++)",
142+
license="Apache License",
143+
python_requires=">=3.8",
144+
long_description=open("README.md").read(),
145+
long_description_content_type="text/markdown",
146+
url="https://github.com/Chia-Network/chiavdf",
147+
ext_modules=[CMakeExtension("chiavdf", "src")],
148+
cmdclass=dict(
149+
build_ext=CMakeBuild, install_hook=install_hook, build_hook=build_hook
168150
),
169-
]
170-
171-
172-
# As of Python 3.6, CCompiler has a `has_flag` method.
173-
# cf http://bugs.python.org/issue26689
174-
def has_flag(compiler, flagname):
175-
"""Return a boolean indicating whether a flag name is supported on
176-
the specified compiler.
177-
"""
178-
import tempfile
179-
180-
with tempfile.NamedTemporaryFile("w", suffix=".cpp") as f:
181-
f.write("int main (int argc, char **argv) { return 0; }")
182-
try:
183-
compiler.compile([f.name], extra_postargs=[flagname])
184-
except errors.CompileError:
185-
return False
186-
return True
187-
188-
189-
def cpp_flag(compiler):
190-
"""Return the -std=c++[11/14/17] compiler flag.
191-
192-
The newer version is prefered over c++11 (when it is available).
193-
"""
194-
flags = ["-std=c++17", "-std=c++14", "-std=c++11"]
195-
196-
for flag in flags:
197-
if has_flag(compiler, flag):
198-
return flag
199-
200-
raise RuntimeError("Unsupported compiler -- at least C++11 support " "is needed!")
201-
202-
203-
class BuildExt(build_ext):
204-
"""A custom build extension for adding compiler-specific options."""
205-
206-
c_opts = {
207-
"msvc": ["/EHsc", "/std:c++17"],
208-
"unix": [""],
209-
}
210-
l_opts = {
211-
"msvc": [],
212-
"unix": [""],
213-
}
214-
215-
def build_extensions(self):
216-
ct = self.compiler.compiler_type
217-
opts = self.c_opts.get(ct, [])
218-
link_opts = self.l_opts.get(ct, [])
219-
if ct == "unix":
220-
opts.append('-DVERSION_INFO="%s"' % self.distribution.get_version())
221-
opts.append(cpp_flag(self.compiler))
222-
if has_flag(self.compiler, "-fvisibility=hidden"):
223-
opts.append("-fvisibility=hidden")
224-
elif ct == "msvc":
225-
opts.append('/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version())
226-
for ext in self.extensions:
227-
ext.extra_compile_args = opts
228-
ext.extra_link_args = link_opts
229-
build_ext.build_extensions(self)
230-
231-
232-
if platform.system() == "Windows":
233-
setup(
234-
name="chiavdf",
235-
author="Mariano Sorgente",
236-
author_email="[email protected]",
237-
description="Chia vdf verification (wraps C++)",
238-
license="Apache License",
239-
python_requires=">=3.8",
240-
long_description=open("README.md").read(),
241-
long_description_content_type="text/markdown",
242-
url="https://github.com/Chia-Network/chiavdf",
243-
ext_modules=ext_modules,
244-
cmdclass={"build_ext": BuildExt},
245-
zip_safe=False,
246-
)
247-
else:
248-
build.sub_commands.append(("build_hook", lambda x: True)) # type: ignore
249-
install.sub_commands.append(("install_hook", lambda x: True))
250-
251-
setup(
252-
name="chiavdf",
253-
author="Florin Chirica",
254-
author_email="[email protected]",
255-
description="Chia vdf verification (wraps C++)",
256-
license="Apache License",
257-
python_requires=">=3.8",
258-
long_description=open("README.md").read(),
259-
long_description_content_type="text/markdown",
260-
url="https://github.com/Chia-Network/chiavdf",
261-
ext_modules=[CMakeExtension("chiavdf", "src")],
262-
cmdclass=dict(
263-
build_ext=CMakeBuild, install_hook=install_hook, build_hook=build_hook
264-
),
265-
zip_safe=False,
266-
)
151+
zip_safe=False,
152+
)

0 commit comments

Comments
 (0)