Skip to content

parallel build support for ffibuilder.compile() #30

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions src/cffi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ def emit_python_code(self, filename):
recompile(self, module_name, source,
c_file=filename, call_c_compiler=False, **kwds)

def compile(self, tmpdir='.', verbose=0, target=None, debug=None):
def compile(self, tmpdir='.', verbose=0, target=None, debug=None, parallel=None):
"""The 'target' argument gives the final file name of the
compiled DLL. Use '*' to force distutils' choice, suitable for
regular CPython C API modules. Use a file name ending in '.*'
Expand All @@ -724,7 +724,7 @@ def compile(self, tmpdir='.', verbose=0, target=None, debug=None):
module_name, source, source_extension, kwds = self._assigned_source
return recompile(self, module_name, source, tmpdir=tmpdir,
target=target, source_extension=source_extension,
compiler_verbose=verbose, debug=debug, **kwds)
compiler_verbose=verbose, debug=debug, parallel=parallel, **kwds)

def init_once(self, func, tag):
# Read _init_once_cache[tag], which is either (False, lock) if
Expand Down
7 changes: 4 additions & 3 deletions src/cffi/ffiplatform.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ def get_extension(srcfilename, modname, sources=(), **kwds):
allsources.append(os.path.normpath(src))
return Extension(name=modname, sources=allsources, **kwds)

def compile(tmpdir, ext, compiler_verbose=0, debug=None):
def compile(tmpdir, ext, compiler_verbose=0, debug=None, parallel=None):
"""Compile a C extension module using distutils."""

saved_environ = os.environ.copy()
try:
outputfilename = _build(tmpdir, ext, compiler_verbose, debug)
outputfilename = _build(tmpdir, ext, compiler_verbose, debug, parallel)
outputfilename = os.path.abspath(outputfilename)
finally:
# workaround for a distutils bugs where some env vars can
Expand All @@ -27,7 +27,7 @@ def compile(tmpdir, ext, compiler_verbose=0, debug=None):
os.environ[key] = value
return outputfilename

def _build(tmpdir, ext, compiler_verbose=0, debug=None):
def _build(tmpdir, ext, compiler_verbose=0, debug=None, parallel=None):
# XXX compact but horrible :-(
from cffi._shimmed_dist_utils import Distribution, CompileError, LinkError, set_threshold, set_verbosity

Expand All @@ -40,6 +40,7 @@ def _build(tmpdir, ext, compiler_verbose=0, debug=None):
options['force'] = ('ffiplatform', True)
options['build_lib'] = ('ffiplatform', tmpdir)
options['build_temp'] = ('ffiplatform', tmpdir)
options['parallel'] = ('ffiplatform', parallel)
#
try:
old_level = set_threshold(0) or 0
Expand Down
4 changes: 2 additions & 2 deletions src/cffi/recompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ def _patch_for_target(patchlist, target):

def recompile(ffi, module_name, preamble, tmpdir='.', call_c_compiler=True,
c_file=None, source_extension='.c', extradir=None,
compiler_verbose=1, target=None, debug=None, **kwds):
compiler_verbose=1, target=None, debug=None, parallel=None, **kwds):
if not isinstance(module_name, str):
module_name = module_name.encode('ascii')
if ffi._windows_unicode:
Expand Down Expand Up @@ -1562,7 +1562,7 @@ def recompile(ffi, module_name, preamble, tmpdir='.', call_c_compiler=True,
print('%s %r' % (msg, os.path.abspath(tmpdir)))
os.chdir(tmpdir)
outputfilename = ffiplatform.compile('.', ext,
compiler_verbose, debug)
compiler_verbose, debug, parallel)
finally:
os.chdir(cwd)
_unpatch_meths(patchlist)
Expand Down