Skip to content

Commit 6f9df9f

Browse files
committed
Make lib-rt/setup.py similar to mypyc extensions
1 parent f2ebd79 commit 6f9df9f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

mypyc/lib-rt/setup.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import os
99
import subprocess
1010
import sys
11+
from distutils import ccompiler, sysconfig
1112
from distutils.command.build_ext import build_ext
12-
from distutils.core import Extension, setup
1313
from typing import Any
1414

15+
from setuptools import Extension, setup
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)