-
-
Notifications
You must be signed in to change notification settings - Fork 392
/
build.sh
270 lines (250 loc) · 7.82 KB
/
build.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
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/bin/sh
#
# Synopsis:
#
# sh build.sh - Build inplace
# sh build.sh test - Build inplace, and run the tests
# sh build.sh wheel - Build a wheel, install, and run the tests
#
# Environment variables:
#
# AUDITWHEEL_PLAT - Linux platform for auditwheel repair
# LIBSSH2_OPENSSL - Where to find openssl
# LIBSSH2_VERSION=<Version> - Build the given version of libssh2
# LIBGIT2_VERSION=<Version> - Build the given version of libgit2
# OPENSSL_VERSION=<Version> - Build the given version of OpenSSL
# (only needed for Mac universal on CI)
#
# Examples.
#
# Build inplace, libgit2 must be available in the path:
#
# sh build.sh
#
# Build libgit2 1.8.4 (will use libssh2 if available), then build pygit2
# inplace:
#
# LIBGIT2_VERSION=1.8.4 sh build.sh
#
# Build libssh2 1.11.1 and libgit2 1.8.4, then build pygit2 inplace:
#
# LIBSSH2_VERSION=1.11.1 LIBGIT2_VERSION=1.8.4 sh build.sh
#
# Build inplace and run the tests:
#
# sh build.sh test
#
# Build a wheel:
#
# sh build.sh wheel
#
set -x # Print every command and variable
set -e # Fail fast
# Variables
ARCH=`uname -m`
KERNEL=`uname -s`
BUILD_TYPE=${BUILD_TYPE:-Debug}
PYTHON=${PYTHON:-python3}
if [ "$CIBUILDWHEEL" != "1" ]; then
PYTHON_TAG=$($PYTHON build_tag.py)
fi
PREFIX="${PREFIX:-$(pwd)/ci/$PYTHON_TAG}"
export LDFLAGS="-Wl,-rpath,$PREFIX/lib"
if [ "$CIBUILDWHEEL" = "1" ]; then
if [ -f /usr/bin/apt-get ]; then
apt-get update
apt-get install wget -y
if [ -z "$OPENSSL_VERSION" ]; then
apt-get install libssl-dev -y
fi
elif [ -f /usr/bin/yum ]; then
yum install wget zlib-devel -y
if [ -z "$OPENSSL_VERSION" ]; then
yum install openssl-devel -y
else
yum install perl-IPC-Cmd -y
fi
elif [ -f /sbin/apk ]; then
apk add wget
if [ -z "$OPENSSL_VERSION" ]; then
apk add openssl-dev
fi
fi
rm -rf ci
mkdir ci || true
cd ci
else
# Create a virtual environment
$PYTHON -m venv $PREFIX
cd ci
fi
# Install zlib
# XXX Build libgit2 with USE_BUNDLED_ZLIB instead?
if [ -n "$ZLIB_VERSION" ]; then
FILENAME=zlib-$ZLIB_VERSION
wget https://www.zlib.net/$FILENAME.tar.gz -N
tar xf $FILENAME.tar.gz
cd $FILENAME
./configure --prefix=$PREFIX
make
make install
cd ..
fi
# Install openssl
if [ -n "$OPENSSL_VERSION" ]; then
FILENAME=openssl-$OPENSSL_VERSION
wget https://www.openssl.org/source/$FILENAME.tar.gz -N --no-check-certificate
if [ "$KERNEL" = "Darwin" ]; then
tar xf $FILENAME.tar.gz
mv $FILENAME openssl-x86
tar xf $FILENAME.tar.gz
mv $FILENAME openssl-arm
cd openssl-x86
./Configure darwin64-x86_64-cc shared
make
cd ../openssl-arm
./Configure enable-rc5 zlib darwin64-arm64-cc no-asm
make
cd ..
mkdir openssl-universal
LIBSSL=$(basename openssl-x86/libssl.*.dylib)
lipo -create openssl-x86/libssl.*.dylib openssl-arm/libssl.*.dylib -output openssl-universal/$LIBSSL
LIBCRYPTO=$(basename openssl-x86/libcrypto.*.dylib)
lipo -create openssl-x86/libcrypto.*.dylib openssl-arm/libcrypto.*.dylib -output openssl-universal/$LIBCRYPTO
cd openssl-universal
install_name_tool -id "@rpath/$LIBSSL" $LIBSSL
install_name_tool -id "@rpath/$LIBCRYPTO" $LIBCRYPTO
OPENSSL_PREFIX=$(pwd)
cd ..
else
# Linux
tar xf $FILENAME.tar.gz
cd $FILENAME
./Configure shared --prefix=$PREFIX --libdir=$PREFIX/lib
make
make install
OPENSSL_PREFIX=$(pwd)
cd ..
fi
fi
# Install libssh2
if [ -n "$LIBSSH2_VERSION" ]; then
FILENAME=libssh2-$LIBSSH2_VERSION
wget https://www.libssh2.org/download/$FILENAME.tar.gz -N --no-check-certificate
tar xf $FILENAME.tar.gz
cd $FILENAME
if [ "$KERNEL" = "Darwin" ] && [ "$CIBUILDWHEEL" = "1" ]; then
cmake . \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_EXAMPLES=OFF \
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
-DOPENSSL_CRYPTO_LIBRARY="../openssl-universal/$LIBCRYPTO" \
-DOPENSSL_SSL_LIBRARY="../openssl-universal/$LIBSSL" \
-DOPENSSL_INCLUDE_DIR="../openssl-x86/include" \
-DBUILD_TESTING=OFF
else
cmake . \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_EXAMPLES=OFF \
-DBUILD_TESTING=OFF
fi
cmake --build . --target install
cd ..
USE_SSH=ON
else
USE_SSH=OFF
fi
# Install libgit2
if [ -n "$LIBGIT2_VERSION" ]; then
FILENAME=libgit2-$LIBGIT2_VERSION
wget https://github.com/libgit2/libgit2/archive/refs/tags/v$LIBGIT2_VERSION.tar.gz -N -O $FILENAME.tar.gz
tar xf $FILENAME.tar.gz
cd $FILENAME
mkdir build -p
cd build
if [ "$KERNEL" = "Darwin" ] && [ "$CIBUILDWHEEL" = "1" ]; then
CMAKE_PREFIX_PATH=$OPENSSL_PREFIX:$PREFIX cmake .. \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_TESTS=OFF \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
-DOPENSSL_CRYPTO_LIBRARY="../openssl-universal/$LIBCRYPTO" \
-DOPENSSL_SSL_LIBRARY="../openssl-universal/$LIBSSL" \
-DOPENSSL_INCLUDE_DIR="../openssl-x86/include" \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DUSE_SSH=$USE_SSH
else
export CFLAGS=-I$PREFIX/include
CMAKE_PREFIX_PATH=$OPENSSL_PREFIX:$PREFIX cmake .. \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_TESTS=OFF \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DUSE_SSH=$USE_SSH
fi
cmake --build . --target install
cd ..
cd ..
export LIBGIT2=$PREFIX
fi
if [ "$CIBUILDWHEEL" = "1" ]; then
if [ "$KERNEL" = "Darwin" ]; then
cp $OPENSSL_PREFIX/*.dylib $PREFIX/lib/
cp $OPENSSL_PREFIX/*.dylib $PREFIX/lib/
echo "PREFIX " $PREFIX
echo "OPENSSL_PREFIX" $OPENSSL_PREFIX
ls -l /Users/runner/work/pygit2/pygit2/ci/
ls -l $PREFIX/lib
fi
# we're done building dependencies, cibuildwheel action will take over
exit 0
fi
# Build pygit2
cd ..
$PREFIX/bin/pip install -U pip wheel
if [ "$1" = "wheel" ]; then
shift
$PREFIX/bin/pip install wheel
$PREFIX/bin/python setup.py bdist_wheel
WHEELDIR=dist
else
# Install Python requirements & build inplace
$PREFIX/bin/pip install -r requirements.txt
$PREFIX/bin/python setup.py build_ext --inplace
fi
# Bundle libraries
if [ "$1" = "bundle" ]; then
shift
WHEELDIR=wheelhouse
case "${KERNEL}" in
Darwin*)
$PREFIX/bin/pip install delocate
$PREFIX/bin/delocate-listdeps dist/pygit2-*macosx*.whl
$PREFIX/bin/delocate-wheel -v -w $WHEELDIR dist/pygit2-*macosx*.whl
$PREFIX/bin/delocate-listdeps $WHEELDIR/pygit2-*macosx*.whl
;;
*) # LINUX
$PREFIX/bin/pip install auditwheel
$PREFIX/bin/auditwheel repair dist/pygit2*-$PYTHON_TAG-*_$ARCH.whl
$PREFIX/bin/auditwheel show $WHEELDIR/pygit2*-$PYTHON_TAG-*_$ARCH.whl
;;
esac
fi
# Tests
if [ "$1" = "test" ]; then
shift
if [ -n "$WHEELDIR" ]; then
$PREFIX/bin/pip install $WHEELDIR/pygit2*-$PYTHON_TAG-*.whl
fi
$PREFIX/bin/pip install -r requirements-test.txt
$PREFIX/bin/pytest --cov=pygit2
fi
# Test .pyi stub file
if [ "$1" = "stubtest" ]; then
shift
$PREFIX/bin/pip install mypy
PYTHONPATH=. $PREFIX/bin/stubtest --mypy-config-file mypy-stubtest.ini pygit2._pygit2
[ $? == 0 ] && echo "stubtest OK"
fi