From 42a1e0865d8423ecd490be9e4108823e87e0b4fa Mon Sep 17 00:00:00 2001 From: Nehal J Wani Date: Thu, 11 Nov 2021 14:05:02 -0500 Subject: [PATCH] Reduce amount of debug info injected in extension modules This can help in decreasing memory resource requirements on CI and generating relatively thinner binaries. Resolves #11507 --- mypyc/__main__.py | 5 +++-- mypyc/build.py | 8 ++++++-- mypyc/test/test_run.py | 4 +++- setup.py | 2 ++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/mypyc/__main__.py b/mypyc/__main__.py index a11426001f77f..aaaf9a83c8c56 100644 --- a/mypyc/__main__.py +++ b/mypyc/__main__.py @@ -22,7 +22,7 @@ from mypyc.build import mypycify setup(name='mypyc_output', - ext_modules=mypycify({}, opt_level="{}"), + ext_modules=mypycify({}, opt_level="{}", debug_level="{}"), ) """ @@ -35,10 +35,11 @@ def main() -> None: pass opt_level = os.getenv("MYPYC_OPT_LEVEL", '3') + debug_level = os.getenv("MYPYC_DEBUG_LEVEL", '1') setup_file = os.path.join(build_dir, 'setup.py') with open(setup_file, 'w') as f: - f.write(setup_format.format(sys.argv[1:], opt_level)) + f.write(setup_format.format(sys.argv[1:], opt_level, debug_level)) # We don't use run_setup (like we do in the test suite) because it throws # away the error code from distutils, and we don't care about the slight diff --git a/mypyc/build.py b/mypyc/build.py index 026da76baaea4..571fb0dd2f5a0 100644 --- a/mypyc/build.py +++ b/mypyc/build.py @@ -431,7 +431,8 @@ def mypycify( *, only_compile_paths: Optional[Iterable[str]] = None, verbose: bool = False, - opt_level: str = '3', + opt_level: str = "3", + debug_level: str = "1", strip_asserts: bool = False, multi_file: bool = False, separate: Union[bool, List[Tuple[List[str], Optional[str]]]] = False, @@ -454,6 +455,7 @@ def mypycify( verbose: Should mypyc be more verbose. Defaults to false. opt_level: The optimization level, as a string. Defaults to '3' (meaning '-O3'). + debug_level: The debug level, as a string. Defaults to '1' (meaning '-g1'). strip_asserts: Should asserts be stripped from the generated code. multi_file: Should each Python module be compiled into its own C source file. @@ -511,7 +513,9 @@ def mypycify( cflags: List[str] = [] if compiler.compiler_type == 'unix': cflags += [ - '-O{}'.format(opt_level), '-Werror', '-Wno-unused-function', '-Wno-unused-label', + '-O{}'.format(opt_level), + '-g{}'.format(debug_level), + '-Werror', '-Wno-unused-function', '-Wno-unused-label', '-Wno-unreachable-code', '-Wno-unused-variable', '-Wno-unused-command-line-argument', '-Wno-unknown-warning-option', ] diff --git a/mypyc/test/test_run.py b/mypyc/test/test_run.py index 731f53c6a3f5e..3876fee2a1579 100644 --- a/mypyc/test/test_run.py +++ b/mypyc/test/test_run.py @@ -242,6 +242,7 @@ def run_case_step(self, testcase: DataDrivenTestCase, incremental_step: int) -> check_serialization_roundtrip(ir) opt_level = int(os.environ.get('MYPYC_OPT_LEVEL', 0)) + debug_level = int(os.environ.get('MYPYC_DEBUG_LEVEL', 0)) setup_file = os.path.abspath(os.path.join(WORKDIR, 'setup.py')) # We pass the C file information to the build script via setup.py unfortunately @@ -250,7 +251,8 @@ def run_case_step(self, testcase: DataDrivenTestCase, incremental_step: int) -> separate, cfiles, self.multi_file, - opt_level)) + opt_level, + debug_level)) if not run_setup(setup_file, ['build_ext', '--inplace']): if testcase.config.getoption('--mypyc-showc'): diff --git a/setup.py b/setup.py index 36163f254265a..6781230d675e7 100644 --- a/setup.py +++ b/setup.py @@ -144,10 +144,12 @@ def run(self): from mypyc.build import mypycify opt_level = os.getenv('MYPYC_OPT_LEVEL', '3') + debug_level = os.getenv('MYPYC_DEBUG_LEVEL', '1') force_multifile = os.getenv('MYPYC_MULTI_FILE', '') == '1' ext_modules = mypycify( mypyc_targets + ['--config-file=mypy_bootstrap.ini'], opt_level=opt_level, + debug_level=debug_level, # Use multi-file compilation mode on windows because without it # our Appveyor builds run out of memory sometimes. multi_file=sys.platform == 'win32' or force_multifile,