Skip to content

Commit

Permalink
Use github CI and fix build on modern Boost (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
apolukhin authored Jan 9, 2025
1 parent f3af8b6 commit 34c3058
Show file tree
Hide file tree
Showing 23 changed files with 458 additions and 219 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: CI

'on':
schedule:
- cron: '30 6 * * 1' # Every Monday at 6:30
pull_request:
push:
branches:
- second_edition

env:
UBSAN_OPTIONS: print_stacktrace=1
ASAN_OPTIONS: detect_odr_violation=2

jobs:
posix:
strategy:
fail-fast: false
matrix:
include:
- CXX_FLAGS: --coverage -fsanitize=address,leak,undefined
LINK_FLAGS: --coverage
QLIBS: -lasan -lubsan
TOOLSET: gcc-12
CXXTOOLSET: g++-12
GCOV: --gcov-tool gcov-6
os: ubuntu-24.04
info: gcc-12


name: '${{matrix.os}}: ${{matrix.info}}'
runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v4

- name: Install deps
run: |
sudo apt update
sudo apt install --allow-downgrades -y git python3-yaml gcc-12 g++-12 qt5-qmake language-pack-ru gdb libc++-dev libpng-dev
- name: Install Boost
run: |
PROJECT_DIR=`pwd`
git init $HOME/boost-local
cd $HOME/boost-local
git remote add --no-tags -t master origin https://github.com/boostorg/boost.git
git fetch --depth=10
git checkout master
git submodule update --init --merge >/dev/null
git status
./bootstrap.sh
./b2 headers
./b2 -j4 toolset=${{ matrix.TOOLSET }} address-model=64 architecture=x86 link=shared --with-program_options --with-filesystem --with-system --with-test --with-atomic --with-thread --with-timer --with-chrono --with-regex --with-random --with-context stage
cd $PROJECT_DIR
- name: Run qmake
run: |
QT_SELECT=qt5 qmake "QMAKE_CXX=${{ matrix.CXXTOOLSET }}" "QMAKE_LINK=${{ matrix.CXXTOOLSET }}" "QMAKE_CXXFLAGS+=${{ matrix.CXX_FLAGS }}" "QMAKE_LFLAGS+=${{ matrix.LINK_FLAGS }}" "LIBS+=${{ matrix.QLIBS }}" "BOOST_PATH=$HOME/boost-local" "CONFIG+=debug" BoostBook.pro
- name: Build
run: |
make -j4
- name: Test
run: |
python ./test.py -v
109 changes: 0 additions & 109 deletions .travis.yml

This file was deleted.

3 changes: 3 additions & 0 deletions Chapter03/01_lexical_to_number/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void sample3() {


#include <boost/lexical_cast.hpp>
#include <cassert>

void sample4() {
char chars[] = {'x', '1', '0', '0', 'y' };
Expand All @@ -43,6 +44,7 @@ void sample4() {


#include <boost/lexical_cast.hpp>
#include <cassert>
#include <iostream>

void sample5() {
Expand All @@ -59,6 +61,7 @@ void sample5() {


#include <boost/lexical_cast.hpp>
#include <cassert>
#include <iostream>

void sample6() {
Expand Down
1 change: 1 addition & 0 deletions Chapter05/05_shared_lock/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class users_online {
#include <boost/lexical_cast.hpp>
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <cassert>

const std::size_t users_count = 1000;

Expand Down
40 changes: 39 additions & 1 deletion Chapter06/01_tasks_processor_base/tasks_processor_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ task_wrapped<T> make_task_wrapped(const T& task_unwrapped) {
} // namespace detail

#include <boost/noncopyable.hpp>
#include <boost/asio/io_service.hpp>

#if __has_include(<boost/asio/io_service.hpp>)
# include <boost/asio/io_service.hpp>

namespace tp_base {

class tasks_processor: private boost::noncopyable {
Expand Down Expand Up @@ -76,4 +79,39 @@ class tasks_processor: private boost::noncopyable {

} // namespace tp_base

#else
# include <boost/asio/io_context.hpp>
# include <boost/asio/executor_work_guard.hpp>
# include <boost/asio/post.hpp>

namespace tp_base {

class tasks_processor: private boost::noncopyable {
protected:
static boost::asio::io_context& get_ios() {
static boost::asio::io_context ios;
static auto work = boost::asio::make_work_guard(ios);

return ios;
}

public:
template <class T>
static void push_task(const T& task_unwrapped) {
boost::asio::post(get_ios(), detail::make_task_wrapped(task_unwrapped));
}

static void start() {
get_ios().run();
}

static void stop() {
get_ios().stop();
}
}; // tasks_processor

} // namespace tp_base

#endif // #if __has_include(<boost/asio/io_service.hpp>)

#endif // BOOK_CHAPTER6_TASK_PROCESSOR_BASE_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "../01_tasks_processor_base/tasks_processor_base.hpp"

#include <boost/asio/io_service.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/system/error_code.hpp>
#include <memory> // std::unique_ptr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ struct connection_with_data: boost::noncopyable {
boost::asio::ip::tcp::socket socket;
std::string data;

explicit connection_with_data(boost::asio::io_service& ios)
: socket(ios)
{}

template <class Executor> // sine Boost 1.70 IO types can construct from executors
explicit connection_with_data(Executor executor)
: socket(executor)
template <class ExecutorOrIos> // sine Boost 1.70 IO types can construct from executors
explicit connection_with_data(ExecutorOrIos&& executor)
: socket(std::forward<ExecutorOrIos>(executor))
{}

void shutdown() {
Expand Down Expand Up @@ -143,7 +139,7 @@ class tasks_processor: public tp_timers::tasks_processor {
connection_ptr c( new connection_with_data(get_ios()) );

c->socket.connect(boost::asio::ip::tcp::endpoint(
boost::asio::ip::address_v4::from_string(addr),
boost::asio::ip::make_address_v4(addr),
port_num
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class tasks_processor: public tp_network_client::tasks_processor {
const on_accpet_func_t func_;
connection_ptr new_c_;

template <class Functor>
template <class Ios, class Functor>
tcp_listener(
boost::asio::io_service& io_service,
Ios& io_service,
unsigned short port,
const Functor& task_unwrapped)
: acceptor_(io_service, boost::asio::ip::tcp::endpoint(
Expand Down Expand Up @@ -88,7 +88,7 @@ class tasks_processor: public tp_network_client::tasks_processor {
connection_ptr c( new connection_with_data(get_ios()) );

c->socket.connect(boost::asio::ip::tcp::endpoint(
boost::asio::ip::address_v4::from_string(addr),
boost::asio::ip::make_address_v4(addr),
port_num
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ class tasks_processor: public tp_network::tasks_processor {
// First thread is the current thread.
-- threads_count;

boost::asio::io_service& ios = get_ios();
boost::thread_group tg;
for (std::size_t i = 0; i < threads_count; ++i) {
tg.create_thread([&ios]() { ios.run(); });
tg.create_thread([]() { get_ios().run(); });
}

ios.run();
get_ios().run();
tg.join_all();
}
};
Expand Down
39 changes: 38 additions & 1 deletion Chapter06/flat/01_tasks_processor_base/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ task_wrapped<T> make_task_wrapped(const T& task_unwrapped) {
} // namespace detail

#include <boost/noncopyable.hpp>
#include <boost/asio/io_service.hpp>
#if __has_include(<boost/asio/io_service.hpp>)
# include <boost/asio/io_service.hpp>

namespace tp_base {

class tasks_processor: private boost::noncopyable {
Expand Down Expand Up @@ -75,6 +77,41 @@ class tasks_processor: private boost::noncopyable {

} // namespace tp_base

#else
# include <boost/asio/io_context.hpp>
# include <boost/asio/executor_work_guard.hpp>
# include <boost/asio/post.hpp>

namespace tp_base {

class tasks_processor: private boost::noncopyable {
protected:
static boost::asio::io_context& get_ios() {
static boost::asio::io_context ios;
static auto work = boost::asio::make_work_guard(ios);

return ios;
}

public:
template <class T>
static void push_task(const T& task_unwrapped) {
boost::asio::post(get_ios(), detail::make_task_wrapped(task_unwrapped));
}

static void start() {
get_ios().run();
}

static void stop() {
get_ios().stop();
}
}; // tasks_processor

} // namespace tp_base

#endif // #if __has_include(<boost/asio/io_service.hpp>)

using namespace tp_base;

int func_test() {
Expand Down
Loading

0 comments on commit 34c3058

Please sign in to comment.