Skip to content

Commit

Permalink
python: only link extension modules against libpython when building f…
Browse files Browse the repository at this point in the history
…or Windows. Fixes mesonbuild#4117

Windows requires things to be linked, on macOS distutils doesn't link by default.
On Linux etc. things are not so clear, some distros patch distutils to not link,
some don't. In addition the manylinux wheels spec disallows linking against libpython.

Just assume for now that not linking on non-Windows works.
  • Loading branch information
lazka committed Sep 15, 2018
1 parent 3f51745 commit 37eea68
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions mesonbuild/modules/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,21 @@ def extension_module(self, interpreter, state, args, kwargs):

kwargs['install_dir'] = os.path.join(self.platlib_install_path, subdir)

# On macOS and some Linux distros distutils doesn't link extensions
# against libpython. We could call into distutils to mirror the default
# behavior, but let's keep it simple for now and only link on Windows.
# More details: https://github.com/mesonbuild/meson/issues/4117
env = interpreter.environment
link_libpython = mesonlib.for_windows(env.is_cross_build(), env) or mesonlib.for_cygwin(env.is_cross_build(), env)
if not link_libpython:
new_deps = []
for holder in kwargs.get('dependencies', []):
dep = holder.held_object
if isinstance(dep, PythonDependency):
holder = interpreter.holderify(dep.get_partial_dependency(compile_args=True))
new_deps.append(holder)
kwargs['dependencies'] = new_deps

suffix = self.variables.get('EXT_SUFFIX') or self.variables.get('SO') or self.variables.get('.so')

# msys2's python3 has "-cpython-36m.dll", we have to be clever
Expand Down

0 comments on commit 37eea68

Please sign in to comment.