Skip to content

Commit 7256f98

Browse files
committed
Make: liburing & asio deps
Uses `FetchContent_Declare` and much more complex `ExternalProject_Add` to build a recent version of `asio` and `liburing` locally from source. axboe/liburing#438 axboe/liburing#946 Borrowed from `unum-cloud/ucall`.
1 parent 84e7710 commit 7256f98

File tree

4 files changed

+75
-10
lines changed

4 files changed

+75
-10
lines changed

.vscode/settings.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
"Adelstein",
66
"Andreas",
77
"ashvardanian",
8+
"ASIO",
89
"asynchrony",
10+
"Axboe",
911
"bioinformatics",
1012
"Boccara",
1113
"bootcamps",
1214
"Byrne",
15+
"chriskohlhoffasio",
16+
"jensaxboeliburing",
1317
"clflush",
1418
"consteval",
1519
"coro",
@@ -25,11 +29,14 @@
2529
"Hana",
2630
"Ibireme",
2731
"JeanHeyd",
32+
"Jens",
33+
"Kohlhoff",
2834
"Kulukundis",
2935
"Lelbach",
3036
"Lemire",
3137
"Lib",
3238
"libunifex",
39+
"liburing",
3340
"Lohmann",
3441
"Maclaurin",
3542
"matmul",
@@ -63,6 +70,7 @@
6370
"unifex",
6471
"unsalvageable",
6572
"unscalable",
73+
"Uring",
6674
"Vardanian",
6775
"Weis",
6876
"Yaoyuan",
@@ -93,6 +101,7 @@
93101
"bit": "cpp",
94102
"bitset": "cpp",
95103
"cctype": "cpp",
104+
"cfenv": "cpp",
96105
"charconv": "cpp",
97106
"chrono": "cpp",
98107
"clocale": "cpp",
@@ -114,6 +123,7 @@
114123
"deque": "cpp",
115124
"exception": "cpp",
116125
"execution": "cpp",
126+
"expected": "cpp",
117127
"format": "cpp",
118128
"forward_list": "cpp",
119129
"fstream": "cpp",
@@ -146,6 +156,7 @@
146156
"shared_mutex": "cpp",
147157
"source_location": "cpp",
148158
"span": "cpp",
159+
"sstream": "cpp",
149160
"stdexcept": "cpp",
150161
"stop_token": "cpp",
151162
"streambuf": "cpp",
@@ -161,9 +172,6 @@
161172
"unordered_set": "cpp",
162173
"utility": "cpp",
163174
"variant": "cpp",
164-
"vector": "cpp",
165-
"sstream": "cpp",
166-
"cfenv": "cpp",
167-
"expected": "cpp"
175+
"vector": "cpp"
168176
}
169177
}

CMakeLists.txt

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ find_package(Threads REQUIRED)
3434
find_package(OpenMP REQUIRED)
3535

3636
set(FETCHCONTENT_QUIET OFF)
37-
include(FetchContent)
37+
include(FetchContent) # For CMake-friendly dependencies
38+
include(ExternalProject) # If the dependency is not CMake-friendly
3839

