Skip to content

Commit

Permalink
Fix C++ client cannot be built with Boost <=1.53 (apache#10307)
Browse files Browse the repository at this point in the history
* Fix build failure for Boost 1.53

* Add build CI

* Fix Boost version not detected
  • Loading branch information
BewareMyPower authored Apr 21, 2021
1 parent f56ae72 commit 2650a36
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 4 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/ci-cpp-build-centos7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# 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.
#

name: CI - CPP build on CentOS 7
on:
pull_request:
branches:
- master
push:
branches:
- branch-*

jobs:

cpp-build-centos7:
name:
runs-on: ubuntu-latest
timeout-minutes: 120

steps:
- name: checkout
uses: actions/checkout@v2

- name: Tune Runner VM
uses: ./.github/actions/tune-runner-vm

- name: Changed files check
id: changes
uses: apache/pulsar-test-infra/paths-filter@master
with:
filters: |
# pattern syntax: https://github.com/micromatch/picomatch
all:
- 'pulsar-client-cpp/**'
docs:
- 'site2/**'
- 'deployment/**'
- '.asf.yaml'
- '*.md'
- '**/*.md'
- name: build cpp client on centos 7
if: ${{ steps.changes.outputs.all_count }} > ${{ steps.changes.outputs.docs_count }}
run: |
echo "Build C++ client library on CentOS 7"
pulsar-client-cpp/docker-build-centos7.sh
40 changes: 40 additions & 0 deletions pulsar-client-cpp/docker-build-centos7.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/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.
#

# Build Pulsar C++ client in CentOS 7 container

set -e

ROOT_DIR=$(git rev-parse --show-toplevel)
cd $ROOT_DIR/pulsar-client-cpp

IMAGE="${BUILD_IMAGE_NAME:-apachepulsar/pulsar-cpp-build-centos7}"
cd ./docker/centos-7
docker build -t "${IMAGE}" .
cd -

VOLUME_OPTION=${VOLUME_OPTION:-"-v $ROOT_DIR:/pulsar"}
COMMAND="cd /pulsar/pulsar-client-cpp && mkdir -p _builds && cd _builds &&
/opt/cmake/cmake-3.4.0-Linux-x86_64/bin/cmake .. -DBUILD_PYTHON_WRAPPER=OFF -DBUILD_TESTS=OFF && make"

DOCKER_CMD="docker run -i ${VOLUME_OPTION} ${IMAGE}"

rm -rf _builds
$DOCKER_CMD bash -c "${COMMAND}"
31 changes: 31 additions & 0 deletions pulsar-client-cpp/docker/centos-7/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# 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.
#


FROM centos:7.6.1810

RUN yum install -y gcc gcc-c++ make \
protobuf-devel.x86_64 protobuf-lite-devel.x86_64 \
libcurl-devel openssl-devel \
boost boost-devel

RUN mkdir -p /opt/cmake
WORKDIR /opt/cmake
RUN curl -L -O https://cmake.org/files/v3.4/cmake-3.4.0-Linux-x86_64.tar.gz \
&& tar zxf cmake-3.4.0-Linux-x86_64.tar.gz
2 changes: 1 addition & 1 deletion pulsar-client-cpp/lib/ClientConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ ClientConnection::ClientConnection(const std::string& logicalAddress, const std:
#if BOOST_VERSION >= 105400
boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12_client);
#else
boost::asio::ssl::context ctx(executor_->io_service_, boost::asio::ssl::context::tlsv1_client);
boost::asio::ssl::context ctx(*executor_->io_service_, boost::asio::ssl::context::tlsv1_client);
#endif
Url serviceUrl;
Url::parse(physicalAddress, serviceUrl);
Expand Down
11 changes: 9 additions & 2 deletions pulsar-client-cpp/lib/Murmur3_32Hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
// the orignal MurmurHash3 source code.
#include "Murmur3_32Hash.h"

#include <boost/version.hpp>
#if BOOST_VERSION >= 105500
#include <boost/predef.h>
#else
#include <boost/detail/endian.hpp>
#endif
#include <limits>

#if BOOST_COMP_MSVC
Expand All @@ -33,16 +38,18 @@
#define ROTATE_LEFT(x, y) rotate_left(x, y)
#endif

#if BOOST_ENDIAN_LITTLE_BYTE
#if defined(BOOST_ENDIAN_LITTLE_BYTE) || defined(BOOST_LITTLE_ENDIAN)
#define BYTESPWAP(x) (x)
#elif BOOST_ENDIAN_BIG_BYTE
#elif defined(BOOST_ENDIAN_BIG_BYTE) || defined(BOOST_BIG_ENDIAN)
#if BOOST_COMP_CLANG || BOOST_COMP_GNUC
#define BYTESPWAP(x) __builtin_bswap32(x)
#elif BOOST_COMP_MSVC
#define BYTESPWAP(x) _byteswap_uint32(x)
#else
#error "No BOOST_COMP_XXX macro found"
#endif
#else
#error "No byte order found"
#endif

#define MACRO_CHUNK_SIZE 4
Expand Down
9 changes: 8 additions & 1 deletion pulsar-client-cpp/lib/checksum/crc32c_sse42.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@
******************************************************************************/
#include "crc32c_sse42.h"

#include <boost/version.hpp>
#if BOOST_VERSION >= 105500
#include <boost/predef.h>
#else
#warning "Boost version is < 1.55, disable CRC32C"
#endif

#include <assert.h>
#include <stdlib.h>

#if BOOST_ARCH_X86_64
#include <nmmintrin.h> // SSE4.2
#include <wmmintrin.h> // PCLMUL
#else
#warning "BOOST_ARCH_X86_64 is not defined, CRC32C will be disabled"
#endif

#ifdef _MSC_VER
Expand Down Expand Up @@ -247,4 +254,4 @@ uint32_t crc32c(uint32_t init, const void *buf, size_t len, const chunk_config *
abort();
}

#endif
#endif

0 comments on commit 2650a36

Please sign in to comment.