-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.py
52 lines (36 loc) · 1.38 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
import glob
import platform
import setuptools
def get_platform() -> str:
"""Return the platform on which this code is run.
Returns the platform name stripped of unnecessary information if the platform is known.
Otherwise, returns the full platform name.
"""
known_platforms = {"windows", "linux", "darwin", "cygwin"}
target = platform.system().lower()
for known in known_platforms:
if target.startswith(known):
return known
return target
def create_extension() -> setuptools.Extension:
"""Create the ANTLR C++ extension to be passed to `setuptools.setup`"""
extra_compile_args = {
"windows": ["/DANTLR4CPP_STATIC", "/Zc:__cplusplus", "/std:c++17"],
"linux": ["-std=c++17"],
"darwin": ["-std=c++17", "-D_LIBCPP_DISABLE_AVAILABILITY"],
"cygwin": ["-std=c++17"],
}
sources = glob.glob("src/pytsql/grammar/cpp_src/**/*.cpp", recursive=True)
depends = glob.glob("src/pytsql/grammar/cpp_src/**/*.h", recursive=True)
return setuptools.Extension(
name="pytsql.grammar.sa_tsql_cpp_parser",
include_dirs=["src/pytsql/grammar/cpp_src/antlr4-cpp-runtime"],
sources=sources,
depends=depends,
extra_compile_args=extra_compile_args.get(get_platform(), []),
)
def run_setup():
setuptools.setup(
ext_modules=[create_extension()],
)
run_setup()