-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_mlpack.osx.sh
executable file
·93 lines (81 loc) · 2.92 KB
/
build_mlpack.osx.sh
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
#!/usr/bin/env bash
#
# Build mlpack's Python bindings inside the cibuildwheel environment.
set -e -u -o pipefail
brew install --force cereal gcc cmake
pip install cython numpy pandas wheel setuptools packaging
export rootdir=`pwd`
# Armadillo must be installed by hand.
#
# If we are building for an arm64 target, then we want to disable everything
# except OpenBLAS.
wget https://files.mlpack.org/armadillo-11.4.1.tar.gz
tar -xvzpf armadillo-11.4.1.tar.gz
cd armadillo-11.4.1/
if [ "$CIBW_ARCHS_MACOS" == "x86_64" ];
then
cmake \
-DCMAKE_OSX_ARCHITECTURES="$CIBW_ARCHS_MACOS" \
-DDETECT_HDF5=OFF \
.
elif [ "$CIBW_ARCHS_MACOS" == "arm64" ];
then
cmake \
-DCMAKE_OSX_ARCHITECTURES="$CIBW_ARCHS_MACOS" \
-DDETECT_HDF5=OFF \
.
else
echo "Unknown architecture \"$CIBW_ARCHS_MACOS\"!"
exit 1
fi
make
cd ../
rm -f armadillo-11.4.1.tar.gz
# ensmallen must also be installed by hand.
wget https://www.ensmallen.org/files/ensmallen-2.19.0.tar.gz
tar -xvzpf ensmallen-2.19.0.tar.gz
rm -f ensmallen-2.19.0.tar.gz
wget https://www.mlpack.org/files/stb.tar.gz
tar -xvzpf stb.tar.gz
rm -rf stb.tar.gz
cd mlpack/
rm -rf build/
mkdir build
cd build/
# _LIBCPP_DISABLE_AVAILABILITY is required to avoid compilation errors claiming
# that any_cast is not available.
cmake \
-DBUILD_PYTHON_BINDINGS=ON \
-DCMAKE_OSX_ARCHITECTURES="$CIBW_ARCHS_MACOS" \
-DCMAKE_CXX_FLAGS="-D_LIBCPP_DISABLE_AVAILABILITY" \
-DBUILD_CLI_EXECUTABLES=OFF \
-DARMADILLO_LIBRARY="$PWD/../../armadillo-11.4.1/libarmadillo.dylib" \
-DARMADILLO_INCLUDE_DIR="$PWD/../../armadillo-11.4.1/tmp/include/" \
-DENSMALLEN_INCLUDE_DIR="$PWD/../../ensmallen-2.19.0/include/" \
-DSTB_IMAGE_INCLUDE_DIR="$PWD/../../stb/include/" \
-DCMAKE_INSTALL_PREFIX="$PWD/../install" \
../
make -j4
# If we are building for ARM64, then all generation of .pyx files will have
# failed because we cannot run any programs compiled for ARM64 (which includes
# the `generate_pyx_*` targets that make the .pyx files). But, we have a way
# out: earlier in the build, before we started emulating, we built all the .pyx
# files and stored them off to the side. So, we will put them back into place,
# and we will then call setup.py build_ext again to build all the Cython
# modules.
if [ "$CIBW_ARCHS_MACOS" == "arm64" ];
then
cp ../py-old/*.pyx src/mlpack/bindings/python/mlpack/
cp ../py-old/*.py src/mlpack/bindings/python/mlpack/
cd src/mlpack/bindings/python
python setup.py build_ext
cd ../../../..
fi
# Manually change the @rpath/libarmadillo.11.dylib to a direct reference.
# This allows delocate-wheel to know exactly where libarmadillo is.
find src/mlpack/bindings/python/ -iname '*.so' -exec \
install_name_tool -change "@rpath/libarmadillo.11.dylib" \
"$rootdir/armadillo-11.4.1/libarmadillo.11.dylib" \
\{\} \;
# Revert to a version of packaging that is sufficient for delocate-wheel.
pip install "packaging>=20.9"