Skip to content

Commit 1e8e4d2

Browse files
Use vcpkg to build macOS packages (#465)
1 parent bdf6854 commit 1e8e4d2

File tree

7 files changed

+109
-212
lines changed

7 files changed

+109
-212
lines changed

.github/workflows/ci-build-binary-artifacts.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ jobs:
208208
steps:
209209
- name: checkout
210210
uses: actions/checkout@v3
211+
with:
212+
fetch-depth: 0
213+
submodules: recursive
211214

212215
- name: Install dependencies
213216
run: |

.github/workflows/ci-pr-validation.yaml

+4-38
Original file line numberDiff line numberDiff line change
@@ -311,54 +311,20 @@ jobs:
311311
run: pkg/${{matrix.pkg.type}}/docker-build-${{matrix.pkg.type}}-${{matrix.cpu.platform}}.sh build:latest
312312

313313
cpp-build-macos:
314-
timeout-minutes: 120
315-
name: Build CPP Client on macOS
316-
needs: formatting-check
317-
runs-on: macos-14
318-
steps:
319-
- name: checkout
320-
uses: actions/checkout@v3
321-
322-
- name: Install dependencies
323-
run: brew install openssl protobuf boost zstd snappy googletest
324-
325-
- name: Configure (default)
326-
shell: bash
327-
run: cmake -B ./build-macos -S .
328-
329-
- name: Compile
330-
shell: bash
331-
run: |
332-
cmake --build ./build-macos --parallel --config Release
333-
334-
- name: Build with C++20
335-
shell: bash
336-
run: |
337-
cmake -B build-macos-cpp20 -DCMAKE_CXX_STANDARD=20
338-
cmake --build build-macos-cpp20 -j8
339-
340-
cpp-build-macos-static:
341314
timeout-minutes: 120
342315
name: Build CPP Client on macOS with static dependencies
343316
runs-on: macos-14
344-
needs: unit-tests
317+
needs: formatting-check
345318
steps:
346319
- name: checkout
347320
uses: actions/checkout@v3
321+
with:
322+
fetch-depth: 0
323+
submodules: recursive
348324

349325
- name: Build libraries
350326
run: ./pkg/mac/build-static-library.sh
351327

352-
- name: Test static libraries
353-
run: |
354-
export PULSAR_DIR=$PWD/pkg/mac/.install
355-
echo "Build with static library"
356-
clang++ win-examples/example.cc -o static.out -std=c++11 -I $PULSAR_DIR/include $PULSAR_DIR/lib/libpulsarwithdeps.a
357-
./static.out
358-
echo "Build with dynamic library"
359-
clang++ win-examples/example.cc -o dynamic.out -std=c++11 -I $PULSAR_DIR/include -L $PULSAR_DIR/lib -Wl,-rpath $PULSAR_DIR/lib -lpulsar
360-
./dynamic.out
361-
362328
# Job that will be required to complete and depends on all the other jobs
363329
check-completion:
364330
name: Check Completion

build-support/merge_archives_vcpkg.sh

+9-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ if [[ $# -lt 1 ]]; then
2727
fi
2828

2929
CMAKE_BUILD_DIRECTORY=$1
30-
./merge_archives.sh $CMAKE_BUILD_DIRECTORY/libpulsarwithdeps.a \
31-
$CMAKE_BUILD_DIRECTORY/lib/libpulsar.a \
32-
$(find "$CMAKE_BUILD_DIRECTORY/vcpkg_installed" -name "*.a" | grep -v debug)
30+
if [[ $VCPKG_TRIPLET ]]; then
31+
./merge_archives.sh $CMAKE_BUILD_DIRECTORY/libpulsarwithdeps.a \
32+
$CMAKE_BUILD_DIRECTORY/lib/libpulsar.a \
33+
$(find "$CMAKE_BUILD_DIRECTORY/vcpkg_installed/$VCPKG_TRIPLET" -name "*.a" | grep -v debug)
34+
else
35+
./merge_archives.sh $CMAKE_BUILD_DIRECTORY/libpulsarwithdeps.a \
36+
$CMAKE_BUILD_DIRECTORY/lib/libpulsar.a \
37+
$(find "$CMAKE_BUILD_DIRECTORY/vcpkg_installed" -name "*.a" | grep -v debug)
38+
fi

pkg/mac/build-static-library.sh

+48-171
Original file line numberDiff line numberDiff line change
@@ -18,182 +18,59 @@
1818
# under the License.
1919
#
2020

21-
set -ex
22-
cd `dirname $0`
21+
set -e
22+
cd `dirname $0`/../..
2323

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"
6427
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
7632
else
77-
echo "Using cached ZLib $ZLIB_VERSION"
33+
echo "Invalid ARCH: $ARCH"
34+
exit 1
7835
fi
7936

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 \
19062
-DBUILD_TESTS=OFF \
63+
-DBUILD_PERF_TOOLS=OFF \
19164
-DBUILD_DYNAMIC_LIB=ON \
19265
-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

pkg/mac/vcpkg-curl-patch.diff

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
diff --git a/ports/curl/portfile.cmake b/ports/curl/portfile.cmake
2+
index bdc544e9e..340d93865 100644
3+
--- a/ports/curl/portfile.cmake
4+
+++ b/ports/curl/portfile.cmake
5+
@@ -64,6 +64,10 @@ if(VCPKG_TARGET_IS_WINDOWS)
6+
list(APPEND OPTIONS -DENABLE_UNICODE=ON)
7+
endif()
8+
9+
+if(VCPKG_TARGET_IS_OSX)
10+
+ list(APPEND OPTIONS -DENABLE_IPV6=OFF)
11+
+endif()
12+
+
13+
vcpkg_cmake_configure(
14+
SOURCE_PATH "${SOURCE_PATH}"
15+
OPTIONS
16+
diff --git a/ports/curl/vcpkg.json b/ports/curl/vcpkg.json
17+
index e028d3897..a63858e34 100644
18+
--- a/ports/curl/vcpkg.json
19+
+++ b/ports/curl/vcpkg.json
20+
@@ -1,6 +1,7 @@
21+
{
22+
"name": "curl",
23+
"version": "8.4.0",
24+
+ "port-version": 1,
25+
"description": "A library for transferring data with URLs",
26+
"homepage": "https://curl.se/",
27+
"license": "curl AND ISC AND BSD-3-Clause",

vcpkg-triplets/arm64-osx.cmake

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set(VCPKG_TARGET_ARCHITECTURE arm64)
2+
set(VCPKG_CRT_LINKAGE dynamic)
3+
set(VCPKG_LIBRARY_LINKAGE static)
4+
5+
set(VCPKG_CMAKE_SYSTEM_NAME Darwin)
6+
set(VCPKG_OSX_ARCHITECTURES arm64)
7+
set(VCPKG_OSX_DEPLOYMENT_TARGET 13.0)
8+
9+
set(VCPKG_BUILD_TYPE release)

vcpkg-triplets/x64-osx.cmake

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set(VCPKG_TARGET_ARCHITECTURE x64)
2+
set(VCPKG_CRT_LINKAGE dynamic)
3+
set(VCPKG_LIBRARY_LINKAGE static)
4+
5+
set(VCPKG_CMAKE_SYSTEM_NAME Darwin)
6+
set(VCPKG_OSX_ARCHITECTURES x86_64)
7+
set(VCPKG_OSX_DEPLOYMENT_TARGET 13.0)
8+
9+
set(VCPKG_BUILD_TYPE release)

0 commit comments

Comments
 (0)