Skip to content

Commit d36bde5

Browse files
build: properly detect MSVC compiler
1 parent ec0eab3 commit d36bde5

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

setup.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
1-
from os import name as os_name
21
from platform import machine
32

43
from setuptools import Extension, setup # type: ignore
4+
from setuptools.command.build_ext import build_ext
5+
6+
7+
class BuildExt(build_ext):
8+
def build_extension(self, ext: Extension):
9+
if self.compiler.compiler_type != "msvc":
10+
ext.extra_compile_args = [
11+
"-std=c11",
12+
"-fvisibility=hidden",
13+
"-Wno-cast-function-type",
14+
"-Werror=implicit-function-declaration",
15+
]
16+
# FIXME: GCC optimizer bug workaround for #330 & #386
17+
if machine().startswith("aarch64"):
18+
ext.extra_compile_args.append("--param=early-inlining-insns=9")
19+
else:
20+
ext.extra_compile_args = ["/std:c11", "/wd4244"]
21+
super().build_extension(ext)
522

6-
if os_name != "nt":
7-
cflags = [
8-
"-std=c11",
9-
"-fvisibility=hidden",
10-
"-Wno-cast-function-type",
11-
"-Werror=implicit-function-declaration",
12-
]
13-
# FIXME: GCC optimizer bug workaround for #330 & #386
14-
if machine().startswith("aarch64"):
15-
cflags.append("--param=early-inlining-insns=9")
16-
else:
17-
cflags = ["/std:c11", "/wd4244"]
1823

1924
setup(
2025
packages=["tree_sitter"],
2126
include_package_data=False,
2227
package_data={
2328
"tree_sitter": ["py.typed", "*.pyi"],
2429
},
30+
cmdclass={
31+
"build_ext": BuildExt,
32+
},
2533
ext_modules=[
2634
Extension(
2735
name="tree_sitter._binding",
@@ -50,7 +58,6 @@
5058
("PY_SSIZE_T_CLEAN", None),
5159
("TREE_SITTER_HIDE_SYMBOLS", None),
5260
],
53-
extra_compile_args=cflags,
5461
)
5562
],
5663
)

0 commit comments

Comments
 (0)