Skip to content

Commit d131ae3

Browse files
committed
use asio without boost
This removes the last dependency to boost (except the boost test driver).
1 parent 9b70155 commit d131ae3

File tree

9 files changed

+47
-98
lines changed

9 files changed

+47
-98
lines changed

.github/workflows/run-all.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
g++ \
2323
gcovr \
2424
git \
25-
libboost-system-dev \
25+
libasio-dev \
2626
libboost-test-dev \
2727
libtclap-dev \
2828
make \

CMakeLists.txt

+1-47
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ endif()
1414
project(Cucumber-Cpp)
1515

1616
option(BUILD_SHARED_LIBS "Generate shared libraries" OFF)
17-
option(CUKE_USE_STATIC_BOOST "Statically link Boost (except boost::test)" ${WIN32})
1817
option(CUKE_USE_STATIC_GTEST "Statically link Google Test" ON)
1918
option(CUKE_ENABLE_BOOST_TEST "Enable Boost.Test framework" ON)
2019
option(CUKE_ENABLE_EXAMPLES "Build examples" OFF)
@@ -111,56 +110,11 @@ endif()
111110
# Boost
112111
#
113112

114-
set(BOOST_MIN_VERSION "1.70")
115-
116113
set(Boost_USE_STATIC_RUNTIME OFF)
117-
set(CUKE_CORE_BOOST_LIBS system)
118114
if(CUKE_ENABLE_BOOST_TEST)
119115
# "An external test runner utility is required to link with dynamic library" (Boost User's Guide)
120-
set(Boost_USE_STATIC_LIBS OFF)
121116
set(CMAKE_CXX_FLAGS "-DBOOST_TEST_DYN_LINK ${CMAKE_CXX_FLAGS}")
122-
find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS unit_test_framework)
123-
endif()
124-
125-
if(CUKE_USE_STATIC_BOOST)
126-
set(Boost_USE_STATIC_LIBS ON)
127-
find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS ${CUKE_CORE_BOOST_LIBS} REQUIRED)
128-
else()
129-
set(CMAKE_CXX_FLAGS "-DBOOST_ALL_DYN_LINK ${CMAKE_CXX_FLAGS}")
130-
set(Boost_USE_STATIC_LIBS OFF)
131-
find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS ${CUKE_CORE_BOOST_LIBS} REQUIRED)
132-
endif()
133-
134-
# Create import targets for CMake versions older than 3.5 (actually older FindBoost.cmake)
135-
if(Boost_USE_STATIC_LIBS)
136-
set(LIBRARY_TYPE STATIC)
137-
else()
138-
# Just because we don't ask for static doesn't mean we're not getting static
139-
set(LIBRARY_TYPE UNKNOWN)
140-
endif()
141-
if(Boost_INCLUDE_DIRS AND NOT TARGET Boost::boost)
142-
add_library(Boost::boost INTERFACE IMPORTED)
143-
set_target_properties(Boost::boost PROPERTIES
144-
"INTERFACE_INCLUDE_DIRECTORIES" "${Boost_INCLUDE_DIRS}")
145-
endif()
146-
if(Boost_SYSTEM_LIBRARY AND NOT TARGET Boost::system)
147-
add_library(Boost::system ${LIBRARY_TYPE} IMPORTED)
148-
set_target_properties(Boost::system PROPERTIES
149-
"IMPORTED_LOCATION" "${Boost_SYSTEM_LIBRARY}"
150-
"INTERFACE_LINK_LIBRARIES" "Boost::boost"
151-
)
152-
if(Boost_USE_STATIC_LIBS)
153-
set_target_properties(Boost::system PROPERTIES
154-
"COMPILE_DEFINITIONS" BOOST_ERROR_CODE_HEADER_ONLY=1
155-
)
156-
endif()
157-
endif()
158-
if(Boost_UNIT_TEST_FRAMEWORK_LIBRARY AND NOT TARGET Boost::unit_test_framework)
159-
add_library(Boost::unit_test_framework ${LIBRARY_TYPE} IMPORTED)
160-
set_target_properties(Boost::unit_test_framework PROPERTIES
161-
"IMPORTED_LOCATION" "${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}"
162-
"INTERFACE_LINK_LIBRARIES" "Boost::boost"
163-
)
117+
find_package(Boost 1.70 COMPONENTS unit_test_framework)
164118
endif()
165119

166120
#

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ It relies on a few executables:
2222

2323
It relies on a few libraries:
2424

