diff --git a/mypyc/lib-rt/setup.py b/mypyc/lib-rt/setup.py index b78ad0dbc23e..afbceba060f4 100644 --- a/mypyc/lib-rt/setup.py +++ b/mypyc/lib-rt/setup.py @@ -8,10 +8,12 @@ import os import subprocess import sys -from distutils.command.build_ext import build_ext -from distutils.core import Extension, setup +from distutils import ccompiler, sysconfig from typing import Any +from setuptools import Extension, setup +from setuptools.command.build_ext import build_ext + C_APIS_TO_TEST = [ "init.c", "int_ops.c", @@ -72,6 +74,14 @@ def run(self) -> None: else: # TODO: we need a way to share our preferred C flags and get_extension() logic with # mypyc/build.py without code duplication. + compiler = ccompiler.new_compiler() + sysconfig.customize_compiler(compiler) + cflags: list[str] = [] + if compiler.compiler_type == "unix": + cflags += ["-O3"] + elif compiler.compiler_type == "msvc": + cflags += ["/O2"] + setup( ext_modules=[ Extension( @@ -85,6 +95,7 @@ def run(self) -> None: "getargsfast.c", ], include_dirs=["."], + extra_compile_args=cflags, ) ] )