Skip to content

Commit

Permalink
Added building non-header-only Boost libraries to GitHub Workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
percona-ysorokin committed Mar 28, 2024
1 parent e7c1046 commit b3a114a
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 12 deletions.
54 changes: 44 additions & 10 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ jobs:
cxx: "g++-13",
sanitizer_cmake_flags: "-DWITH_ASAN=ON",
aws_sanitizer_cmake_flags: "-DENABLE_ADDRESS_SANITIZER=ON",
boost_sanitizer_cmake_flags: "-DCMAKE_CXX_FLAGS_INIT=-fsanitize=address",
label: "ASan-gcc13",
run_mtr: true,
mtr_options: "--sanitize"
Expand All @@ -94,6 +95,7 @@ jobs:
cxx: "clang++-17",
libcxx_cmake_flags: "-DWITH_STDLIB_LIBCXX=ON",
aws_libcxx_cmake_flags: "-DCMAKE_CXX_FLAGS_INIT=-stdlib=libc++",
boost_libcxx_cmake_flags: "-DCMAKE_CXX_FLAGS_INIT=-stdlib=libc++",
label: "Debug-clang17",
run_clang_tidy: true,
}
Expand All @@ -104,6 +106,7 @@ jobs:
cxx: "clang++-17",
libcxx_cmake_flags: "-DWITH_STDLIB_LIBCXX=ON",
aws_libcxx_cmake_flags: "-DCMAKE_CXX_FLAGS_INIT=-stdlib=libc++",
boost_libcxx_cmake_flags: "-DCMAKE_CXX_FLAGS_INIT=-stdlib=libc++",
label: "RelWithDebInfo-clang17",
run_clang_tidy: true,
}
Expand All @@ -114,8 +117,10 @@ jobs:
cxx: "clang++-17",
libcxx_cmake_flags: "-DWITH_STDLIB_LIBCXX=ON",
aws_libcxx_cmake_flags: "-DCMAKE_CXX_FLAGS_INIT=-stdlib=libc++",
boost_libcxx_cmake_flags: "-DCMAKE_CXX_FLAGS_INIT=-stdlib=libc++",
sanitizer_cmake_flags: "-DWITH_ASAN=ON",
aws_sanitizer_cmake_flags: "-DENABLE_ADDRESS_SANITIZER=ON",
boost_sanitizer_cmake_flags: "-DCMAKE_CXX_FLAGS_INIT=-fsanitize=address",
label: "ASan-clang17",
run_mtr: true,
mtr_options: "--sanitize"
Expand Down Expand Up @@ -175,19 +180,48 @@ jobs:
run: mkdir -p ${{runner.temp}}/deps

- name: Cache boost libraries
id: cache-boost-libraries
id: cache-boost-static-libraries
uses: actions/cache@v4
with:
path: ${{runner.temp}}/deps/${{format('boost_{0}_{1}_{2}', env.BOOST_MAJOR, env.BOOST_MINOR, env.BOOST_PATCH)}}
key: ${{format('boost-libraries-{0}-{1}-{2}', env.BOOST_MAJOR, env.BOOST_MINOR, env.BOOST_PATCH)}}
path: ${{runner.temp}}/deps/boost-install-${{matrix.config.label}}
key: ${{format('boost-static-libraries-{0}-{1}-{2}', env.BOOST_MAJOR, env.BOOST_MINOR, env.BOOST_PATCH)}}

- name: Download and unpack boost libraries
if: steps.cache-boost-libraries.outputs.cache-hit != 'true'
working-directory: ${{runner.temp}}/deps
- name: Checking out Boost source tree
if: steps.cache-boost-static-libraries.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
repository: boostorg/boost
ref: ${{format('boost-{0}.{1}.{2}', env.BOOST_MAJOR, env.BOOST_MINOR, env.BOOST_PATCH)}}
path: boost
submodules: recursive
fetch-tags: true

- name: Configure CMake for Boost
if: steps.cache-boost-static-libraries.outputs.cache-hit != 'true'
run: |
wget --quiet ${{format('https://boostorg.jfrog.io/artifactory/main/release/{0}.{1}.{2}/source/boost_{0}_{1}_{2}{3}', env.BOOST_MAJOR, env.BOOST_MINOR, env.BOOST_PATCH, env.BOOST_EXT)}}
tar xf ${{format('boost_{0}_{1}_{2}{3}', env.BOOST_MAJOR, env.BOOST_MINOR, env.BOOST_PATCH, env.BOOST_EXT)}}
rm -f ${{format('boost_{0}_{1}_{2}{3}', env.BOOST_MAJOR, env.BOOST_MINOR, env.BOOST_PATCH, env.BOOST_EXT)}}
cmake \
-B ${{github.workspace}}/boost-build-${{matrix.config.label}} \
-S ${{github.workspace}}/boost \
-DCMAKE_INSTALL_PREFIX=${{runner.temp}}/deps/boost-install-${{matrix.config.label}} \
-DCMAKE_BUILD_TYPE=${{matrix.config.build_type}} \
-DCMAKE_C_COMPILER=${{matrix.config.cc}} \
-DCMAKE_CXX_COMPILER=${{matrix.config.cxx}} \
${{matrix.config.boost_libcxx_cmake_flags}} \
${{matrix.config.boost_sanitizer_cmake_flags}} \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_TESTING=OFF
- name: CMake info for Boost
if: steps.cache-boost-static-libraries.outputs.cache-hit != 'true'
run: cmake -L ${{github.workspace}}/boost-build-${{matrix.config.label}}

