Skip to content
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

BUG: distutils: fix building mixed C/Fortran extensions #20910

Merged
merged 1 commit into from Jan 27, 2022

Conversation

charris
Copy link
Member

@charris charris commented Jan 27, 2022

Backport of #20881.

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 gh-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 scipy/scipy#8325 and scipy/scipy#15414.

In the build log, this should show up:

WARN: resetting extension 'scipy.integrate._quadpack' language from 'c' to 'f77'.

And then the resetting should actually happen. So not this:

INFO: building 'scipy.integrate._quadpack' extension
INFO: compiling C sources
INFO: C compiler: /home/rgommers/anaconda3/envs/scipy-dev/bin/x86_64-conda-linux-gnu-cc -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/rgommers/anaconda3/envs/scipy-dev/include -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/rgommers/anaconda3/envs/scipy-dev/include -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/rgommers/anaconda3/envs/scipy-dev/include -DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem /home/rgommers/anaconda3/envs/scipy-dev/include -fPIC

INFO: compile options: '-DHAVE_CBLAS -Iscipy/_lib/src -I/home/rgommers/anaconda3/envs/scipy-dev/lib/python3.9/site-packages/numpy/core/include -Ibuild/src.linux-x86_64-3.9/numpy/distutils/include -I/home/rgommers/anaconda3/envs/scipy-dev/include/python3.9 -c'
extra options: '-msse -msse2 -msse3'
INFO: x86_64-conda-linux-gnu-cc: scipy/integrate/_quadpackmodule.c
 
INFO: /home/rgommers/anaconda3/envs/scipy-dev/bin/x86_64-conda-linux-gnu-cc -shared -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--disable-new-dtags -Wl,--gc-sections -Wl,-rpath,/home/rgommers/anaconda3/envs/scipy-dev/lib -Wl,-rpath-link,/home/rgommers/anaconda3/envs/scipy-dev/lib -L/home/rgommers/anaconda3/envs/scipy-dev/lib -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--disable-new-dtags -Wl,--gc-sections -Wl,-rpath,/home/rgommers/anaconda3/envs/scipy-dev/lib -Wl,-rpath-link,/home/rgommers/anaconda3/envs/scipy-dev/lib -L/home/rgommers/anaconda3/envs/scipy-dev/lib -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--disable-new-dtags -Wl,--gc-sections -Wl,-rpath,/home/rgommers/anaconda3/envs/scipy-dev/lib -Wl,-rpath-link,/home/rgommers/anaconda3/envs/scipy-dev/lib -L/home/rgommers/anaconda3/envs/scipy-dev/lib -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/rgommers/anaconda3/envs/scipy-dev/include -DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem /home/rgommers/anaconda3/envs/scipy-dev/include build/temp.linux-x86_64-3.9/scipy/integrate/_quadpackmodule.o -L/home/rgommers/anaconda3/envs/scipy-dev/lib -Lbuild/temp.linux-x86_64-3.9 -lquadpack -lmach -lopenblas -lopenblas -o scipy/integrate/_quadpack.cpython-39-x86_64-linux-gnu.so -Wl,--version-script=build/temp.linux-x86_64-3.9/link-version-scipy.integrate._quadpack.map

But this:

INFO: building 'scipy.integrate._quadpack' extension
INFO: compiling C sources
INFO: C compiler: /home/rgommers/anaconda3/envs/scipy-dev/bin/x86_64-conda-linux-gnu-cc -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/rgommers/anaconda3/envs/scipy-dev/include -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/rgommers/anaconda3/envs/scipy-dev/include -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/rgommers/anaconda3/envs/scipy-dev/include -DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem /home/rgommers/anaconda3/envs/scipy-dev/include -fPIC

INFO: compile options: '-DHAVE_CBLAS -Iscipy/_lib/src -I/home/rgommers/code/numpy/numpy/core/include -Ibuild/src.linux-x86_64-3.9/numpy/distutils/include -I/home/rgommers/anaconda3/envs/scipy-dev/include/python3.9 -c'
extra options: '-msse -msse2 -msse3'
INFO: x86_64-conda-linux-gnu-cc: scipy/integrate/_quadpackmodule.c

INFO: /home/rgommers/anaconda3/envs/scipy-dev/bin/x86_64-conda-linux-gnu-gfortran -Wall -g -Wall -g -shared -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--disable-new-dtags -Wl,--gc-sections -Wl,-rpath,/home/rgommers/anaconda3/envs/scipy-dev/lib -Wl,-rpath-link,/home/rgommers/anaconda3/envs/scipy-dev/lib -L/home/rgommers/anaconda3/envs/scipy-dev/lib build/temp.linux-x86_64-3.9/scipy/integrate/_quadpackmodule.o -L/home/rgommers/anaconda3/envs/scipy-dev/lib -L/home/rgommers/anaconda3/envs/scipy-dev/bin/../lib/gcc/x86_64-conda-linux-gnu/9.4.0/../../../../x86_64-conda-linux-gnu/lib/../lib -L/home/rgommers/anaconda3/envs/scipy-dev/bin/../lib/gcc/x86_64-conda-linux-gnu/9.4.0/../../../../x86_64-conda-linux-gnu/lib/../lib -Lbuild/temp.linux-x86_64-3.9 -lquadpack -lmach -lopenblas -lopenblas -lgfortran -o scipy/integrate/_quadpack.cpython-39-x86_64-linux-gnu.so -Wl,--version-script=build/temp.linux-x86_64-3.9/link-version-scipy.integrate._quadpack.map

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.
@charris charris added this to the 1.22.2 release milestone Jan 27, 2022
@charris charris merged commit d9df288 into numpy:maintenance/1.22.x Jan 27, 2022
@charris charris deleted the backport-20886 branch January 27, 2022 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants