forked from borglab/gtsam-manylinux-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-macos-new.sh
executable file
·160 lines (126 loc) · 4.95 KB
/
build-macos-new.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
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
#!/bin/bash
set -x -e
function retry {
local retries=$1
shift
local count=0
until "$@"; do
exit=$?
wait=$((2 ** $count))
count=$(($count + 1))
if [ $count -lt $retries ]; then
echo "Retry $count/$retries exited $exit, retrying in $wait seconds..."
sleep $wait
else
echo "Retry $count/$retries exited $exit, no more retries left."
return $exit
fi
done
return 0
}
brew update
# brew uninstall bazel
# brew upgrade
brew install wget "$1" cmake || true
CURRDIR=$(pwd)
GTSAM_RELEASE_TAG="4.2.0"
GTSAM_LIB_VERSION="4.2"
GTSAM_PYTHON_VERSION="4.2"
# Build Boost staticly
mkdir -p boost_build
cd boost_build
retry 3 wget https://boostorg.jfrog.io/artifactory/main/release/1.73.0/source/boost_1_73_0.tar.gz
tar xzf boost_1_73_0.tar.gz
cd boost_1_73_0
./bootstrap.sh --prefix=$CURRDIR/boost_install --with-libraries=serialization,filesystem,thread,system,atomic,date_time,timer,chrono,program_options,regex clang-darwin
./b2 -j$(sysctl -n hw.logicalcpu) cxxflags="-fPIC" runtime-link=static variant=release link=static install
cd $CURRDIR
mkdir -p $CURRDIR/wheelhouse_unrepaired
mkdir -p $CURRDIR/wheelhouse
git clone https://github.com/borglab/gtsam.git --depth 1 -b $GTSAM_RELEASE_TAG
cd $CURRDIR/gtsam
patch -p0 < ../setup.py.in.patch
cd $CURRDIR
ORIGPATH=$PATH
PYTHON_LIBRARY=$(cd $(dirname $0); pwd)/libpython-not-needed-symbols-exported-by-interpreter
touch ${PYTHON_LIBRARY}
declare -a PYTHON_VERS=( $1 )
# Get the python version numbers only by splitting the string
split_array=(${PYTHON_VERS//@/ })
VERSION_NUMBER=${split_array[1]}
# Compile wheels
for PYVER in ${PYTHON_VERS[@]}; do
PYBIN="$(brew --prefix "$1")/bin"
PIP="${PYBIN}/pip${VERSION_NUMBER}"
${PIP} install -r ./requirements.txt
PYTHONVER="$(basename $(dirname $PYBIN))"
BUILDDIR="$CURRDIR/gtsam_$PYTHONVER/gtsam_build"
mkdir -p $BUILDDIR
cd $BUILDDIR
export PATH=$PYBIN:$PYBIN:$(brew --prefix)/bin:$ORIGPATH
${PIP} install delocate
PYTHON_EXECUTABLE=${PYBIN}/python${VERSION_NUMBER}
#PYTHON_INCLUDE_DIR=$( find -L ${PYBIN}/../include/ -name Python.h -exec dirname {} \; )
# echo ""
# echo "PYTHON_EXECUTABLE:${PYTHON_EXECUTABLE}"
# echo "PYTHON_INCLUDE_DIR:${PYTHON_INCLUDE_DIR}"
# echo "PYTHON_LIBRARY:${PYTHON_LIBRARY}"
cmake $CURRDIR/gtsam -DCMAKE_BUILD_TYPE=Release \
-DGTSAM_BUILD_TESTS=OFF -DGTSAM_BUILD_UNSTABLE=ON \
-DGTSAM_USE_QUATERNIONS=OFF \
-DGTSAM_BUILD_EXAMPLES_ALWAYS=OFF \
-DGTSAM_PYTHON_VERSION=$VERSION_NUMBER \
-DGTSAM_BUILD_WITH_MARCH_NATIVE=OFF \
-DGTSAM_ALLOW_DEPRECATED_SINCE_V42=OFF \
-DCMAKE_INSTALL_PREFIX="$BUILDDIR/../gtsam_install" \
-DBoost_USE_STATIC_LIBS=ON \
-DBoost_USE_STATIC_RUNTIME=ON \
-DBOOST_ROOT=$CURRDIR/boost_install \
-DCMAKE_PREFIX_PATH=$CURRDIR/boost_install/lib/cmake/Boost-1.73.0/ \
-DBoost_NO_SYSTEM_PATHS=OFF \
-DBUILD_STATIC_METIS=ON \
-DGTSAM_BUILD_PYTHON=ON \
-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
# -DGTSAM_USE_CUSTOM_PYTHON_LIBRARY=ON \
# -DPYTHON_INCLUDE_DIRS:PATH=${PYTHON_INCLUDE_DIR} \
# -DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY}
ec=$?
if [ $ec -ne 0 ]; then
echo "Error:"
cat ./CMakeCache.txt
exit $ec
fi
set -e -x
make -j$(sysctl -n hw.logicalcpu) install
# "${PYBIN}/pip" wheel . -w "/io/wheelhouse/"
cd python
${PYTHON_EXECUTABLE} setup.py bdist_wheel
cp ./dist/*.whl $CURRDIR/wheelhouse_unrepaired
done
# Bundle external shared libraries into the wheels
for whl in $CURRDIR/wheelhouse_unrepaired/*.whl; do
delocate-listdeps --all "$whl"
delocate-wheel -w "$CURRDIR/wheelhouse" -v "$whl"
rm $whl
done
cd $CURRDIR/wheelhouse
# Only for 3.8
# if [ "$VERSION_NUMBER" != "3.8" ]; then
exit 0
# fi
for whln in $CURRDIR/wheelhouse/*.whl; do
whl=$(basename "${whln}" .whl)
unzip $whl.whl -d $whl
cd $whl
install_name_tool -change @loader_path/../../../gtsam.dylibs/libgtsam.$GTSAM_LIB_VERSION.dylib @loader_path/../gtsam.dylibs/libgtsam.$GTSAM_LIB_VERSION.dylib gtsam-$GTSAM_PYTHON_VERSION.data/purelib/gtsam/gtsam.cpython-*-darwin.so
install_name_tool -change @loader_path/../../../gtsam.dylibs/libgtsam.$GTSAM_LIB_VERSION.dylib @loader_path/../gtsam.dylibs/libgtsam.$GTSAM_LIB_VERSION.dylib gtsam-$GTSAM_PYTHON_VERSION.data/purelib/gtsam_unstable/gtsam_unstable.cpython-*-darwin.so
install_name_tool -change @loader_path/../../../gtsam.dylibs/libgtsam_unstable.$GTSAM_LIB_VERSION.dylib @loader_path/../gtsam.dylibs/libgtsam_unstable.$GTSAM_LIB_VERSION.dylib gtsam-$GTSAM_PYTHON_VERSION.data/purelib/gtsam_unstable/gtsam_unstable.cpython-*-darwin.so
zip -r ../$whl.whl ./*
cd $CURRDIR/wheelhouse
rm -rf $whl
done
# Install packages and test
# for PYBIN in /opt/python/*/bin/; do
# "${PYBIN}/pip" install python-manylinux-demo --no-index -f /io/wheelhouse
# (cd "$HOME"; "${PYBIN}/nosetests" pymanylinuxdemo)
# done