From 6f9df9f06b701839ad930efeea6dfddfcab969af Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Wed, 8 Oct 2025 00:37:07 +0100 Subject: [PATCH 1/2] Make lib-rt/setup.py similar to mypyc extensions --- mypyc/lib-rt/setup.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mypyc/lib-rt/setup.py b/mypyc/lib-rt/setup.py index b78ad0dbc23e..0a0f7991e320 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 import ccompiler, sysconfig from distutils.command.build_ext import build_ext -from distutils.core import Extension, setup from typing import Any +from setuptools import Extension, setup + 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, ) ] ) From 7f1f1749925bce0a973b47217f6a389c5f708ee9 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Wed, 8 Oct 2025 12:53:51 +0100 Subject: [PATCH 2/2] Use setuptools for build_ext as well --- mypyc/lib-rt/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypyc/lib-rt/setup.py b/mypyc/lib-rt/setup.py index 0a0f7991e320..afbceba060f4 100644 --- a/mypyc/lib-rt/setup.py +++ b/mypyc/lib-rt/setup.py @@ -9,10 +9,10 @@ import subprocess import sys from distutils import ccompiler, sysconfig -from distutils.command.build_ext import build_ext from typing import Any from setuptools import Extension, setup +from setuptools.command.build_ext import build_ext C_APIS_TO_TEST = [ "init.c",