-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathbuild_steps.sh
More file actions
233 lines (217 loc) · 8.75 KB
/
build_steps.sh
File metadata and controls
233 lines (217 loc) · 8.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!bash
# Build script for manylinux and OSX
BUILD_PREFIX=${BUILD_PREFIX:-/usr/local}
ROOT_DIR=$(dirname $(dirname "${BASH_SOURCE[0]}"))
MB_PYTHON_VERSION=3.9
function before_build {
# install gfortran, objconv on macOS
if [ "$(uname -s)" == "Darwin" ]; then
if [ ! -e /usr/local/lib ]; then
sudo mkdir -p /usr/local/lib
sudo chmod 777 /usr/local/lib
touch /usr/local/lib/.dir_exists
fi
if [ ! -e /usr/local/include ]; then
sudo mkdir -p /usr/local/include
sudo chmod 777 /usr/local/include
touch /usr/local/include/.dir_exists
fi
# get_macpython_environment ${MB_PYTHON_VERSION} venv
python3.9 -m venv venv
source venv/bin/activate
unalias gfortran 2>/dev/null || true
source tools/gfortran_utils.sh
download_and_unpack_gfortran ${PLAT} native
export FC=/opt/gfortran/gfortran-darwin-${PLAT}-native/bin/gfortran
which ${FC}
${FC} --version
local libdir=/opt/gfortran/gfortran-darwin-${PLAT}-native/lib
# Remove conflicting shared objects
rm -fv ${libdir}/libiconv*
export FFLAGS="-L${libdir} -Wl,-rpath,${libdir}"
# Not clear why this is needed for tests on arm64...
export LDFLAGS="$FFLAGS"
# Deployment target set by gfortran_utils
echo "Deployment target $MACOSX_DEPLOYMENT_TARGET"
# Build the objconv tool
if [[ ! -x objconv/objconv ]]; then
(cd ${ROOT_DIR}/objconv && bash ../tools/build_objconv.sh)
fi
fi
}
function clean_code {
set -ex
local build_commit=$1
[ -z "$build_commit" ] && echo "build_commit not defined" && exit 1
pushd OpenBLAS
git fetch origin --tags
git checkout $build_commit
git clean -fxd
git submodule update --init --recursive
popd
}
function get_plat_tag {
# Copied from gfortran-install/gfortran_utils.sh, modified for MB_ML_LIBC
# Modify fat architecture tags on macOS to reflect compiled architecture
# For non-darwin, report manylinux version
local plat=$1
local mb_ml_ver=${MB_ML_VER:-1}
local mb_ml_libc=${MB_ML_LIBC:-manylinux}
case $plat in
i686|x86_64|arm64|universal2|intel|aarch64|s390x|ppc64le|loongarch64) ;;
*) echo Did not recognize plat $plat; return 1 ;;
esac
local uname=${2:-$(uname)}
if [ "$uname" != "Darwin" ]; then
if [ "$plat" == "intel" ]; then
echo plat=intel not allowed for Manylinux
return 1
fi
echo "${mb_ml_libc}${mb_ml_ver}_${plat}"
return
fi
# macOS 32-bit arch is i386
[ "$plat" == "i686" ] && plat="i386"
local target=$(echo $MACOSX_DEPLOYMENT_TARGET | tr .- _)
echo "macosx_${target}_${plat}"
}
function patch_source {
# Runs inside OpenBLAS directory
# Make the patches by git format-patch <old commit>
for f in $(ls ../patches); do
echo applying patch $f
git apply ../patches/$f
done
# local version=$(git describe --tags --abbrev=8 | sed -e "s/^v//" | sed -e "s/\\./-/g")
# sed -e "s/^VERSION = .*/VERSION = ${version}/" -i.bak Makefile.rule
}
function build_lib {
# OSX or manylinux build
#
# Input arg
# plat - one of i686, x86_64, arm64
# interface64 - 1 if build with INTERFACE64 and SYMBOLSUFFIX
#
# Depends on globals
# BUILD_PREFIX - install suffix e.g. "/usr/local"
# MB_ML_VER
set -x
local plat=${1:-$PLAT}
local interface64=${2:-$INTERFACE64}
case $(uname -s)-$plat in
Linux-x86_64)
local bitness=64
local target="PRESCOTT"
local dynamic_list="PRESCOTT NEHALEM SANDYBRIDGE HASWELL SKYLAKEX"
;;
Darwin-x86_64)
local bitness=64
local target="CORE2"
CFLAGS="$CFLAGS -arch x86_64"
MACOSX_DEPLOYMENT_TARGET="10.9"
export SDKROOT=${SDKROOT:-$(xcrun --show-sdk-path)}
local dynamic_list="CORE2 NEHALEM SANDYBRIDGE HASWELL SKYLAKEX"
;;
*-i686)
local bitness=32
local target="PRESCOTT"
local dynamic_list="PRESCOTT NEHALEM SANDYBRIDGE HASWELL"
;;
Linux-aarch64)
local bitness=64
local target="ARMV8"
;;
Darwin-arm64)
local bitness=64
local target="VORTEX"
CFLAGS="$CFLAGS -ftrapping-math -mmacos-version-min=11.0"
MACOSX_DEPLOYMENT_TARGET="11.0"
export SDKROOT=${SDKROOT:-$(xcrun --show-sdk-path)}
;;
*-s390x)
# The TargetList.txt has only ZARCH_GENERIC, Z13, Z14. Not worth
# messing with dynamic lists.
local bitness=64
local target="ZARCH_GENERIC"
;;
*-ppc64le)
local bitness=64
local target="POWER8"
;;
Linux-loongarch64)
local target="GENERIC"
;;
*) echo "Strange plat value $plat"; exit 1 ;;
esac
case $interface64 in
1)
local interface_flags="INTERFACE64=1 SYMBOLSUFFIX=64_ LIBNAMESUFFIX=64_ OBJCONV=$PWD/objconv/objconv";
local symbolsuffix="64_";
;;
*)
local interface_flags="OBJCONV=$PWD/objconv/objconv"
local symbolsuffix="";
;;
esac
interface_flags="$interface_flags SYMBOLPREFIX=scipy_ LIBNAMEPREFIX=scipy_ FIXED_LIBNAME=1"
mkdir -p libs
set -x
git config --global --add safe.directory '*'
pushd OpenBLAS
patch_source
echo start building
if [ "$plat" == "loongarch64" ]; then
# https://github.com/OpenMathLib/OpenBLAS/blob/develop/.github/workflows/loongarch64.yml#L65
echo -n > utest/test_dsdot.c
echo "Due to the qemu versions 7.2 causing utest cases to fail,"
echo "the utest dsdot:dsdot_n_1 have been temporarily disabled."
elif [ "$plat" == "s390x" ]; then
sed -i 's/CTEST(samin, positive_step_1_N_70){/CTEST_SKIP(samin, positive_step_1_N_70){/g' ./utest/test_extensions/test_samin.c
sed -i 's/CTEST(samin, negative_step_1_N_70){/CTEST_SKIP(samin, negative_step_1_N_70){/g' ./utest/test_extensions/test_samin.c
sed -i 's/CTEST(damin, positive_step_1_N_70){/CTEST_SKIP(damin, positive_step_1_N_70){/g' ./utest/test_extensions/test_damin.c
sed -i 's/CTEST(damin, negative_step_1_N_70){/CTEST_SKIP(damin, negative_step_1_N_70){/g' ./utest/test_extensions/test_damin.c
echo "the utest samin/damin have been temporarily disabled."
echo "QEMU does not support the 'lper' /'lpdr' instructions used"
fi
if [ "$plat" == "loongarch64" ] || [ "$plat" == "ppc64le" ] || [ "$plat" == "s390x" ]; then
sed -i 's/CTEST(fork, safety)/CTEST_SKIP(fork, safety)/g' ./utest/test_fork.c
sed -i 's/CTEST(fork, safety_after_fork_in_parent)/CTEST_SKIP(fork, safety_after_fork_in_parent)/g' ./utest/test_post_fork.c
echo "QEMU has a race condition preventing fork tests to work as expected"
fi
if [ -n "$dynamic_list" ]; then
CFLAGS="$CFLAGS -fvisibility=hidden -Wno-uninitialized" \
make BUFFERSIZE=20 DYNAMIC_ARCH=1 \
USE_OPENMP=0 NUM_THREADS=64 \
DYNAMIC_LIST="$dynamic_list" \
BINARY="$bitness" $interface_flags \
TARGET="$target"
else
CFLAGS="$CFLAGS -fvisibility=hidden -Wno-uninitialized" \
make BUFFERSIZE=20 DYNAMIC_ARCH=1 \
USE_OPENMP=0 NUM_THREADS=64 \
BINARY="$bitness" $interface_flags \
TARGET="$target"
fi
make PREFIX=$BUILD_PREFIX $interface_flags install
popd
mv $BUILD_PREFIX/lib/pkgconfig/openblas*.pc $BUILD_PREFIX/lib/pkgconfig/scipy-openblas.pc
local plat_tag=$(get_plat_tag $plat)
if [ "$interface64" = "1" ]; then
# OpenBLAS does not install the symbol suffixed static library,
# do it ourselves
static_libname=$(basename `find OpenBLAS -maxdepth 1 -type f -name '*.a' \! -name '*.dll.a'`)
renamed_libname=$(basename `find OpenBLAS -maxdepth 1 -type f -name '*.renamed'`)
cp -f "OpenBLAS/${renamed_libname}" "$BUILD_PREFIX/lib/${static_libname}"
sed -e "s/\(^Cflags.*\)/\1 -DBLAS_SYMBOL_PREFIX=scipy_ -DBLAS_SYMBOL_SUFFIX=64_/" -i.bak $BUILD_PREFIX/lib/pkgconfig/scipy-openblas.pc
else
sed -e "s/\(^Cflags.*\)/\1 -DBLAS_SYMBOL_PREFIX=scipy_/" -i.bak $BUILD_PREFIX/lib/pkgconfig/scipy-openblas.pc
rm $BUILD_PREFIX/lib/pkgconfig/scipy-openblas.pc.bak
fi
local out_name="openblas.tar.gz"
tar zcvf libs/$out_name \
$BUILD_PREFIX/include/*blas* \
$BUILD_PREFIX/include/*lapack* \
$BUILD_PREFIX/lib/libscipy_openblas* \
$BUILD_PREFIX/lib/pkgconfig/scipy-openblas* \
$BUILD_PREFIX/lib/cmake/openblas
}