Skip to content

Commit 8aab896

Browse files
Use Rocky Linux 8 and vcpkg to build RPM packages (#428)
### Motivation See https://lists.apache.org/thread/7o8hpv1gtoffvzx053wm0ss2s9xt0795, we will discard the support for CentOS 7 and old `std::string` ABI. ### Modifications - Switch from `centos:7` image and GCC 4.8 to `rockylinux:8` image and GCC 8 to build RPM packages. - Use vcpkg to install dependencies according to `vcpkg.json` (`dependencies.json` will be deprecated in future) - Add a new script to build `libpulsarwithdeps.a` for dependencies installed by vcpkg - Link to `libstdc++` and `libgcc_s` libraries statically Additional, with vcpkg, OpenSSL will search `/etc/ssl/certs.pem` for the default CA certificate rather than `/usr/local/ssl/ssl/certs.pem`.
1 parent 739f0f0 commit 8aab896

File tree

5 files changed

+61
-81
lines changed

5 files changed

+61
-81
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
21+
set -e
22+
cd `dirname $0`
23+
24+
if [[ $# -lt 1 ]]; then
25+
echo "Usage: $0 <cmake-build-directory>"
26+
exit 1
27+
fi
28+
29+
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)

lib/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ target_include_directories(PULSAR_OBJECT_LIB PUBLIC
7676
"${CMAKE_SOURCE_DIR}/include"
7777
"${CMAKE_BINARY_DIR}/include")
7878

79+
include(CheckCXXSymbolExists)
7980
if (BUILD_DYNAMIC_LIB)
8081
add_library(pulsarShared SHARED $<TARGET_OBJECTS:PULSAR_OBJECT_LIB>)
8182
set_property(TARGET pulsarShared PROPERTY OUTPUT_NAME ${LIB_NAME_SHARED})
@@ -89,9 +90,12 @@ if (BUILD_DYNAMIC_LIB)
8990
target_include_directories(pulsarShared PRIVATE ${dlfcn-win32_INCLUDE_DIRS})
9091
target_link_options(pulsarShared PRIVATE $<$<CONFIG:DEBUG>:/NODEFAULTLIB:MSVCRT>)
9192
endif()
93+
check_cxx_symbol_exists(__GLIBCXX__ iostream GLIBCXX)
94+
if (GLIBCXX)
95+
target_link_libraries(pulsarShared PUBLIC -static-libgcc -static-libstdc++)
96+
endif ()
9297
endif()
9398

94-
include(CheckCXXSymbolExists)
9599
check_cxx_symbol_exists(getauxval sys/auxv.h HAVE_AUXV_GETAUXVAL)
96100
if(HAVE_AUXV_GETAUXVAL)
97101
add_definitions(-DPULSAR_AUXV_GETAUXVAL_PRESENT)

pkg/rpm/Dockerfile

Lines changed: 10 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
# Build pulsar client library in Centos with tools to build static RPM
2121

22-
FROM centos:7
22+
FROM rockylinux:8
2323

2424
ARG PLATFORM
2525

@@ -30,87 +30,19 @@ RUN yum update -y && \
3030
rpm-build \
3131
which \
3232
createrepo \
33-
libstdc++-static \
34-
python3
33+
git \
34+
python3 \
35+
python3-pip
36+
RUN dnf --enablerepo=powertools install -y libstdc++-static
3537

3638
RUN pip3 install pyyaml
3739

3840
ADD .build/dependencies.yaml /
3941
ADD .build/dep-version.py /usr/local/bin
4042

41-
# Download and compile boost
42-
# GCC 4.8.2 implementation of std::regex is buggy, so we install boost::regex here
43-
RUN BOOST_VERSION=$(dep-version.py boost) && \
44-
echo "BOOST VERSION: '${BOOST_VERSION}'" && \
45-
curl -O -L https://github.com/boostorg/boost/releases/download/boost-${BOOST_VERSION}/boost-${BOOST_VERSION}.tar.gz && \
46-
tar zxf boost-${BOOST_VERSION}.tar.gz && \
47-
cd boost-${BOOST_VERSION} && \
48-
./bootstrap.sh --with-libraries=regex && \
49-
./b2 address-model=64 cxxflags="-fPIC -std=c++11" link=static threading=multi variant=release install && \
50-
rm -rf /boost-${BOOST_VERSION}.tar.gz /boost-${BOOST_VERSION}
51-
52-
RUN CMAKE_VERSION=$(dep-version.py cmake) && \
53-
curl -O -L https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-${PLATFORM}.tar.gz && \
54-
tar xfz cmake-${CMAKE_VERSION}-linux-${PLATFORM}.tar.gz && \
55-
cp cmake-${CMAKE_VERSION}-linux-${PLATFORM}/bin/* /usr/bin/ && \
56-
cp -r cmake-${CMAKE_VERSION}-linux-${PLATFORM}/share/cmake-* /usr/share/ && \
57-
rm -rf cmake-${CMAKE_VERSION}-linux-${PLATFORM} cmake-${CMAKE_VERSION}-linux-${PLATFORM}.tar.gz
58-
59-
# Download and compile protobuf
60-
RUN PROTOBUF_VERSION=$(dep-version.py protobuf) && \
61-
curl -O -L https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-cpp-${PROTOBUF_VERSION}.tar.gz && \
62-
tar xfz protobuf-cpp-${PROTOBUF_VERSION}.tar.gz && \
63-
cd protobuf-${PROTOBUF_VERSION}/ && \
64-
CXXFLAGS=-fPIC ./configure && \
65-
make -j8 && make install && ldconfig && \
66-
rm -rf /protobuf-cpp-${PROTOBUF_VERSION}.tar.gz /protobuf-${PROTOBUF_VERSION}
67-
68-
# ZLib
69-
RUN ZLIB_VERSION=$(dep-version.py zlib) && \
70-
curl -O -L https://github.com/madler/zlib/archive/v${ZLIB_VERSION}.tar.gz && \
71-
tar xfz v${ZLIB_VERSION}.tar.gz && \
72-
cd zlib-${ZLIB_VERSION} && \
73-
CFLAGS="-fPIC -O3" ./configure && \
74-
make -j8 && make install && \
75-
rm -rf /v${ZLIB_VERSION}.tar.gz /zlib-${ZLIB_VERSION}
76-
77-
# Zstandard
78-
RUN ZSTD_VERSION=$(dep-version.py zstd) && \
79-
curl -O -L https://github.com/facebook/zstd/releases/download/v${ZSTD_VERSION}/zstd-${ZSTD_VERSION}.tar.gz && \
80-
tar xfz zstd-${ZSTD_VERSION}.tar.gz && \
81-
cd zstd-${ZSTD_VERSION} && \
82-
CFLAGS="-fPIC -O3" make -j8 && \
83-
make install && \
84-
rm -rf /zstd-${ZSTD_VERSION} /zstd-${ZSTD_VERSION}.tar.gz
85-
86-
# Snappy
87-
RUN SNAPPY_VERSION=$(dep-version.py snappy) && \
88-
curl -O -L https://github.com/google/snappy/archive/refs/tags/${SNAPPY_VERSION}.tar.gz && \
89-
tar xfz ${SNAPPY_VERSION}.tar.gz && \
90-
cd snappy-${SNAPPY_VERSION} && \
91-
CXXFLAGS="-fPIC -O3" cmake . -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF && \
92-
make -j8 && make install && \
93-
rm -rf /snappy-${SNAPPY_VERSION} /${SNAPPY_VERSION}.tar.gz
94-
95-
RUN OPENSSL_VERSION=$(dep-version.py openssl) && \
96-
OPENSSL_VERSION_UNDERSCORE=$(echo $OPENSSL_VERSION | sed 's/\./_/g') && \
97-
curl -O -L https://github.com/openssl/openssl/archive/OpenSSL_${OPENSSL_VERSION_UNDERSCORE}.tar.gz && \
98-
tar xfz OpenSSL_${OPENSSL_VERSION_UNDERSCORE}.tar.gz && \
99-
cd openssl-OpenSSL_${OPENSSL_VERSION_UNDERSCORE}/ && \
100-
./Configure -fPIC --prefix=/usr/local/ssl/ linux-${PLATFORM} && \
101-
make -j8 && make install && \
102-
rm -rf /OpenSSL_${OPENSSL_VERSION_UNDERSCORE}.tar.gz /openssl-OpenSSL_${OPENSSL_VERSION_UNDERSCORE}
103-
104-
ENV LD_LIBRARY_PATH /usr/local/ssl/lib/:
105-
ENV OPENSSL_ROOT_DIR /usr/local/ssl/
106-
107-
# LibCurl
108-
RUN CURL_VERSION=$(dep-version.py curl) && \
109-
CURL_VERSION_UNDERSCORE=$(echo $CURL_VERSION | sed 's/\./_/g') && \
110-
curl -O -L https://github.com/curl/curl/releases/download/curl-${CURL_VERSION_UNDERSCORE}/curl-${CURL_VERSION}.tar.gz && \
111-
tar xfz curl-${CURL_VERSION}.tar.gz && \
112-
cd curl-${CURL_VERSION} && \
113-
CFLAGS=-fPIC ./configure --with-ssl=/usr/local/ssl/ --without-zstd --without-libpsl && \
114-
make -j8 && make install && \
115-
rm -rf /curl-${CURL_VERSION}.tar.gz /curl-${CURL_VERSION}
43+
# Vcpkg does not provide pre-built binaries for Arm architectures so we need to build vcpkg from source
44+
RUN yum install -y cmake
45+
RUN dnf --enablerepo=devel install -y ninja-build
11646

47+
# Dependencies when building OpenSSL
48+
RUN yum install -y perl-IPC-Cmd

pkg/rpm/SPECS/pulsar-client.spec

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
%define name apache-pulsar-client
2121
%define release 1
2222
%define buildroot %{_topdir}/%{name}-%{version}-root
23+
%define debug_package %{nil}
2324

2425
BuildRoot: %{buildroot}
2526
Summary: Apache Pulsar client library
@@ -52,8 +53,15 @@ static library.
5253
%setup -q -n apache-pulsar-client-cpp-%{pom_version}
5354

5455
%build
55-
cmake . -DBUILD_TESTS=OFF -DLINK_STATIC=ON
56-
make -j 3
56+
git clone https://github.com/microsoft/vcpkg.git
57+
cmake -B build -DINTEGRATE_VCPKG=ON -DCMAKE_BUILD_TYPE=Release \
58+
-DBUILD_TESTS=OFF -DBUILD_DYNAMIC_LIB=ON -DBUILD_STATIC_LIB=ON
59+
cmake --build build -j8
60+
./build-support/merge_archives_vcpkg.sh $PWD/build
61+
62+
cp build/lib/libpulsar.a lib/libpulsar.a
63+
cp build/lib/libpulsar.so lib/libpulsar.so
64+
cp build/libpulsarwithdeps.a lib/libpulsarwithdeps.a
5765

5866
%install
5967
INCLUDE_DIR=$RPM_BUILD_ROOT/usr/include

pkg/rpm/build-rpm.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ cd /pulsar-client-cpp
2424
ROOT_DIR=$(pwd)
2525
cd $ROOT_DIR/pkg/rpm
2626

27+
if [[ $PLATFORM == "aarch64" ]]; then
28+
export VCPKG_FORCE_SYSTEM_BINARIES=arm
29+
fi
30+
2731
POM_VERSION=`cat $ROOT_DIR/version.txt | xargs`
2832

2933
# Sanitize VERSION by removing `-incubating` since it's not legal in RPM

0 commit comments

Comments
 (0)