forked from apache/pulsar-client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-mac-wheels.sh
More file actions
executable file
·157 lines (128 loc) · 5.73 KB
/
build-mac-wheels.sh
File metadata and controls
executable file
·157 lines (128 loc) · 5.73 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
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
set -e -x
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <python-version> <python-version-long>"
exit 1
fi
ROOT_DIR=$(git rev-parse --show-toplevel)
cd "${ROOT_DIR}"
source build-support/dep-url.sh
CACHE_DIR=$ROOT_DIR/.pulsar-mac-build
PREFIX=${CACHE_DIR}/install
mkdir -p $PREFIX
mkdir -p $PREFIX/lib/
if [ ! -f $PREFIX/lib/libpulsarwithdeps.a ]; then
VERSION=$(cat ./dependencies.yaml | grep pulsar-cpp | awk '{print $2}')
curl -O -L $(pulsar_cpp_base_url $VERSION)/macos-arm64.zip
curl -O -L $(pulsar_cpp_base_url $VERSION)/macos-x86_64.zip
unzip -q macos-arm64.zip -d arm64
unzip -q macos-x86_64.zip -d x86_64
libtool -static -o libpulsarwithdeps.a arm64/lib/libpulsarwithdeps.a x86_64/lib/libpulsarwithdeps.a
mv arm64/include/ $PREFIX/
mv libpulsarwithdeps.a $PREFIX/lib/
rm -rf arm64/ x86_64/ macos-arm64.zip macos-x86_64.zip
fi
PYTHON_VERSION=$1
PYTHON_VERSION_LONG=$2
# When building Python from source, it will read this environment variable to determine the minimum supported macOS version
export MACOSX_DEPLOYMENT_TARGET=13
pushd $CACHE_DIR
# We need to build OpenSSL from source to have universal2 binaries
OPENSSL_VERSION=$(cat $ROOT_DIR/dependencies.yaml | grep openssl | awk '{print $2}')
OPENSSL_VERSION_UNDERSCORE=$(echo $OPENSSL_VERSION | sed 's/\./_/g')
if [ ! -f openssl-OpenSSL_${OPENSSL_VERSION_UNDERSCORE}.done ]; then
echo "Building OpenSSL"
download_dependency $ROOT_DIR/dependencies.yaml openssl
tar xfz OpenSSL_${OPENSSL_VERSION_UNDERSCORE}.tar.gz
mv openssl-OpenSSL_${OPENSSL_VERSION_UNDERSCORE} openssl-OpenSSL_${OPENSSL_VERSION_UNDERSCORE}-arm64
pushd openssl-OpenSSL_${OPENSSL_VERSION_UNDERSCORE}-arm64
echo -e "#include <string.h>\n$(cat test/v3ext.c)" > test/v3ext.c
CFLAGS="-fPIC -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}" \
./Configure --prefix=$PREFIX no-shared no-unit-test darwin64-arm64-cc
make -j8
make install_sw
popd
tar xfz OpenSSL_${OPENSSL_VERSION_UNDERSCORE}.tar.gz
mv openssl-OpenSSL_${OPENSSL_VERSION_UNDERSCORE} openssl-OpenSSL_${OPENSSL_VERSION_UNDERSCORE}-x86_64
pushd openssl-OpenSSL_${OPENSSL_VERSION_UNDERSCORE}-x86_64
echo -e "#include <string.h>\n$(cat test/v3ext.c)" > test/v3ext.c
CFLAGS="-fPIC -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}" \
./Configure --prefix=$PREFIX no-shared no-unit-test darwin64-x86_64-cc
make -j8
make install_sw
popd
# Create universal binaries
lipo -create openssl-OpenSSL_${OPENSSL_VERSION_UNDERSCORE}-arm64/libssl.a openssl-OpenSSL_${OPENSSL_VERSION_UNDERSCORE}-x86_64/libssl.a \
-output $PREFIX/lib/libssl.a
lipo -create openssl-OpenSSL_${OPENSSL_VERSION_UNDERSCORE}-arm64/libcrypto.a openssl-OpenSSL_${OPENSSL_VERSION_UNDERSCORE}-x86_64/libcrypto.a \
-output $PREFIX/lib/libcrypto.a
touch openssl-OpenSSL_${OPENSSL_VERSION_UNDERSCORE}.done
else
echo "Using cached OpenSSL"
fi
if [ ! -f Python-${PYTHON_VERSION_LONG}/.done ]; then
echo "Building Python $PYTHON_VERSION_LONG"
curl -O -L https://www.python.org/ftp/python/${PYTHON_VERSION_LONG}/Python-${PYTHON_VERSION_LONG}.tgz
tar xfz Python-${PYTHON_VERSION_LONG}.tgz
pushd Python-${PYTHON_VERSION_LONG}
export CFLAGS="-fPIC -O3"
./configure --prefix=$PREFIX --enable-shared --enable-universalsdk --with-universal-archs=universal2 --with-openssl=$PREFIX
make -j16
make install
curl -O -L https://files.pythonhosted.org/packages/27/d6/003e593296a85fd6ed616ed962795b2f87709c3eee2bca4f6d0fe55c6d00/wheel-0.37.1-py2.py3-none-any.whl
export SSL_CERT_FILE=/etc/ssl/cert.pem
$PREFIX/bin/pip3 install wheel setuptools
$PREFIX/bin/pip3 install wheel-*.whl
touch .done
popd
else
echo "Using cached Python $PYTHON_VERSION_LONG"
fi
PYBIND11_VERSION=$(cat $ROOT_DIR/dependencies.yaml | grep pybind11 | awk '{print $2}')
if [ ! -f pybind11/.done ]; then
download_dependency $ROOT_DIR/dependencies.yaml pybind11
mkdir -p $PREFIX/include/
cp -rf pybind11-${PYBIND11_VERSION}/include/pybind11 $PREFIX/include/
mkdir -p pybind11
touch pybind11/.done
fi
popd # $CACHE_DIR
PYTHON_CLIENT_VERSION=$(grep -v '^#' pulsar/__about__.py | cut -d "=" -f2 | sed "s/'//g")
echo "Build wheel for Python $PYTHON_VERSION"
PY_EXE=$PREFIX/bin/python3
PIP_EXE=$PREFIX/bin/pip3
ARCHS='arm64;x86_64'
PIP_TAG='universal2'
cmake -B build \
-DCMAKE_OSX_ARCHITECTURES=${ARCHS} \
-DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=$PREFIX \
-DLINK_STATIC=ON \
-DPython3_ROOT_DIR=$PREFIX
cmake --build build --config Release -j8
cp -f build/lib_pulsar.so .
$PY_EXE setup.py bdist_wheel
PY_SPEC=$(echo $PYTHON_VERSION | sed 's/\.//g')
cd /tmp
$PIP_EXE install --no-dependencies --force-reinstall \
$ROOT_DIR/dist/pulsar_client-${PYTHON_CLIENT_VERSION}-cp$PY_SPEC-*-macosx*_${PIP_TAG}.whl
$PY_EXE -c 'import pulsar'