3940
# GTest (required by Google Benchmark)
4041
FetchContent_Declare(
@@ -79,7 +80,7 @@ FetchContent_Declare(
7980
GIT_TAG master
8081
)
8182

82-
# Suppress TBBs own tests:
83+
# Suppress TBB's own tests:
8384
set(TBB_TEST OFF CACHE BOOL "Do not build TBB tests" FORCE)
8485
FetchContent_MakeAvailable(IntelTBB)
8586

@@ -159,14 +160,55 @@ FetchContent_Declare(
159160
)
160161
FetchContent_MakeAvailable(NielsLohmannJSON)
161162

162-
# Yaoyuan Guo YYJSON for more flexible & performant C-style parsing
163+
# Yaoyuan Guo's YYJSON for more flexible & performant C-style parsing
163164
FetchContent_Declare(
164165
YaoyuanGuoYYJSON
165166
GIT_REPOSITORY https://github.com/ibireme/yyjson.git
166167
GIT_TAG 0.10.0
167168
)
168169
FetchContent_MakeAvailable(YaoyuanGuoYYJSON)
169170

171+
# Chris Kohlhoff's ASIO standalone, avoiding Boost... integration is a bit tricky:
172+
# https://github.com/cpm-cmake/CPM.cmake/blob/master/examples/asio-standalone/CMakeLists.txt
173+
FetchContent_Declare(
174+
ChrisKohlhoffASIO
175+
GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git
176+
GIT_TAG master
177+
)
178+
FetchContent_MakeAvailable(ChrisKohlhoffASIO)
179+
add_library(asio INTERFACE)
180+
target_include_directories(asio SYSTEM INTERFACE ${chriskohlhoffasio_SOURCE_DIR}/asio/include)
181+
target_compile_definitions(asio INTERFACE ASIO_STANDALONE ASIO_NO_DEPRECATED)
182+
183+
# Jens Axboe's liburing to simplify I/O operations on Linux
184+
# https://github.com/axboe/liburing/pull/438
185+
# https://github.com/axboe/liburing/issues/946
186+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
187+
set(LIBURING_DIR ${CMAKE_BINARY_DIR}/_deps/jensaxboeliburing)
188+
ExternalProject_Add(
189+
JensAxboeLibUring
190+
GIT_REPOSITORY https://github.com/axboe/liburing.git
191+
GIT_TAG liburing-2.8
192+
GIT_SHALLOW 1
193+
PREFIX ${CMAKE_BINARY_DIR}/_deps/
194+
SOURCE_DIR ${LIBURING_DIR}
195+
CONFIGURE_COMMAND echo Configuring LibUring && cd ${LIBURING_DIR} && ./configure --nolibc --cc=${CMAKE_C_COMPILER} --cxx=${CMAKE_CXX_COMPILER};
196+
BUILD_COMMAND cd ${LIBURING_DIR} && make;
197+
INSTALL_COMMAND ""
198+
UPDATE_COMMAND ""
199+
)
200+
add_library(liburing_internal STATIC IMPORTED GLOBAL)
201+
add_dependencies(liburing_internal JensAxboeLibUring)
202+
set_property(TARGET liburing_internal
203+
PROPERTY IMPORTED_LOCATION
204+
${LIBURING_DIR}/src/liburing.a
205+
)
206+
set_property(TARGET liburing_internal
207+
PROPERTY INTERFACE_INCLUDE_DIRECTORIES
208+
${LIBURING_DIR}/src/include
209+
)
210+
endif()
211+
170212
# ------------------------------------------------------------------------------
171213
# Main Executable
172214
# ------------------------------------------------------------------------------
@@ -219,13 +261,18 @@ target_link_libraries(less_slow
219261
range-v3
220262
cppcoro
221263
unifex
264+
asio
222265
stringzilla
223266
yyjson
224267
ctre
225268
# There is no `absl` shortcut:
226269
# https://github.com/abseil/abseil-cpp/blob/master/CMake/README.md#available-abseil-cmake-public-targets
227270
absl::flat_hash_map
228271
nlohmann_json::nlohmann_json
229-
$<$<STREQUAL:${CMAKE_SYSTEM_NAME},Linux>:TBB::tbb>
230-
$<$<STREQUAL:${CMAKE_SYSTEM_NAME},Linux>:OpenMP::OpenMP_CXX>
231-
)
272+
)
273+
274+
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
275+
target_link_libraries(less_slow PRIVATE TBB::tbb)
276+
target_link_libraries(less_slow PRIVATE OpenMP::OpenMP_CXX)
277+
target_link_libraries(less_slow PRIVATE liburing_internal)
278+
endif()

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ The build will pull and compile several third-party dependencies from the source
5959
- Yaoyuan Guo's [yyjson](https://github.com/ibireme/yyjson) for faster JSON processing.
6060
- Google's [Abseil](https://github.com/abseil/abseil-cpp) replaces STL's associative containers.
6161
- Lewis Baker's [cppcoro](https://github.com/lewissbaker/cppcoro) implements C++20 coroutines.
62+
- Jens Axboe's [liburing](https://github.com/axboe/liburing) to simplify Linux kernel-bypass.
63+
- Chris Kohlhoff's [ASIO](https://github.com/chriskohlhoff/asio) as a [networking TS](https://en.cppreference.com/w/cpp/experimental/networking) extension.
6264

6365
To control the output or run specific benchmarks, use the following flags:
6466

less_slow.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3908,8 +3908,16 @@ BENCHMARK(logging<log_fmt_t>)->Name("log_fmt")->MinTime(2);
39083908
*/
39093909
#pragma region ASIO
39103910

3911+
#include <asio.hpp>
3912+
39113913
#pragma endregion // ASIO
39123914

3915+
#pragma region IO Uring
3916+
3917+
#include <liburing.h> // `liburing`
3918+
3919+
#pragma endregion // IO Uring
3920+
39133921
#pragma endregion // - Networking and Databases
39143922

39153923
/**

0 commit comments

Comments
 (0)