- name: Build for Boost
if: steps.cache-boost-static-libraries.outputs.cache-hit != 'true'
run: cmake --build ${{github.workspace}}/boost-build-${{matrix.config.label}} --config ${{matrix.config.build_type}} --parallel

- name: Install for Boost
if: steps.cache-boost-static-libraries.outputs.cache-hit != 'true'
run: cmake --install ${{github.workspace}}/boost-build-${{matrix.config.label}} --config ${{matrix.config.build_type}}

- name: Cache AWS SDK C++ libraries
id: cache-aws-sdk-cpp-libraries
Expand Down Expand Up @@ -259,7 +293,7 @@ jobs:
${{matrix.config.libcxx_cmake_flags}} \
${{matrix.config.sanitizer_cmake_flags}} \
-DCMAKE_PREFIX_PATH=${{runner.temp}}/deps/aws-sdk-cpp-install-${{matrix.config.label}} \
-DBoost_ROOT=${{runner.temp}}/deps/${{format('boost_{0}_{1}_{2}', env.BOOST_MAJOR, env.BOOST_MINOR, env.BOOST_PATCH)}} \
-DBoost_ROOT=${{runner.temp}}/deps/boost-install-${{matrix.config.label}} \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
- name: CMake info
Expand Down
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ if(WITH_ASAN)
target_link_options(binlog_server_compiler_flags INTERFACE "-fsanitize=address")
endif()

find_package(Boost 1.84.0 EXACT REQUIRED)
find_package(Boost 1.84.0 EXACT REQUIRED COMPONENTS url)

find_package(MySQL REQUIRED)

Expand Down Expand Up @@ -260,7 +260,8 @@ target_link_libraries(binlog_server
PUBLIC
binlog_server_compiler_flags
PRIVATE
Boost::headers MySQL::client
Boost::headers Boost::url
MySQL::client
aws-cpp-sdk-s3-crt
)
# for some reason it is not possible to propagate CXX_EXTENSIONS and
Expand Down
37 changes: 37 additions & 0 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@
#include <stdexcept>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>

#include <boost/lexical_cast.hpp>

#include <boost/url/host_type.hpp>
#include <boost/url/scheme.hpp>
#include <boost/url/url_view.hpp>

#include "binsrv/basic_logger.hpp"
#include "binsrv/basic_storage_backend.hpp"
#include "binsrv/exception_handling_helpers.hpp"
Expand Down Expand Up @@ -145,11 +150,43 @@ void receive_binlog_events(binsrv::basic_logger &logger,
}
}

void dump_url(const boost::urls::url_view &url) {
std::cout << "url : " << url << '\n'
<< "has_scheme : " << url.has_scheme() << '\n'
<< "scheme : " << url.scheme() << '\n'
<< "scheme_id : " << boost::urls::to_string(url.scheme_id())
<< '\n'
<< "host : " << url.host() << '\n'
<< "host_name : " << url.host_name() << '\n'
<< "host_type : "
<< static_cast<std::underlying_type_t<boost::urls::host_type>>(
url.host_type())
<< '\n'
<< "has_userinfo : " << url.has_userinfo() << '\n'
<< "userinfo : " << url.userinfo() << '\n'
<< "user : " << url.user() << '\n'
<< "has_password : " << url.has_password() << '\n'
<< "password : " << url.password() << '\n'
<< "segments : " << url.segments() << '\n'
<< "encoded_segments: " << url.encoded_segments() << '\n'
<< "path : " << url.path() << '\n'
<< "encoded_path : " << url.encoded_path() << '\n';
}

} // anonymous namespace

int main(int argc, char *argv[]) {
using namespace std::string_literals;

using namespace std::string_view_literals;
const auto file_url_sv{"file:///home/user/binsrv%20vault"sv};
const boost::urls::url_view file_url{file_url_sv};
dump_url(file_url);

const auto s3_url_sv{"s3://key:secret@mybucket/binsrv%20vault"sv};
const boost::urls::url_view s3_url{s3_url_sv};
dump_url(s3_url);

int exit_code = EXIT_FAILURE;

const auto cmd_args = util::to_command_line_agg_view(argc, argv);
Expand Down

0 comments on commit b3a114a

Please sign in to comment.