|
18 | 18 | # under the License. |
19 | 19 | # |
20 | 20 |
|
21 | | -set -ex |
22 | | -cd `dirname $0` |
| 21 | +set -e |
| 22 | +cd `dirname $0`/../.. |
23 | 23 |
|
24 | | -python3 -m venv venv |
25 | | -source venv/bin/activate |
26 | | -python3 -m pip install pyyaml |
27 | | - |
28 | | -MACOSX_DEPLOYMENT_TARGET=10.15 |
29 | | -if [[ -z ${ARCH} ]]; then |
30 | | - ARCH=`uname -m` |
31 | | -fi |
32 | | - |
33 | | -BUILD_DIR=$PWD/.build |
34 | | -INSTALL_DIR=$PWD/.install |
35 | | -PREFIX=$BUILD_DIR/install |
36 | | -mkdir -p $BUILD_DIR |
37 | | -cp -f ../../build-support/dep-version.py $BUILD_DIR/ |
38 | | -cp -f ../../dependencies.yaml $BUILD_DIR/ |
39 | | - |
40 | | -pushd $BUILD_DIR |
41 | | - |
42 | | -BOOST_VERSION=$(./dep-version.py boost) |
43 | | -ZLIB_VERSION=$(./dep-version.py zlib) |
44 | | -OPENSSL_VERSION=$(./dep-version.py openssl) |
45 | | -PROTOBUF_VERSION=$(./dep-version.py protobuf) |
46 | | -ZSTD_VERSION=$(./dep-version.py zstd) |
47 | | -SNAPPY_VERSION=$(./dep-version.py snappy) |
48 | | -CURL_VERSION=$(./dep-version.py curl) |
49 | | - |
50 | | -if [ ! -f boost/.done ]; then |
51 | | - echo "Building Boost $BOOST_VERSION" |
52 | | - curl -O -L https://github.com/boostorg/boost/releases/download/boost-${BOOST_VERSION}/boost-${BOOST_VERSION}.tar.gz |
53 | | - tar zxf boost-${BOOST_VERSION}.tar.gz |
54 | | - mkdir -p $PREFIX/include |
55 | | - pushd boost-${BOOST_VERSION} |
56 | | - ./bootstrap.sh |
57 | | - ./b2 headers |
58 | | - cp -rf boost $PREFIX/include/ |
59 | | - popd |
60 | | - mkdir -p boost |
61 | | - touch boost/.done |
62 | | -else |
63 | | - echo "Using cached Boost $BOOST_VERSION" |
| 24 | +if [[ -z $ARCH ]]; then |
| 25 | + ARCH=$(uname -m) |
| 26 | + echo "Use default ARCH: $ARCH" |
64 | 27 | fi |
65 | | - |
66 | | -if [ ! -f zlib-${ZLIB_VERSION}/.done ]; then |
67 | | - echo "Building ZLib $ZLIB_VERSION" |
68 | | - curl -O -L https://zlib.net/fossils/zlib-${ZLIB_VERSION}.tar.gz |
69 | | - tar zxf zlib-${ZLIB_VERSION}.tar.gz |
70 | | - pushd zlib-$ZLIB_VERSION |
71 | | - CFLAGS="-fPIC -O3 -arch ${ARCH} -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}" ./configure --prefix=$PREFIX |
72 | | - make -j16 |
73 | | - make install |
74 | | - touch .done |
75 | | - popd |
| 28 | +if [[ $ARCH == "x86_64" ]]; then |
| 29 | + export VCPKG_TRIPLET=x64-osx |
| 30 | +elif [[ $ARCH == "arm64" ]]; then |
| 31 | + export VCPKG_TRIPLET=arm64-osx |
76 | 32 | else |
77 | | - echo "Using cached ZLib $ZLIB_VERSION" |
| 33 | + echo "Invalid ARCH: $ARCH" |
| 34 | + exit 1 |
78 | 35 | fi |
79 | 36 |
|
80 | | -OPENSSL_VERSION_UNDERSCORE=$(echo $OPENSSL_VERSION | sed 's/\./_/g') |
81 | | -if [ ! -f openssl-OpenSSL_${OPENSSL_VERSION_UNDERSCORE}.done ]; then |
82 | | - echo "Building OpenSSL $OPENSSL_VERSION" |
83 | | - curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_$OPENSSL_VERSION_UNDERSCORE.tar.gz |
84 | | - tar zxf OpenSSL_$OPENSSL_VERSION_UNDERSCORE.tar.gz |
85 | | - |
86 | | - pushd openssl-OpenSSL_${OPENSSL_VERSION_UNDERSCORE} |
87 | | - if [[ $ARCH = 'arm64' ]]; then |
88 | | - PLATFORM=darwin64-arm64-cc |
89 | | - else |
90 | | - PLATFORM=darwin64-x86_64-cc |
91 | | - fi |
92 | | - CFLAGS="-fPIC -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}" \ |
93 | | - ./Configure --prefix=$PREFIX no-shared no-unit-test $PLATFORM |
94 | | - make -j8 >/dev/null |
95 | | - make install_sw >/dev/null |
96 | | - popd |
97 | | - |
98 | | - touch openssl-OpenSSL_${OPENSSL_VERSION_UNDERSCORE}.done |
99 | | -else |
100 | | - echo "Using cached OpenSSL $OPENSSL_VERSION" |
101 | | -fi |
102 | | - |
103 | | -if [ ! -f protobuf-${PROTOBUF_VERSION}/.done ]; then |
104 | | - echo "Building Protobuf $PROTOBUF_VERSION" |
105 | | - curl -O -L https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-cpp-${PROTOBUF_VERSION}.tar.gz |
106 | | - tar zxf protobuf-cpp-${PROTOBUF_VERSION}.tar.gz |
107 | | - pushd protobuf-${PROTOBUF_VERSION} |
108 | | - pushd cmake/ |
109 | | - # Build protoc that can run on both x86 and arm architectures |
110 | | - cmake -B build -DCMAKE_CXX_FLAGS="-fPIC -arch x86_64 -arch arm64 -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}" \ |
111 | | - -Dprotobuf_BUILD_TESTS=OFF \ |
112 | | - -DCMAKE_INSTALL_PREFIX=$PREFIX |
113 | | - cmake --build build -j16 --target install |
114 | | - popd |
115 | | - |
116 | | - # Retain the library for one architecture so that `ar` can work on the library |
117 | | - pushd $PREFIX/lib |
118 | | - mv libprotobuf.a libprotobuf_universal.a |
119 | | - lipo libprotobuf_universal.a -thin ${ARCH} -output libprotobuf.a |
120 | | - popd |
121 | | - touch .done |
122 | | - popd |
123 | | -else |
124 | | - echo "Using cached Protobuf $PROTOBUF_VERSION" |
125 | | -fi |
126 | | - |
127 | | -if [ ! -f zstd-${ZSTD_VERSION}/.done ]; then |
128 | | - echo "Building ZStd $ZSTD_VERSION" |
129 | | - curl -O -L https://github.com/facebook/zstd/releases/download/v${ZSTD_VERSION}/zstd-${ZSTD_VERSION}.tar.gz |
130 | | - tar zxf zstd-${ZSTD_VERSION}.tar.gz |
131 | | - pushd zstd-${ZSTD_VERSION} |
132 | | - CFLAGS="-fPIC -O3 -arch ${ARCH} -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}" PREFIX=$PREFIX \ |
133 | | - make -j16 -C lib install-static install-includes |
134 | | - touch .done |
135 | | - popd |
136 | | -else |
137 | | - echo "Using cached ZStd $ZSTD_VERSION" |
138 | | -fi |
139 | | - |
140 | | -if [ ! -f snappy-${SNAPPY_VERSION}/.done ]; then |
141 | | - echo "Building Snappy $SNAPPY_VERSION" |
142 | | - curl -O -L https://github.com/google/snappy/archive/refs/tags/${SNAPPY_VERSION}.tar.gz |
143 | | - tar zxf ${SNAPPY_VERSION}.tar.gz |
144 | | - pushd snappy-${SNAPPY_VERSION} |
145 | | - # Without this patch, snappy 1.10 will report a sign-compare error, which cannot be suppressed with the -Wno-sign-compare option in CI |
146 | | - curl -O -L https://raw.githubusercontent.com/microsoft/vcpkg/2024.02.14/ports/snappy/no-werror.patch |
147 | | - patch <no-werror.patch |
148 | | - CXXFLAGS="-fPIC -O3 -arch ${ARCH} -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}" \ |
149 | | - cmake . -DCMAKE_INSTALL_PREFIX=$PREFIX -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF |
150 | | - make -j16 |
151 | | - make install |
152 | | - touch .done |
153 | | - popd |
154 | | -else |
155 | | - echo "Using cached Snappy $SNAPPY_VERSION" |
156 | | -fi |
157 | | - |
158 | | -if [ ! -f curl-${CURL_VERSION}/.done ]; then |
159 | | - echo "Building LibCurl $CURL_VERSION" |
160 | | - CURL_VERSION_=${CURL_VERSION//./_} |
161 | | - curl -O -L https://github.com/curl/curl/releases/download/curl-${CURL_VERSION_}/curl-${CURL_VERSION}.tar.gz |
162 | | - tar zxf curl-${CURL_VERSION}.tar.gz |
163 | | - pushd curl-${CURL_VERSION} |
164 | | - # Force the compiler to find the OpenSSL headers instead of the headers in the system path like /usr/local/include/openssl. |
165 | | - cp -rf $PREFIX/include/openssl include/ |
166 | | - CFLAGS="-I$PREFIX/include -fPIC -arch ${ARCH} -mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}" \ |
167 | | - ./configure --with-ssl=$PREFIX \ |
168 | | - --without-nghttp2 \ |
169 | | - --without-libidn2 \ |
170 | | - --disable-ldap \ |
171 | | - --without-brotli \ |
172 | | - --without-secure-transport \ |
173 | | - --without-librtmp \ |
174 | | - --disable-ipv6 \ |
175 | | - --without-libpsl \ |
176 | | - --host=$ARCH-apple-darwin \ |
177 | | - --prefix=$PREFIX |
178 | | - make -j16 install |
179 | | - touch .done |
180 | | - popd |
181 | | -else |
182 | | - echo "Using cached LibCurl $CURL_VERSION" |
183 | | -fi |
184 | | - |
185 | | -popd # pkg/mac |
186 | | -cd ../../ # project root |
187 | | - |
188 | | -cmake -B build-static -DCMAKE_OSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET \ |
189 | | - -DLINK_STATIC=ON \ |
| 37 | +# Apply the patch to support building libcurl with IPv6 disabled |
| 38 | +COMMIT_ID=$(grep "builtin-baseline" vcpkg.json | sed 's/"//g' | sed 's/,//' | awk '{print $2}') |
| 39 | +cd vcpkg |
| 40 | +git reset --hard $COMMIT_ID |
| 41 | +git apply ../pkg/mac/vcpkg-curl-patch.diff |
| 42 | +git add ports/curl |
| 43 | +git commit -m "Disable IPv6 for macOS in curl" |
| 44 | +./bootstrap-vcpkg.sh |
| 45 | +./vcpkg x-add-version --all |
| 46 | +git add versions/ |
| 47 | +git commit -m "Update version" |
| 48 | +COMMIT_ID=$(git log --pretty=oneline | head -n 1 | awk '{print $1}') |
| 49 | +cd .. |
| 50 | +sed -i.bak "s/.*builtin-baseline.*/ \"builtin-baseline\": \"$COMMIT_ID\",/" vcpkg.json |
| 51 | +sed -i.bak "s/\"version>=\": \"8\.4\.0\"/\"version>=\": \"8.4.0#1\"/" vcpkg.json |
| 52 | + |
| 53 | +INSTALL_DIR=$PWD/pkg/mac/.install |
| 54 | +set -x |
| 55 | +cmake -B build-osx \ |
| 56 | + -DCMAKE_OSX_DEPLOYMENT_TARGET=13.0 \ |
| 57 | + -DINTEGRATE_VCPKG=ON \ |
| 58 | + -DVCPKG_OVERLAY_TRIPLETS=$PWD/vcpkg-triplets \ |
| 59 | + -DVCPKG_TARGET_TRIPLET=$VCPKG_TRIPLET \ |
| 60 | + -DCMAKE_OSX_ARCHITECTURES=$ARCH \ |
| 61 | + -DCMAKE_BUILD_TYPE=Release \ |
190 | 62 | -DBUILD_TESTS=OFF \ |
| 63 | + -DBUILD_PERF_TOOLS=OFF \ |
191 | 64 | -DBUILD_DYNAMIC_LIB=ON \ |
192 | 65 | -DBUILD_STATIC_LIB=ON \ |
193 | | - -DCMAKE_OSX_ARCHITECTURES=${ARCH} \ |
194 | | - -DCMAKE_PREFIX_PATH=$PREFIX \ |
195 | | - -DOPENSSL_ROOT_DIR=$PREFIX \ |
196 | | - -DPROTOC_PATH=$PREFIX/bin/protoc \ |
197 | | - -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \ |
198 | | - -DCMAKE_BUILD_TYPE=Release |
199 | | -cmake --build build-static -j16 --target install |
| 66 | + -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR |
| 67 | +cmake --build build-osx -j16 --target install |
| 68 | + |
| 69 | +./build-support/merge_archives_vcpkg.sh $PWD/build-osx |
| 70 | +cp ./build-osx/libpulsarwithdeps.a $INSTALL_DIR/lib/ |
| 71 | + |
| 72 | +# Test the libraries |
| 73 | +clang++ win-examples/example.cc -o dynamic.out -std=c++11 -arch $ARCH -I $INSTALL_DIR/include -L $INSTALL_DIR/lib -Wl,-rpath $INSTALL_DIR/lib -lpulsar |
| 74 | +./dynamic.out |
| 75 | +clang++ win-examples/example.cc -o static.out -std=c++11 -arch $ARCH -I $INSTALL_DIR/include $INSTALL_DIR/lib/libpulsarwithdeps.a |
| 76 | +./static.out |
0 commit comments