Skip to content

[mypyc] include instead of compiling rt .c files in non-multifile mode #7770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions mypyc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,15 @@ def mypycify(
'/wd9025', # warning about overriding /GL
]

# Copy the runtime library in
# In multi-file mode, copy the runtime library in.
# Otherwise it just gets #included to save on compiler invocations
shared_cfilenames = []
for name in ['CPy.c', 'getargs.c']:
rt_file = os.path.join(build_dir, name)
with open(os.path.join(include_dir(), name), encoding='utf-8') as f:
write_file(rt_file, f.read())
shared_cfilenames.append(rt_file)
if multi_file:
for name in ['CPy.c', 'getargs.c']:
rt_file = os.path.join(build_dir, name)
with open(os.path.join(include_dir(), name), encoding='utf-8') as f:
write_file(rt_file, f.read())
shared_cfilenames.append(rt_file)

extensions = []
for (group_sources, lib_name), (cfilenames, deps) in zip(groups, group_cfilenames):
Expand Down
6 changes: 6 additions & 0 deletions mypyc/emitmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ def generate_c_for_modules(self) -> List[Tuple[str, str]]:
multi_file = self.use_shared_lib and self.multi_file

base_emitter = Emitter(self.context)
# When not in multi-file mode we just include the runtime
# library c files to reduce the number of compiler invocations
# needed
if not self.multi_file:
base_emitter.emit_line('#include "CPy.c"')
base_emitter.emit_line('#include "getargs.c"')
base_emitter.emit_line('#include "__native{}.h"'.format(self.group_suffix))
base_emitter.emit_line('#include "__native_internal{}.h"'.format(self.group_suffix))
emitter = base_emitter
Expand Down
5 changes: 3 additions & 2 deletions mypyc/test/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
from mypyc.build import mypycify

setup(name='test_run_output',
ext_modules=mypycify({}, separate={}, skip_cgen_input={!r}, strip_asserts=False),
ext_modules=mypycify({}, separate={}, skip_cgen_input={!r}, strip_asserts=False,
multi_file={}),
)
"""

Expand Down Expand Up @@ -192,7 +193,7 @@ def run_case_inner(self, testcase: DataDrivenTestCase) -> None:
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
with open(setup_file, 'w', encoding='utf-8') as f:
f.write(setup_format.format(module_paths, self.separate, cfiles))
f.write(setup_format.format(module_paths, self.separate, cfiles, self.multi_file))

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