Skip to content

Commit

Permalink
Reduce amount of debug info injected in extension modules (#11526)
Browse files Browse the repository at this point in the history
This can help in decreasing memory resource requirements on CI and
generating relatively thinner binaries.

Resolves #11507
  • Loading branch information
nehaljwani authored Nov 22, 2021
1 parent 4dfa38c commit 2189714
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions mypyc/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="{}"),
)
"""

Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions mypyc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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',
]
Expand Down
4 changes: 3 additions & 1 deletion mypyc/test/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'):
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2189714

Please sign in to comment.