25-
* [Boost](http://www.boost.org/) 1.70.
26-
Required libraries: *system*.
27-
Optional library for Boost Test driver: *test*.
25+
* [Asio](https://think-async.com/Asio/) 1.18.1 or later.
26+
* [Boost.Test](http://www.boost.org/) 1.70. Optional for the Boost Test driver.
2827
* [GTest](http://code.google.com/p/googletest/) 1.6 or later.
2928
Optional for the GTest driver. By default downloaded and built by CMake.
3029
* [GMock](http://code.google.com/p/googlemock/) 1.6 or later.

cmake/modules/FindAsio.cmake

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
find_path(ASIO_INCLUDE_DIR asio.hpp)
2+
3+
if (ASIO_INCLUDE_DIR)
4+
set(ASIO_FOUND TRUE)
5+
else ()
6+
set(ASIO_FOUND FALSE)
7+
endif ()
8+
9+
include(FindPackageHandleStandardArgs)
10+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Asio REQUIRED_VARS ASIO_INCLUDE_DIR)

include/cucumber-cpp/internal/connectors/wire/WireServer.hpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <string>
88

9-
#include <boost/asio.hpp>
9+
#include <asio.hpp>
1010

1111
namespace cucumber {
1212
namespace internal {
@@ -29,15 +29,14 @@ class CUCUMBER_CPP_EXPORT SocketServer {
2929

3030
protected:
3131
const ProtocolHandler* protocolHandler;
32-
boost::asio::io_service ios;
32+
asio::io_service ios;
3333

3434
template<typename Protocol>
3535
void doListen(
36-
boost::asio::basic_socket_acceptor<Protocol>& acceptor,
37-
const typename Protocol::endpoint& endpoint
36+
asio::basic_socket_acceptor<Protocol>& acceptor, const typename Protocol::endpoint& endpoint
3837
);
3938
template<typename Protocol>
40-
void doAcceptOnce(boost::asio::basic_socket_acceptor<Protocol>& acceptor);
39+
void doAcceptOnce(asio::basic_socket_acceptor<Protocol>& acceptor);
4140
void processStream(std::iostream& stream);
4241
};
4342

@@ -64,7 +63,7 @@ class CUCUMBER_CPP_EXPORT TCPSocketServer : public SocketServer {
6463
/**
6564
* Bind and listen to a TCP port on the given endpoint
6665
*/
67-
void listen(const boost::asio::ip::tcp::endpoint endpoint);
66+
void listen(const asio::ip::tcp::endpoint endpoint);
6867

6968
/**
7069
* Endpoint (IP address and port number) that this server is currently
@@ -73,15 +72,15 @@ class CUCUMBER_CPP_EXPORT TCPSocketServer : public SocketServer {
7372
* @throw std::system_error when not listening on any socket or
7473
* the endpoint cannot be determined.
7574
*/
76-
boost::asio::ip::tcp::endpoint listenEndpoint() const;
75+
asio::ip::tcp::endpoint listenEndpoint() const;
7776

7877
void acceptOnce() override;
7978

8079
private:
81-
boost::asio::ip::tcp::acceptor acceptor;
80+
asio::ip::tcp::acceptor acceptor;
8281
};
8382

84-
#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
83+
#if defined(ASIO_HAS_LOCAL_SOCKETS)
8584
/**
8685
* Socket server that calls a protocol handler line by line
8786
*/
@@ -103,14 +102,14 @@ class CUCUMBER_CPP_EXPORT UnixSocketServer : public SocketServer {
103102
* @throw std::system_error when not listening on any socket or
104103
* the endpoint cannot be determined.
105104
*/
106-
boost::asio::local::stream_protocol::endpoint listenEndpoint() const;
105+
asio::local::stream_protocol::endpoint listenEndpoint() const;
107106

108107
void acceptOnce() override;
109108

110109
~UnixSocketServer() override;
111110

112111
private:
113-
boost::asio::local::stream_protocol::acceptor acceptor;
112+
asio::local::stream_protocol::acceptor acceptor;
114113
};
115114
#endif
116115

src/CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
include(GenerateExportHeader)
22

33
find_package(nlohmann_json 3.10.5 REQUIRED)
4+
find_package(Asio REQUIRED)
45
find_package(TCLAP REQUIRED)
56
include(../cmake/modules/GitVersion.cmake)
67

@@ -107,8 +108,6 @@ foreach(TARGET
107108
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>
108109
)
109110
target_link_libraries(${TARGET}
110-
PUBLIC
111-
Boost::boost
112111
PRIVATE
113112
${CUKE_EXTRA_PRIVATE_LIBRARIES}
114113
)

src/connectors/wire/WireServer.cpp

+9-15
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,14 @@
44
namespace cucumber {
55
namespace internal {
66

7-
using namespace boost::asio;
8-
using namespace boost::asio::ip;
9-
#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
10-
using namespace boost::asio::local;
11-
#endif
12-
137
SocketServer::SocketServer(const ProtocolHandler* protocolHandler) :
148
protocolHandler(protocolHandler),
159
ios() {
1610
}
1711

1812
template<typename Protocol>
1913
void SocketServer::doListen(
20-
basic_socket_acceptor<Protocol>& acceptor, const typename Protocol::endpoint& endpoint
14+
asio::basic_socket_acceptor<Protocol>& acceptor, const typename Protocol::endpoint& endpoint
2115
) {
2216
if (acceptor.is_open())
2317
throw std::system_error(asio::error::already_open);
@@ -28,7 +22,7 @@ void SocketServer::doListen(
2822
}
2923

3024
template<typename Protocol>
31-
void SocketServer::doAcceptOnce(basic_socket_acceptor<Protocol>& acceptor) {
25+
void SocketServer::doAcceptOnce(asio::basic_socket_acceptor<Protocol>& acceptor) {
3226
typename Protocol::iostream stream;
3327
acceptor.accept(*stream.rdbuf());
3428
processStream(stream);
@@ -47,23 +41,23 @@ TCPSocketServer::TCPSocketServer(const ProtocolHandler* protocolHandler) :
4741
}
4842

4943
void TCPSocketServer::listen(const port_type port) {
50-
listen(tcp::endpoint(tcp::v4(), port));
44+
listen(asio::ip::tcp::endpoint(asio::ip::tcp::v4(), port));
5145
}
5246

53-
void TCPSocketServer::listen(const tcp::endpoint endpoint) {
47+
void TCPSocketServer::listen(const asio::ip::tcp::endpoint endpoint) {
5448
doListen(acceptor, endpoint);
55-
acceptor.set_option(tcp::no_delay(true));
49+
acceptor.set_option(asio::ip::tcp::no_delay(true));
5650
}
5751

58-
tcp::endpoint TCPSocketServer::listenEndpoint() const {
52+
asio::ip::tcp::endpoint TCPSocketServer::listenEndpoint() const {
5953
return acceptor.local_endpoint();
6054
}
6155

6256
void TCPSocketServer::acceptOnce() {
6357
doAcceptOnce(acceptor);
6458
}
6559

66-
#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
60+
#if defined(ASIO_HAS_LOCAL_SOCKETS)
6761
UnixSocketServer::UnixSocketServer(const ProtocolHandler* protocolHandler) :
6862
SocketServer(protocolHandler),
6963
acceptor(ios) {
@@ -73,10 +67,10 @@ void UnixSocketServer::listen(const std::string& unixPath) {
7367
if (std::filesystem::status(unixPath).type() == std::filesystem::file_type::socket)
7468
std::filesystem::remove(unixPath);
7569

76-
doListen(acceptor, stream_protocol::endpoint(unixPath));
70+
doListen(acceptor, asio::local::stream_protocol::endpoint(unixPath));
7771
}
7872

79-
stream_protocol::endpoint UnixSocketServer::listenEndpoint() const {
73+
asio::local::stream_protocol::endpoint UnixSocketServer::listenEndpoint() const {
8074
return acceptor.local_endpoint();
8175
}
8276

src/main.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void acceptWireProtocol(
1616
JsonWireMessageCodec wireCodec;
1717
WireProtocolHandler protocolHandler(wireCodec, cukeEngine);
1818
std::unique_ptr<SocketServer> server;
19-
#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
19+
#if defined(ASIO_HAS_LOCAL_SOCKETS)
2020
if (!unixPath.empty()) {
2121
UnixSocketServer* const unixServer = new UnixSocketServer(&protocolHandler);
2222
server.reset(unixServer);
@@ -31,9 +31,7 @@ void acceptWireProtocol(
3131
{
3232
TCPSocketServer* const tcpServer = new TCPSocketServer(&protocolHandler);
3333
server.reset(tcpServer);
34-
tcpServer->listen(
35-
boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(host), port)
36-
);
34+
tcpServer->listen(asio::ip::tcp::endpoint(asio::ip::address::from_string(host), port));
3735
if (verbose)
3836
std::clog << "Listening on " << tcpServer->listenEndpoint() << std::endl;
3937
}
@@ -60,7 +58,7 @@ int CUCUMBER_CPP_EXPORT main(int argc, char** argv) {
6058
);
6159
cmd.add(portArg);
6260

63-
#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
61+
#if defined(ASIO_HAS_LOCAL_SOCKETS)
6462
TCLAP::ValueArg<std::string> unixArg(
6563
"u",
6664
"unix",
@@ -77,7 +75,7 @@ int CUCUMBER_CPP_EXPORT main(int argc, char** argv) {
7775
std::string unixPath;
7876
std::string listenHost = listenArg.getValue();
7977
int port = portArg.getValue();
80-
#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
78+
#if defined(ASIO_HAS_LOCAL_SOCKETS)
8179
unixPath = unixArg.getValue();
8280
#endif
8381

tests/integration/WireServerTest.cpp

+9-13
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
#include <sstream>
1313

1414
using namespace cucumber::internal;
15-
using namespace boost::asio::ip;
16-
#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
17-
using namespace boost::asio::local;
18-
#endif
1915
using namespace testing;
2016

2117
static const auto THREAD_TEST_TIMEOUT = std::chrono::milliseconds(4000);
@@ -94,7 +90,7 @@ class TCPSocketServerTest : public SocketServerTest {
9490

9591
TEST_F(TCPSocketServerTest, exitsOnFirstConnectionClosed) {
9692
// given
97-
tcp::iostream client(server->listenEndpoint());
93+
asio::ip::tcp::iostream client(server->listenEndpoint());
9894
ASSERT_THAT(client, IsConnected());
9995
ASSERT_THAT(server->listenEndpoint().address().to_string(), std::string("0.0.0.0"));
10096

@@ -107,11 +103,11 @@ TEST_F(TCPSocketServerTest, exitsOnFirstConnectionClosed) {
107103

108104
TEST_F(TCPSocketServerTest, moreThanOneClientCanConnect) {
109105
// given
110-
tcp::iostream client1(server->listenEndpoint());
106+
asio::ip::tcp::iostream client1(server->listenEndpoint());
111107
ASSERT_THAT(client1, IsConnected());
112108

113109
// when
114-
tcp::iostream client2(server->listenEndpoint());
110+
asio::ip::tcp::iostream client2(server->listenEndpoint());
115111

116112
// then
117113
ASSERT_THAT(client2, IsConnected());
@@ -126,7 +122,7 @@ TEST_F(TCPSocketServerTest, receiveAndSendsSingleLineMassages) {
126122
}
127123

128124
// given
129-
tcp::iostream client(server->listenEndpoint());
125+
asio::ip::tcp::iostream client(server->listenEndpoint());
130126
ASSERT_THAT(client, IsConnected());
131127

132128
// when
@@ -145,7 +141,7 @@ class TCPSocketServerLocalhostTest : public SocketServerTest {
145141

146142
SocketServer* createListeningServer() override {
147143
server.reset(new TCPSocketServer(&protocolHandler));
148-
server->listen(tcp::endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 0));
144+
server->listen(asio::ip::tcp::endpoint(asio::ip::address::from_string("127.0.0.1"), 0));
149145
return server.get();
150146
}
151147

@@ -156,7 +152,7 @@ class TCPSocketServerLocalhostTest : public SocketServerTest {
156152

157153
TEST_F(TCPSocketServerLocalhostTest, listensOnLocalhost) {
158154
// given
159-
tcp::iostream client(server->listenEndpoint());
155+
asio::ip::tcp::iostream client(server->listenEndpoint());
160156
ASSERT_THAT(client, IsConnected());
161157
ASSERT_THAT(server->listenEndpoint().address().to_string(), std::string("127.0.0.1"));
162158

@@ -167,7 +163,7 @@ TEST_F(TCPSocketServerLocalhostTest, listensOnLocalhost) {
167163
EXPECT_THAT(serverThread, EventuallyTerminates());
168164
}
169165

170-
#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
166+
#if defined(ASIO_HAS_LOCAL_SOCKETS)
171167
class UnixSocketServerTest : public SocketServerTest {
172168
protected:
173169
std::unique_ptr<UnixSocketServer> server;
@@ -204,14 +200,14 @@ class UnixSocketServerTest : public SocketServerTest {
204200
* created at startup and removed on shutdown.
205201
*/
206202
TEST_F(UnixSocketServerTest, fullLifecycle) {
207-
stream_protocol::endpoint socketName = server->listenEndpoint();
203+
asio::local::stream_protocol::endpoint socketName = server->listenEndpoint();
208204
EXPECT_CALL(protocolHandler, handle("X")).WillRepeatedly(Return("Y"));
209205

210206
// socket created at startup
211207
ASSERT_TRUE(std::filesystem::exists(socketName.path()));
212208

213209
// traffic flows
214-
stream_protocol::iostream client(socketName);
210+
asio::local::stream_protocol::iostream client(socketName);
215211
client << "X" << std::endl << std::flush;
216212
EXPECT_THAT(client, EventuallyReceives("Y"));
217213

0 commit comments

Comments
 (0)