This is an automated email from the ASF dual-hosted git repository. penghui pushed a commit to branch branch-2.7 in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit bc0587d1daeb0b6aa011aa7466505397812366c5 Author: Yunze Xu <[email protected]> AuthorDate: Tue Apr 27 02:36:35 2021 +0800 Add CI to verify C++ client could be built on Windows (#10387) * Add vcpkg dependencies * Add dependencies for compression * Add C++ client Windows build CI * Remove redundant variables * Update README * Fix compile error (cherry picked from commit d81c16abed5d2f390dafe617fade57e8de644a95) --- .github/workflows/ci-cpp-build-windows.yaml | 79 +++++++++++++++++++++++++++ pulsar-client-cpp/.gitignore | 7 +++ pulsar-client-cpp/CMakeLists.txt | 8 +++ pulsar-client-cpp/README.md | 84 ++++++++++++++++++++++------- pulsar-client-cpp/lib/ConnectionPool.cc | 1 - pulsar-client-cpp/lib/JavaStringHash.cc | 1 + pulsar-client-cpp/lib/JavaStringHash.h | 1 - pulsar-client-cpp/lib/TopicName.cc | 1 - pulsar-client-cpp/lib/auth/AuthOauth2.h | 1 - pulsar-client-cpp/vcpkg.json | 26 +++++++++ 10 files changed, 185 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci-cpp-build-windows.yaml b/.github/workflows/ci-cpp-build-windows.yaml new file mode 100644 index 0000000..87de993 --- /dev/null +++ b/.github/workflows/ci-cpp-build-windows.yaml @@ -0,0 +1,79 @@ +# +# 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 Windows +on: + pull_request: + branches: + - master + push: + branches: + - branch-* + +env: + VCPKG_FEATURE_FLAGS: manifests + +jobs: + cpp-build-windows: + timeout-minutes: 120 + + name: ${{ matrix.name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - name: 'Windows x64' + os: windows-latest + triplet: x64-windows + vcpkg_dir: 'C:\vcpkg' + suffix: 'windows-win64' + generator: 'Visual Studio 16 2019' + arch: '-A x64' + + steps: + - name: checkout + uses: actions/checkout@v2 + + - name: Install vcpkg packages + shell: bash + run: | + cd pulsar-client-cpp && vcpkg install --triplet ${{ matrix.triplet }} + + - name: Configure + shell: bash + run: | + if [ "$RUNNER_OS" == "Windows" ]; then + cd pulsar-client-cpp && \ + cmake \ + -B ./build \ + -G "${{ matrix.generator }}" ${{ matrix.arch }} \ + -DBUILD_PYTHON_WRAPPER=OFF -DBUILD_TESTS=OFF \ + -DVCPKG_TRIPLET=${{ matrix.triplet }} \ + -DCMAKE_BUILD_TYPE=Release \ + -S . + fi + + - name: Compile + shell: bash + run: | + if [ "$RUNNER_OS" == "Windows" ]; then + cd pulsar-client-cpp && \ + cmake --build ./build + fi diff --git a/pulsar-client-cpp/.gitignore b/pulsar-client-cpp/.gitignore index f031a55..afb332d 100644 --- a/pulsar-client-cpp/.gitignore +++ b/pulsar-client-cpp/.gitignore @@ -73,3 +73,10 @@ pulsar-dist install_manifest.txt merged-library python/venv + +# Visual Studio files +out/ +CMakeSettings.json + +# vcpkg dependencies directory +vcpkg_installed/ diff --git a/pulsar-client-cpp/CMakeLists.txt b/pulsar-client-cpp/CMakeLists.txt index d4fdb8e..59b1c00 100644 --- a/pulsar-client-cpp/CMakeLists.txt +++ b/pulsar-client-cpp/CMakeLists.txt @@ -21,6 +21,14 @@ cmake_minimum_required(VERSION 3.4) project (pulsar-cpp) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules") +if (VCPKG_TRIPLET) + message(STATUS "Use vcpkg, triplet is ${VCPKG_TRIPLET}") + set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/vcpkg_installed/${VCPKG_TRIPLET}") + message(STATUS "Use CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") + set(PROTOC_PATH "${CMAKE_PREFIX_PATH}/tools/protobuf/protoc") + message(STATUS "Use protoc: ${PROTOC_PATH}") +endif() + find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) set(CMAKE_CXX_COMPILER_LAUNCHER "ccache") diff --git a/pulsar-client-cpp/README.md b/pulsar-client-cpp/README.md index 67ec2bf..f489c3d 100644 --- a/pulsar-client-cpp/README.md +++ b/pulsar-client-cpp/README.md @@ -37,14 +37,31 @@ https://github.com/apache/pulsar/tree/master/pulsar-client-cpp/examples ## Requirements - * CMake + * A C++ compiler that supports C++11, like GCC >= 4.8 + * CMake >= 3.4 * [Boost](http://www.boost.org/) - * [Protocol Buffer 2.6](https://developers.google.com/protocol-buffers/) - * [Log4CXX](https://logging.apache.org/log4cxx) - * LibCurl - * [GTest](https://github.com/google/googletest) - * JsonCpp + * [Protocol Buffer](https://developers.google.com/protocol-buffers/) + * [libcurl](https://curl.se/libcurl/) + * [openssl](https://github.com/openssl/openssl) +It's recommended to use Protocol Buffer 2.6 because it's verified by CI, but 3.x also works. + +The default supported [compression types](include/pulsar/CompressionType.h) are: + +- `CompressionNone` +- `CompressionLZ4` + +If you want to enable other compression types, you need to install: + +- `CompressionZLib`: [zlib](https://zlib.net/) +- `CompressionZSTD`: [zstd](https://github.com/facebook/zstd) +- `CompressionSNAPPY`: [snappy](https://github.com/google/snappy) + +If you want to build and run the tests, you need to install [GTest](https://github.com/google/googletest). Otherwise, you need to add CMake option `-DBUILD_TESTS=OFF`. + +If you don't want to build Python client since `boost-python` may not be easy to install, you need to add CMake option `-DBUILD_PYTHON_WRAPPER=OFF`. + +If you want to use `ClientConfiguration::setLogConfFilePath`, you need to install the [Log4CXX](https://logging.apache.org/log4cxx) and add CMake option `-DUSE_LOG4CXX=ON`. ## Platforms @@ -52,6 +69,7 @@ Pulsar C++ Client Library has been tested on: * Linux * Mac OS X +* Windows x64 ## Compilation @@ -76,7 +94,7 @@ Run unit tests: ```shell apt-get install -y g++ cmake libssl-dev libcurl4-openssl-dev liblog4cxx-dev \ libprotobuf-dev libboost-all-dev libgtest-dev google-mock \ - libjsoncpp-dev libxml2-utils protobuf-compiler python-setuptools + protobuf-compiler python-setuptools ``` #### Compile and install Google Test: @@ -167,22 +185,45 @@ ${PULSAR_PATH}/pulsar-client-cpp/perf/perfConsumer ### Compile on Windows -#### Install all dependencies: +#### Install with [vcpkg](https://github.com/microsoft/vcpkg) -Clone and build all dependencies from source if a binary distro can't be found. +It's highly recommended to use `vcpkg` for C++ package management on Windows. It's easy to install and well supported by Visual Studio (2015/2017/2019) and CMake. See [here](https://github.com/microsoft/vcpkg#quick-start-windows) for quick start. -- [Boost](https://github.com/boostorg/boost) -- [LibCurl](https://github.com/curl/curl) -- [zlib](https://github.com/madler/zlib) -- [OpenSSL](https://github.com/openssl/openssl) -- [ProtoBuf](https://github.com/protocolbuffers/protobuf) -- [dlfcn-win32](https://github.com/dlfcn-win32/dlfcn-win32) -- [LLVM](https://llvm.org/builds/) (for clang-tidy and clang-format) +Take 64 bits Windows as an example, you only need to run -If you want to build and run the tests, then also install -- [GTest and GMock](https://github.com/google/googletest) +```bash +vcpkg install --feature-flags=manifests --triplet x64-windows +``` -#### Compile Pulsar client library: +> NOTE: The default triplet is `x86-windows`, see [here](https://github.com/microsoft/vcpkg/blob/master/docs/users/triplets.md) for more details. + +The all dependencies, which are specified by [vcpkg.json](vcpkg.json), will be installed in `vcpkg_installed/` subdirectory, + +With `vcpkg`, you only need to run two commands: + +```bash +cmake \ + -B ./build \ + -A x64 \ + -DBUILD_PYTHON_WRAPPER=OFF -DBUILD_TESTS=OFF \ + -DVCPKG_TRIPLET=x64-windows \ + -DCMAKE_BUILD_TYPE=Release \ + -S . +cmake --build ./build --config Release +``` + +Then all artifacts will be built into `build` subdirectory. + +> NOTE: +> +> 1. Change `Release` to `Debug` if you want to build a debug version library. +> 2. For 32 bits Windows, you need to use `-A Win32` and `-DVCPKG_TRIPLET=x32-windows`. + +#### Install dependencies manually + +You need to install [dlfcn-win32](https://github.com/dlfcn-win32/dlfcn-win32) in addition. + +If you installed the dependencies manually, you need to run ```shell #If all dependencies are in your path, all that is necessary is @@ -212,4 +253,7 @@ ${PULSAR_PATH}/pulsar-test-service-stop.sh ``` ## Requirements for Contributors -We welcome contributions from the open source community, kindly make sure your changes are backward compatible with gcc-4.4.7 and Boost 1.41. + +It's recommended to install [LLVM](https://llvm.org/builds/) for `clang-tidy` and `clang-format`. Pulsar C++ client use `clang-format` 5.0 to format files, which is a little different with latest `clang-format`. + +We welcome contributions from the open source community, kindly make sure your changes are backward compatible with GCC 4.8 and Boost 1.53. diff --git a/pulsar-client-cpp/lib/ConnectionPool.cc b/pulsar-client-cpp/lib/ConnectionPool.cc index 586acec..cc5668b 100644 --- a/pulsar-client-cpp/lib/ConnectionPool.cc +++ b/pulsar-client-cpp/lib/ConnectionPool.cc @@ -21,7 +21,6 @@ #include "LogUtils.h" #include "Url.h" -#include <boost/iostreams/stream.hpp> #include <boost/asio.hpp> #include <boost/asio/ssl.hpp> diff --git a/pulsar-client-cpp/lib/JavaStringHash.cc b/pulsar-client-cpp/lib/JavaStringHash.cc index 7579e0e..bf809bf 100644 --- a/pulsar-client-cpp/lib/JavaStringHash.cc +++ b/pulsar-client-cpp/lib/JavaStringHash.cc @@ -17,6 +17,7 @@ * under the License. */ #include "JavaStringHash.h" +#include <limits> namespace pulsar { diff --git a/pulsar-client-cpp/lib/JavaStringHash.h b/pulsar-client-cpp/lib/JavaStringHash.h index 8498d1a..6059b1a 100644 --- a/pulsar-client-cpp/lib/JavaStringHash.h +++ b/pulsar-client-cpp/lib/JavaStringHash.h @@ -24,7 +24,6 @@ #include <cstdint> #include <string> -#include <boost/functional/hash.hpp> namespace pulsar { class PULSAR_PUBLIC JavaStringHash : public Hash { diff --git a/pulsar-client-cpp/lib/TopicName.cc b/pulsar-client-cpp/lib/TopicName.cc index 46fa355..a56b979 100644 --- a/pulsar-client-cpp/lib/TopicName.cc +++ b/pulsar-client-cpp/lib/TopicName.cc @@ -21,7 +21,6 @@ #include "PartitionedProducerImpl.h" #include "TopicName.h" -#include <boost/format.hpp> #include <boost/algorithm/string.hpp> #include <boost/algorithm/string/find.hpp> #include <memory> diff --git a/pulsar-client-cpp/lib/auth/AuthOauth2.h b/pulsar-client-cpp/lib/auth/AuthOauth2.h index f9bdc21..4de6f53 100644 --- a/pulsar-client-cpp/lib/auth/AuthOauth2.h +++ b/pulsar-client-cpp/lib/auth/AuthOauth2.h @@ -21,7 +21,6 @@ #include <pulsar/Authentication.h> #include <string> -#include <boost/function.hpp> namespace pulsar { diff --git a/pulsar-client-cpp/vcpkg.json b/pulsar-client-cpp/vcpkg.json new file mode 100644 index 0000000..3c14d10 --- /dev/null +++ b/pulsar-client-cpp/vcpkg.json @@ -0,0 +1,26 @@ +{ + "name": "pulsar-cpp", + "version": "2.8.0", + "description": "Pulsar C++ SDK", + "dependencies": [ + "boost-accumulators", + "boost-algorithm", + "boost-any", + "boost-circular-buffer", + "boost-asio", + "boost-date-time", + "boost-predef", + "boost-program-options", + "boost-property-tree", + "boost-random", + "boost-serialization", + "boost-xpressive", + "curl", + "dlfcn-win32", + "openssl", + "protobuf", + "snappy", + "zlib", + "zstd" + ] +}
