Skip to content

Commit eec826e

Browse files
authored
Make lib-rt/setup.py similar to mypyc extensions (#20022)
Two small things here: * Use `setuptools` extension class. * Use same optimization levels we use when compiling mypy.
1 parent 59e9e7d commit eec826e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

mypyc/lib-rt/setup.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import os
99
import subprocess
1010
import sys
11-
from distutils.command.build_ext import build_ext
12-
from distutils.core import Extension, setup
11+
from distutils import ccompiler, sysconfig
1312
from typing import Any
1413

14+
from setuptools import Extension, setup
15+
from setuptools.command.build_ext import build_ext
16+
1517
C_APIS_TO_TEST = [
1618
"init.c",
1719
"int_ops.c",
@@ -72,6 +74,14 @@ def run(self) -> None:
7274
else:
7375
# TODO: we need a way to share our preferred C flags and get_extension() logic with
7476
# mypyc/build.py without code duplication.
77+
compiler = ccompiler.new_compiler()
78+
sysconfig.customize_compiler(compiler)
79+
cflags: list[str] = []
80+
if compiler.compiler_type == "unix":
81+
cflags += ["-O3"]
82+
elif compiler.compiler_type == "msvc":
83+
cflags += ["/O2"]
84+
7585
setup(
7686
ext_modules=[
7787
Extension(
@@ -85,6 +95,7 @@ def run(self) -> None:
8595
"getargsfast.c",
8696
],
8797
include_dirs=["."],
98+
extra_compile_args=cflags,
8899
)
89100
]
90101
)

0 commit comments

Comments
 (0)