-
Notifications
You must be signed in to change notification settings - Fork 7
/
setup.py
63 lines (49 loc) · 1.99 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
import os
import subprocess
import sys
from pathlib import Path
import pybind11
from setuptools import setup, Extension, Command
from setuptools.command.build_ext import build_ext
import versioneer
# https://github.com/pybind/cmake_example/blob/master/setup.py
class CMakeExtension(Extension):
def __init__(self, name: str, sourcedir: str = "") -> None:
super().__init__(name, sources=[])
self.sourcedir = os.fspath(Path(sourcedir).resolve())
cmdclass: dict[str, type[Command]] = versioneer.get_cmdclass()
class CMakeBuild(cmdclass.get("build_ext", build_ext)):
def build_extension(self, ext):
ext_fullpath = Path.cwd() / self.get_ext_fullpath("")
src_dir = ext_fullpath.parent.resolve()
platform_args = []
if sys.platform == "win32":
platform_args.extend(["-G", "Visual Studio 17 2022"])
if sys.maxsize > 2**32:
platform_args.extend(["-A", "x64"])
else:
platform_args.extend(["-A", "Win32"])
platform_args.extend(["-T", "v143"])
if subprocess.run(
[
"cmake",
*platform_args,
f"-DPYTHON_EXECUTABLE={sys.executable}",
f"-Dpybind11_DIR={pybind11.get_cmake_dir().replace(os.sep, '/')}",
f"-DCMAKE_INSTALL_PREFIX=install",
f"-DSRC_INSTALL_DIR={src_dir}",
"-B",
"build",
]
).returncode:
raise RuntimeError("Error configuring amulet_nbt")
if subprocess.run(["cmake", "--build", "build", "--config", "Release"]).returncode:
raise RuntimeError("Error installing amulet_nbt")
if subprocess.run(["cmake", "--install", "build", "--config", "Release"]).returncode:
raise RuntimeError("Error installing amulet_nbt")
cmdclass["build_ext"] = CMakeBuild
setup(
version=versioneer.get_version(),
cmdclass=cmdclass,
ext_modules=[CMakeExtension("amulet_nbt._amulet_nbt")],
)