1+ #! bash
2+
13# Build script for manylinux and OSX
24BUILD_PREFIX=${BUILD_PREFIX:-/ usr/ local}
35
46ROOT_DIR=$( dirname $( dirname " ${BASH_SOURCE[0]} " ) )
57
68MB_PYTHON_VERSION=3.9
79
8- function any_python {
9- for cmd in $PYTHON_EXE python3 python; do
10- if [ -n " $( type -t $cmd ) " ]; then
11- echo $cmd
12- return
13- fi
14- done
15- echo " Could not find python or python3"
16- exit 1
17- }
18-
19- function get_os {
20- # Report OS as given by uname
21- # Use any Python that comes to hand.
22- $( any_python) -c ' import platform; print(platform.uname()[0])'
23- }
24-
25-
2610function before_build {
2711 # Manylinux Python version set in build_lib
28- if [ -n " $IS_OSX " ]; then
12+ if [ " $( uname -s ) " == " Darwin " ]; then
2913 if [ ! -e /usr/local/lib ]; then
3014 sudo mkdir -p /usr/local/lib
3115 sudo chmod 777 /usr/local/lib
@@ -39,29 +23,39 @@ function before_build {
3923 # get_macpython_environment ${MB_PYTHON_VERSION} venv
4024 python3.9 -m venv venv
4125 source venv/bin/activate
42- alias gfortran=gfortran-15
26+
27+ unalias gfortran 2> /dev/null || true
28+ source tools/gfortran_utils.sh
29+ download_and_unpack_gfortran ${PLAT} native
30+ export FC=/opt/gfortran/gfortran-darwin-${PLAT} -native/bin/gfortran
31+ which ${FC}
32+ ${FC} --version
33+ local libdir=/opt/gfortran/gfortran-darwin-${PLAT} -native/lib
34+ # Remove conflicting shared objects
35+ rm -fv ${libdir} /libiconv*
36+ export FFLAGS=" -L${libdir} -Wl,-rpath,${libdir} "
37+ # Not clear why this is needed for tests on arm64...
38+ export LDFLAGS=" $FFLAGS "
39+
4340 # Deployment target set by gfortran_utils
4441 echo " Deployment target $MACOSX_DEPLOYMENT_TARGET "
4542
4643 # Build the objconv tool
47- (cd ${ROOT_DIR} /objconv && bash ../tools/build_objconv.sh)
44+ if [[ ! -x objconv/objconv ]]; then
45+ (cd ${ROOT_DIR} /objconv && bash ../tools/build_objconv.sh)
46+ fi
4847 fi
4948}
5049
5150function clean_code {
5251 set -ex
53- # Copied from common_utils.sh, with added debugging
5452 local build_commit=$1
5553 [ -z " $build_commit " ] && echo " build_commit not defined" && exit 1
5654 pushd OpenBLAS
5755 git fetch origin --tags
58- echo after git fetch origin
5956 git checkout $build_commit
60- echo after git checkout $build_commit
6157 git clean -fxd
62- echo after git clean
6358 git submodule update --init --recursive
64- echo after git submodule update
6559 popd
6660}
6761
@@ -108,12 +102,7 @@ function build_lib {
108102 local interface64=${2:- $INTERFACE64 }
109103 local nightly=${3: 0}
110104 local manylinux=${MB_ML_VER:- 1}
111- if [ -n " $IS_OSX " ]; then
112- # Do build, add gfortran hash to end of name
113- do_build_lib " $plat " " gf_${GFORTRAN_SHA: 0: 7} " " $interface64 " " $nightly "
114- else
115- do_build_lib " $plat " " " " $interface64 " " $nightly "
116- fi
105+ do_build_lib " $plat " " $interface64 " " $nightly "
117106}
118107
119108function patch_source {
@@ -129,19 +118,16 @@ function do_build_lib {
129118 # Build openblas lib
130119 # Input arg
131120 # plat - one of i686, x86_64, arm64
132- # suffix (optional) - suffix for output archive name
133- # Suffix added with hyphen prefix
134121 # interface64 (optional) - whether to build ILP64 openblas
135122 # with 64_ symbol suffix
136123 # nightly (optional) - whether to build for nightlies
137124 #
138125 # Depends on globals
139126 # BUILD_PREFIX - install suffix e.g. "/usr/local"
140127 local plat=$1
141- local suffix=$2
142- local interface64=$3
143- local nightly=$4
144- case $( get_os) -$plat in
128+ local interface64=$2
129+ local nightly=$3
130+ case $( uname -s) -$plat in
145131 Linux-x86_64)
146132 local bitness=64
147133 local target=" PRESCOTT"
@@ -150,16 +136,8 @@ function do_build_lib {
150136 Darwin-x86_64)
151137 local bitness=64
152138 local target=" CORE2"
153- # Use gfortran-11
154- unalias gfortran
155- # Since install_fortran uses `uname -a` to determine arch,
156- # force the architecture
157- arch -${PLAT} bash -s << EOF
158- source ${ROOT_DIR} /gfortran-install/gfortran_utils.sh
159- install_gfortran
160- EOF
161- export DYLD_LIBRARY_PATH=/usr/local/lib:$DYLD_LIBRARY_PATH
162139 CFLAGS=" $CFLAGS -arch x86_64"
140+ MACOSX_DEPLOYMENT_TARGET=" 10.9"
163141 export SDKROOT=${SDKROOT:- $(xcrun --show-sdk-path)}
164142 local dynamic_list=" CORE2 NEHALEM SANDYBRIDGE HASWELL SKYLAKEX"
165143 ;;
171149 Linux-aarch64)
172150 local bitness=64
173151 local target=" ARMV8"
174- # manylinux2014 image uses gcc-10, which miscompiles ARMV8SVE and up
175152 if [ " $MB_ML_VER " == " 2014" ]; then
153+ # manylinux2014 image uses gcc-10, which miscompiles ARMV8SVE and up
176154 echo setting DYNAMIC_LIST for manylinux2014 to ARMV8 only
177155 local dynamic_list=" ARMV8"
178156 fi
183161 CFLAGS=" $CFLAGS -ftrapping-math -mmacos-version-min=11.0"
184162 MACOSX_DEPLOYMENT_TARGET=" 11.0"
185163 export SDKROOT=${SDKROOT:- $(xcrun --show-sdk-path)}
186- export DYLD_LIBRARY_PATH=/usr/local/lib:$DYLD_LIBRARY_PATH
187164 ;;
188165 * -s390x)
189166 local bitness=64
201178 1)
202179 local interface_flags=" INTERFACE64=1 SYMBOLSUFFIX=64_ LIBNAMESUFFIX=64_ OBJCONV=$PWD /objconv/objconv" ;
203180 local symbolsuffix=" 64_" ;
204- if [ -n " $IS_OSX " ]; then
205- $PWD /objconv/objconv --help
206- fi
207181 ;;
208182 * )
209183 local interface_flags=" OBJCONV=$PWD /objconv/objconv"
246220 fi
247221 mv $BUILD_PREFIX /lib/pkgconfig/openblas* .pc $BUILD_PREFIX /lib/pkgconfig/scipy-openblas.pc
248222 local plat_tag=$( get_plat_tag $plat )
249- local suff=" "
250- [ -n " $suffix " ] && suff=" -$suffix "
251223 if [ " $interface64 " = " 1" ]; then
252224 # OpenBLAS does not install the symbol suffixed static library,
253225 # do it ourselves
260232 rm $BUILD_PREFIX /lib/pkgconfig/scipy-openblas.pc.bak
261233 fi
262234
263- local out_name=" openblas${symbolsuffix} -${version} -${plat_tag}${suff} .tar.gz"
235+ local out_name=" openblas${symbolsuffix} -${version} -${plat_tag} .tar.gz"
264236 tar zcvf libs/$out_name \
265237 $BUILD_PREFIX /include/* blas* \
266238 $BUILD_PREFIX /include/* lapack* \
0 commit comments