-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.py
113 lines (92 loc) · 2.75 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
from setuptools import setup, find_packages
from setuptools.command.install import install
import re
import pathlib
import platform
import subprocess
PLATFORM = platform.system()
ROOT_DIR = pathlib.Path().resolve()
PACKAGE_NAME = 'Xray-core'
BINDING_NAME = 'xray'
CMAKE_BUILD_CACHE = 'CMakeBuildCache'
def getXrayCoreVersion():
return '1.8.24'
def runCommand(command):
subprocess.run(command, check=True)
def buildXrayCore():
output = f'{BINDING_NAME}.lib' if PLATFORM == 'Windows' else f'{BINDING_NAME}.a'
runCommand(
[
'go',
'build',
'-C',
'xray-go',
'-o',
f'{ROOT_DIR / "gobuild" / output}',
'-buildmode=c-archive',
'-trimpath',
'-ldflags',
'-s -w -buildid=',
'./main',
]
)
def buildBindings():
configureCache = [
'cmake',
'-S',
'.',
'-B',
CMAKE_BUILD_CACHE,
'-DCMAKE_BUILD_TYPE=Release',
]
if PLATFORM == 'Windows':
configureCache += ['-G', 'MinGW Makefiles']
runCommand(configureCache)
runCommand(
[
'cmake',
'--build',
CMAKE_BUILD_CACHE,
'--target',
BINDING_NAME,
]
)
class InstallXrayCore(install):
def run(self):
buildXrayCore()
buildBindings()
install.run(self)
with open('README.md', 'r', encoding='utf-8') as file:
long_description = file.read()
setup(
name=PACKAGE_NAME,
version=getXrayCoreVersion(),
license='MPL 2.0',
description='Python bindings for Xray-core, the best v2ray-core with XTLS support.',
long_description=long_description,
long_description_content_type='text/markdown',
author='Loren Eteval',
author_email='[email protected]',
url='https://github.com/LorenEteval/Xray-core-python',
cmdclass={'install': InstallXrayCore},
packages=find_packages(),
include_package_data=True,
classifiers=[
'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
'Intended Audience :: Developers',
'Programming Language :: C++',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Operating System :: OS Independent',
'Topic :: Internet',
'Topic :: Internet :: Proxy Servers',
],
zip_safe=False,
)