|
1 | | -from os import name as os_name |
2 | 1 | from platform import machine |
3 | 2 |
|
4 | 3 | 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) |
5 | 22 |
|
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"] |
18 | 23 |
|
19 | 24 | setup( |
20 | 25 | packages=["tree_sitter"], |
21 | 26 | include_package_data=False, |
22 | 27 | package_data={ |
23 | 28 | "tree_sitter": ["py.typed", "*.pyi"], |
24 | 29 | }, |
| 30 | + cmdclass={ |
| 31 | + "build_ext": BuildExt, |
| 32 | + }, |
25 | 33 | ext_modules=[ |
26 | 34 | Extension( |
27 | 35 | name="tree_sitter._binding", |
|
50 | 58 | ("PY_SSIZE_T_CLEAN", None), |
51 | 59 | ("TREE_SITTER_HIDE_SYMBOLS", None), |
52 | 60 | ], |
53 | | - extra_compile_args=cflags, |
54 | 61 | ) |
55 | 62 | ], |
56 | 63 | ) |
0 commit comments