Skip to content

Commit 2189714

Browse files
authored
Reduce amount of debug info injected in extension modules (#11526)
This can help in decreasing memory resource requirements on CI and generating relatively thinner binaries. Resolves #11507
1 parent 4dfa38c commit 2189714

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

mypyc/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from mypyc.build import mypycify
2323
2424
setup(name='mypyc_output',
25-
ext_modules=mypycify({}, opt_level="{}"),
25+
ext_modules=mypycify({}, opt_level="{}", debug_level="{}"),
2626
)
2727
"""
2828

@@ -35,10 +35,11 @@ def main() -> None:
3535
pass
3636

3737
opt_level = os.getenv("MYPYC_OPT_LEVEL", '3')
38+
debug_level = os.getenv("MYPYC_DEBUG_LEVEL", '1')
3839

3940
setup_file = os.path.join(build_dir, 'setup.py')
4041
with open(setup_file, 'w') as f:
41-
f.write(setup_format.format(sys.argv[1:], opt_level))
42+
f.write(setup_format.format(sys.argv[1:], opt_level, debug_level))
4243

4344
# We don't use run_setup (like we do in the test suite) because it throws
4445
# away the error code from distutils, and we don't care about the slight

mypyc/build.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ def mypycify(
431431
*,
432432
only_compile_paths: Optional[Iterable[str]] = None,
433433
verbose: bool = False,
434-
opt_level: str = '3',
434+
opt_level: str = "3",
435+
debug_level: str = "1",
435436
strip_asserts: bool = False,
436437
multi_file: bool = False,
437438
separate: Union[bool, List[Tuple[List[str], Optional[str]]]] = False,
@@ -454,6 +455,7 @@ def mypycify(
454455
verbose: Should mypyc be more verbose. Defaults to false.
455456
456457
opt_level: The optimization level, as a string. Defaults to '3' (meaning '-O3').
458+
debug_level: The debug level, as a string. Defaults to '1' (meaning '-g1').
457459
strip_asserts: Should asserts be stripped from the generated code.
458460
459461
multi_file: Should each Python module be compiled into its own C source file.
@@ -511,7 +513,9 @@ def mypycify(
511513
cflags: List[str] = []
512514
if compiler.compiler_type == 'unix':
513515
cflags += [
514-
'-O{}'.format(opt_level), '-Werror', '-Wno-unused-function', '-Wno-unused-label',
516+
'-O{}'.format(opt_level),
517+
'-g{}'.format(debug_level),
518+
'-Werror', '-Wno-unused-function', '-Wno-unused-label',
515519
'-Wno-unreachable-code', '-Wno-unused-variable',
516520
'-Wno-unused-command-line-argument', '-Wno-unknown-warning-option',
517521
]

mypyc/test/test_run.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ def run_case_step(self, testcase: DataDrivenTestCase, incremental_step: int) ->
242242
check_serialization_roundtrip(ir)
243243

244244
opt_level = int(os.environ.get('MYPYC_OPT_LEVEL', 0))
245+
debug_level = int(os.environ.get('MYPYC_DEBUG_LEVEL', 0))
245246

246247
setup_file = os.path.abspath(os.path.join(WORKDIR, 'setup.py'))
247248
# 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) ->
250251
separate,
251252
cfiles,
252253
self.multi_file,
253-
opt_level))
254+
opt_level,
255+
debug_level))
254256

255257
if not run_setup(setup_file, ['build_ext', '--inplace']):
256258
if testcase.config.getoption('--mypyc-showc'):

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,12 @@ def run(self):
144144

145145
from mypyc.build import mypycify
146146
opt_level = os.getenv('MYPYC_OPT_LEVEL', '3')
147+
debug_level = os.getenv('MYPYC_DEBUG_LEVEL', '1')
147148
force_multifile = os.getenv('MYPYC_MULTI_FILE', '') == '1'
148149
ext_modules = mypycify(
149150
mypyc_targets + ['--config-file=mypy_bootstrap.ini'],
150151
opt_level=opt_level,
152+
debug_level=debug_level,
151153
# Use multi-file compilation mode on windows because without it
152154
# our Appveyor builds run out of memory sometimes.
153155
multi_file=sys.platform == 'win32' or force_multifile,

0 commit comments

Comments
 (0)