@@ -9,36 +9,6 @@ MB_PYTHON_VERSION=3.9
99
1010source $( dirname " ${BASH_SOURCE[0]} " ) /gfortran_compat.sh
1111
12- # Whether to build without a runtime dependency on libgfortran (and so
13- # without libquadmath, which is only ever a dependency of libgfortran itself).
14- #
15- # Enabled for every manylinux and musllinux target. The set of libgfortran
16- # entry points the Fortran LAPACK sources reference is identical on all of
17- # them -- _gfortran_concat_string and _gfortran_etime, plus _gfortran_pow_r*_i8
18- # for INTERFACE64 -- because it comes from the LAPACK Fortran itself
19- # (`SIDE // TRANS`, `x**n`) rather than from anything architecture specific.
20- # If a toolchain cannot support it anyway, build_gfortran_compat returns
21- # non-zero and the build falls back to linking libgfortran as before.
22- #
23- # macOS is excluded for now: the link needs -Wl,--exclude-libs to keep the
24- # compat symbols out of the dylib's export table, and ld64 has no equivalent,
25- # so it would be a hard link failure rather than a fallback. See
26- # tools/gfortran_compat.sh. Windows never gets here -- it uses
27- # tools/build_steps_windows.sh, which already static-links libgfortran and
28- # asserts that libquadmath is not pulled in.
29- #
30- # Set NO_LIBGFORTRAN=0 in a CI matrix row to opt that row out, or
31- # NO_LIBGFORTRAN=1 to force it on.
32- function want_no_libgfortran {
33- # want_no_libgfortran <plat> (plat accepted but not currently needed --
34- # the decision is per-OS, and callers already have it to hand)
35- [ -n " $NO_LIBGFORTRAN " ] && { [ " $NO_LIBGFORTRAN " = " 1" ]; return $? ; }
36- case " $( uname -s) " in
37- Linux) return 0 ;;
38- * ) return 1 ;;
39- esac
40- }
41-
4212function before_build {
4313 # install gfortran, objconv on macOS
4414 if [ " $( uname -s) " == " Darwin" ]; then
@@ -72,10 +42,30 @@ function before_build {
7242 # Deployment target set by gfortran_utils
7343 echo " Deployment target $MACOSX_DEPLOYMENT_TARGET "
7444
45+ # The tarball ships libgfortran as a dylib only; fetch the static
46+ # archive of the same gcc release (tools/gfortran_compat.sh).
47+ local libgfortran_a
48+ if ! libgfortran_a=$( download_macos_libgfortran_a " ${PLAT} " ) ; then
49+ echo " ERROR: cannot fetch the static libgfortran for ${PLAT} " >&2
50+ exit 1
51+ fi
52+ export LIBGFORTRAN_A=" $libgfortran_a "
53+
7554 # Build the objconv tool
7655 if [[ ! -x objconv/objconv ]]; then
7756 (cd ${ROOT_DIR} /objconv && bash ../tools/build_objconv.sh)
7857 fi
58+ else
59+ # Red Hat keeps static libraries in separate *-static subpackages, so
60+ # the images on a system gcc rather than a gcc-toolset (manylinux_2_39,
61+ # i.e. riscv64) have no libgfortran.a. The archive is in the CRB repo,
62+ # which they already enable. A no-op on gcc-toolset images and Alpine.
63+ if ! find_libgfortran_a > /dev/null; then
64+ echo " no static libgfortran; installing libgfortran-static"
65+ { dnf install -y libgfortran-static \
66+ || yum install -y libgfortran-static; } \
67+ || echo " WARNING: could not install libgfortran-static"
68+ fi
7969 fi
8070}
8171
@@ -202,23 +192,17 @@ function build_lib {
202192 esac
203193 interface_flags=" $interface_flags SYMBOLPREFIX=scipy_ LIBNAMEPREFIX=scipy_ FIXED_LIBNAME=1"
204194
205- # Drop the libgfortran/libquadmath runtime dependency where we can. If
206- # the toolchain cannot support it (no static libgfortran.a, or the
207- # objects we need are no longer self-contained) fall back to the old
208- # behaviour rather than failing the build -- see tools/gfortran_compat.sh.
209- local compat_lib=" "
210- if want_no_libgfortran " $plat " ; then
211- if compat_lib=$( build_gfortran_compat " $PWD /build/gfortran_compat" " $interface64 " ) ; then
212- # TIMER=NONE selects LAPACK's second_NONE.f/dsecnd_NONE.f, which
213- # removes the only reference to _gfortran_etime. SECOND/DSECND
214- # then return 0.0, as they already do in a C_LAPACK build.
215- interface_flags=" $interface_flags NO_LIBGFORTRAN=1 LIBGFORTRAN_COMPAT=$compat_lib TIMER=NONE"
216- echo " building without a libgfortran runtime dependency"
217- else
218- compat_lib=" "
219- echo " WARNING: cannot drop libgfortran on ${MB_ML_LIBC:- manylinux} -$plat , linking it as usual"
220- fi
195+ # Replace the libgfortran/libquadmath runtime dependency with the compat
196+ # archive; a toolchain that cannot supply it fails the build. TIMER=NONE
197+ # selects LAPACK's second_NONE.f/dsecnd_NONE.f, removing the only
198+ # reference to _gfortran_etime. See tools/gfortran_compat.sh.
199+ local compat_lib
200+ if ! compat_lib=$( build_gfortran_compat " $PWD /build/gfortran_compat" " $interface64 " ) ; then
201+ echo " ERROR: cannot build the libgfortran compat archive for" \
202+ " ${MB_ML_LIBC:- manylinux} -$plat " >&2
203+ exit 1
221204 fi
205+ interface_flags=" $interface_flags NO_LIBGFORTRAN=1 LIBGFORTRAN_COMPAT=$compat_lib TIMER=NONE"
222206
223207 mkdir -p libs
224208 set -x
@@ -269,25 +253,20 @@ function build_lib {
269253 rm $BUILD_PREFIX /lib/pkgconfig/scipy-openblas.pc.bak
270254 fi
271255
272- if [ -n " $compat_lib " ]; then
273- # The shared library picked these up from the link line (see
274- # LIBGFORTRAN_COMPAT_LINK in the patch), but the static library is
275- # assembled from OpenBLAS's own objects only. Add them so
276- # that linking libscipy_openblas*.a does not need libgfortran either
277- # -- the .pc file no longer advertises -lgfortran in Libs.private.
278- # Done after the INTERFACE64 branch above, which overwrites the
279- # installed archive with the symbol-renamed one. The renaming does
280- # not touch _gfortran_* names, so order is safe either way.
281- local compat_dir=$( dirname " $compat_lib " )
282- for static_lib in $BUILD_PREFIX /lib/libscipy_openblas* .a; do
283- # An unmatched glob arrives as a literal, and `ar crs` would
284- # happily create an archive at that bogus path.
285- [ -f " $static_lib " ] || continue
286- ar crs " $static_lib " " $compat_dir " /* .o
287- done
288- assert_no_fortran_runtime $BUILD_PREFIX /lib/libscipy_openblas* .so \
289- $BUILD_PREFIX /lib/libscipy_openblas* .dylib
290- fi
256+ # The shared library picked these up from the link line (see
257+ # LIBGFORTRAN_COMPAT_LINK in the patch), but the static one is assembled
258+ # from OpenBLAS's own objects only; add them there too, so that linking
259+ # libscipy_openblas*.a does not need libgfortran either. Must come after
260+ # the INTERFACE64 branch above, which overwrites the installed archive.
261+ local compat_dir=$( dirname " $compat_lib " )
262+ for static_lib in $BUILD_PREFIX /lib/libscipy_openblas* .a; do
263+ # An unmatched glob arrives as a literal, and `ar crs` would happily
264+ # create an archive at that bogus path.
265+ [ -f " $static_lib " ] || continue
266+ ar crs " $static_lib " " $compat_dir " /* .o
267+ done
268+ assert_no_fortran_runtime $BUILD_PREFIX /lib/libscipy_openblas* .so \
269+ $BUILD_PREFIX /lib/libscipy_openblas* .dylib
291270
292271 local out_name=" openblas.tar.gz"
293272 tar zcvf libs/$out_name \
0 commit comments