-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py
90 lines (69 loc) · 2.19 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
# © 2019-present nextmv.io inc
import os
import platform
import subprocess
from setuptools import Distribution, setup
try:
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
class MyWheel(_bdist_wheel):
def finalize_options(self):
_bdist_wheel.finalize_options(self)
self.root_is_pure = False
def get_tag(self):
python, abi, plat = _bdist_wheel.get_tag(self)
# python, abi = "py3", "none"
return python, abi, plat
class MyDistribution(Distribution):
def __init__(self, *attrs):
Distribution.__init__(self, *attrs)
self.cmdclass["bdist_wheel"] = MyWheel
def is_pure(self):
return False
def has_ext_modules(self):
return True
except ImportError:
class MyDistribution(Distribution):
def is_pure(self):
return False
def has_ext_modules(self):
return True
# Compile Nextroute binary. We cross-compile (if necessary) for the current
# platform. We also set CGO_ENABLED=0 to ensure that the binary is statically
# linked.
goos = platform.system().lower()
goarch = platform.machine().lower()
if goos not in ["linux", "windows", "darwin"]:
raise Exception(f"unsupported operating system: {goos}")
# Translate the architecture to the Go convention.
if goarch == "x86_64":
goarch = "amd64"
elif goarch == "aarch64":
goarch = "arm64"
if goarch not in ["amd64", "arm64"]:
raise Exception(f"unsupported architecture: {goarch}")
# Compile the binary.
print(f"Compiling Nextroute binary for {goos} {goarch}...")
cwd = os.getcwd()
standalone_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "cmd")
os.chdir(standalone_dir)
call = ["go", "build", "-o", "../src/nextroute/bin/nextroute.exe", "."]
try:
subprocess.check_call(
call,
env={
**os.environ,
"GOOS": goos,
"GOARCH": goarch,
"CGO_ENABLED": "0",
},
)
finally:
os.chdir(cwd)
# Get version from version file.
__version__ = "v0.0.0"
exec(open("./src/nextroute/__about__.py").read())
# Setup package.
setup(
distclass=MyDistribution,
version=__version__,
)