Skip to content

Commit 7ed2885

Browse files
committed
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
1 parent 8f281fb commit 7ed2885

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
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 & 3 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,
@@ -511,9 +512,11 @@ def mypycify(
511512
cflags: List[str] = []
512513
if compiler.compiler_type == 'unix':
513514
cflags += [
514-
'-O{}'.format(opt_level), '-Werror', '-Wno-unused-function', '-Wno-unused-label',
515+
'-O{}'.format(opt_level),
516+
'-g{}'.format(debug_level),
517+
'-Werror', '-Wno-unused-function', '-Wno-unused-label',
515518
'-Wno-unreachable-code', '-Wno-unused-variable',
516-
'-Wno-unused-command-line-argument', '-Wno-unknown-warning-option',
519+
'-Wno-unused-command-line-argument', '-Wno-unknown-warning-option', '-g1'
517520
]
518521
if 'gcc' in compiler.compiler[0] or 'gnu-cc' in compiler.compiler[0]:
519522
# This flag is needed for gcc but does not exist on clang.

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)