8000 BUG: distutils: fix building mixed C/Fortran extensions · rgommers/numpy@1e83f83 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e83f83

Browse files
committed
BUG: distutils: fix building mixed C/Fortran extensions
In SciPy we had a couple of cases where we build a Python extension with C source files but linked against static libraries built from Fortran code. Those should be using the Fortran linker, but this was broken in 1.22.0 by numpygh-19713 (the PR that introduced C++ in NumPy). This fixes a few issues in the `build_ext` command, and documents better what is going on there. Should close SciPy issues 8325 and 15414.
1 parent 6218e76 commit 1e83f83

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

numpy/distutils/command/build_ext.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,36 @@ def report(copt):
231231
l = ext.language or self.compiler.detect_language(ext.sources)
232232
if l:
233233
ext_languages.add(l)
234+
234235
# reset language attribute for choosing proper linker
236+
#
237+
# When we build extensions with multiple languages, we have to
238+
# choose a linker. The rules here are:
239+
# 1. if there is Fortran code, always prefer the Fortran linker,
240+
# 2. otherwise prefer C++ over C,
241+
# 3. Users can force a particular linker by using
242+
# `language='c'` # or 'c++', 'f90', 'f77'
243+
# in their config.add_extension() calls.
235244
if 'c++' in ext_languages:
236245
ext_language = 'c++'
237-
elif 'f90' in ext_languages:
246+
else:
247+
ext_language = 'c' # default
248+
249+
has_fortran = False
250+
if 'f90' in ext_languages:
238251
ext_language = 'f90'
252+
has_fortran = True
239253
elif 'f77' in ext_languages:
240254
ext_language = 'f77'
241-
else:
242-
ext_language = 'c' # default
243-
if l and l != ext_language and ext.language:
244-
log.warn('resetting extension %r language from %r to %r.' %
245-
(ext.name, l, ext_language))
246-
if not ext.language:
255+
has_fortran = True
256+
257+
if not ext.language or has_fortran:
258+
if l and l != ext_language and ext.language:
259+
log.warn('resetting extension %r language from %r to %r.' %
260+
(ext.name, l, ext_language))
261+
247262
ext.language = ext_language
263+
248264
# global language
249265
all_languages.update(ext_languages)
250266

0 commit comments

Comments
 (0)
0