-
Notifications
You must be signed in to change notification settings - Fork 44
/
CMakeLists.txt
212 lines (184 loc) · 7.56 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project(
ucall
VERSION 0.5.6
LANGUAGES C CXX
DESCRIPTION "Up to 100x Faster FastAPI. JSON-RPC with io_uring, SIMD-acceleration, and pure CPython bindings"
HOMEPAGE_URL "https://github.com/unum-cloud/ucall")
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
option(UCALL_BUILD_BENCHMARKS "Builds all available backend for the summation server to run benchmarks" OFF)
option(UCALL_BUILD_EXAMPLES "Builds examples for Redis-like server and PyTorch deployment")
message("CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
# Make Release by default
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CACHEFILE_DIR "${CMAKE_SOURCE_DIR}/build")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/build/lib" CACHE PATH "Path to static libs")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/build/lib" CACHE PATH "Path to shared libs")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/build/bin")
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /DEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /O2 /DEBUG")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmax-errors=1")
endif()
# Check if we are running on Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(LINUX TRUE)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_OSX_DEPLOYMENT_TARGET "11")
set(CMAKE_OSX_SYSROOT CACHE STRING "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk")
set(CMAKE_OSX_DEPLOYMENT_TARGET "11" CACHE STRING "Minimum OS X deployment version")
set(CMAKE_OSX_ARCHITECTURES "x86_64" "universal2" "arm64" CACHE STRING "Minimum OS X deployment version")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -std=c++17")
endif()
# Pull the version of Linux kernel, to check if io_uring is available
if(LINUX)
execute_process(COMMAND uname -r OUTPUT_VARIABLE UNAME_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE)
message(-- " Linux Kernel version: " ${UNAME_RESULT})
string(REGEX MATCH "[0-9]+.[0-9]+" LINUX_KERNEL_VERSION ${UNAME_RESULT})
endif()
include(FetchContent)
include(ExternalProject)
FetchContent_Declare(
simdjson
GIT_REPOSITORY https://github.com/simdjson/simdjson.git
GIT_TAG v3.1.6
GIT_SHALLOW 1
)
FetchContent_MakeAvailable(simdjson)
include_directories(${simdjson_SOURCE_DIR}/include)
if(${UCALL_BUILD_BENCHMARKS})
set(BENCHMARK_ENABLE_TESTING OFF)
set(BENCHMARK_ENABLE_INSTALL OFF)
set(BENCHMARK_ENABLE_DOXYGEN OFF)
set(BENCHMARK_INSTALL_DOCS OFF)
set(BENCHMARK_DOWNLOAD_DEPENDENCIES ON)
set(BENCHMARK_ENABLE_GTEST_TESTS OFF)
set(BENCHMARK_USE_BUNDLED_GTEST ON)
FetchContent_Declare(
benchmark
GIT_REPOSITORY https://github.com/google/benchmark
GIT_TAG v1.7.0
GIT_SHALLOW 1
)
FetchContent_MakeAvailable(benchmark)
include_directories(${benchmark_SOURCE_DIR}/include)
endif()
# CLI
FetchContent_Declare(
cxxopts
GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git
GIT_TAG v3.1.1
GIT_SHALLOW 1
)
FetchContent_MakeAvailable(cxxopts)
include_directories(${cxxopts_SOURCE_DIR}/include)
# Parsing HTTP headers
# On MacOS you may need to locate headers here:
# export CPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/
FetchContent_Declare(
picohttpparser
GIT_REPOSITORY https://github.com/unum-cloud/picohttpparser.git
GIT_SHALLOW 1
)
FetchContent_MakeAvailable(picohttpparser)
include_directories(${picohttpparser_SOURCE_DIR})
# Base64 decoding
FetchContent_Declare(
tb64
GIT_REPOSITORY https://github.com/unum-cloud/Turbo-Base64.git
GIT_SHALLOW 1
)
FetchContent_MakeAvailable(tb64)
include_directories(${tb64_SOURCE_DIR})
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
FetchContent_Declare(
mbedtls
GIT_REPOSITORY https://github.com/Mbed-TLS/mbedtls/
GIT_TAG v3.4.0
CMAKE_ARGS
-DENABLE_PROGRAMS=OFF
-DENABLE_TESTING=OFF
-DUSE_SHARED_MBEDTLS_LIBRARY=OFF
-DUSE_STATIC_MBEDTLS_LIBRARY=ON
)
FetchContent_MakeAvailable(mbedtls)
include_directories(${mbedtls_SOURCE_DIR}/include)
set(mbedtls_LIBS mbedtls mbedcrypto mbedx509)
# LibUring
if(LINUX)
set(URING_DIR ${CMAKE_BINARY_DIR}/_deps/liburing-ep)
ExternalProject_Add(
liburing-ep
GIT_REPOSITORY https://github.com/axboe/liburing.git
GIT_TAG liburing-2.3
GIT_SHALLOW 1
PREFIX ${CMAKE_BINARY_DIR}/_deps/
SOURCE_DIR ${URING_DIR}
CONFIGURE_COMMAND echo Configuring LibUring && cd ${URING_DIR} && ./configure --nolibc --cc=${CMAKE_C_COMPILER} --cxx=${CMAKE_CXX_COMPILER};
BUILD_COMMAND cd ${URING_DIR} && make;
INSTALL_COMMAND ""
UPDATE_COMMAND ""
)
add_library(uring_internal STATIC IMPORTED GLOBAL)
add_dependencies(uring_internal liburing-ep)
set_property(TARGET uring_internal
PROPERTY IMPORTED_LOCATION
${URING_DIR}/src/liburing.a
)
include_directories(${URING_DIR}/src/include/)
set(URING_LIBS uring_internal)
endif()
find_package(Threads REQUIRED)
include_directories(include/ src/)
add_library(ucall_server_posix src/engine_posix.cpp)
target_link_libraries(ucall_server_posix simdjson::simdjson Threads::Threads ${mbedtls_LIBS})
set(PYTHON_BACKEND ucall_server_posix)
add_executable(ucall_example_login_posix examples/login/ucall_server.cpp)
target_link_libraries(ucall_example_login_posix ucall_server_posix cxxopts)
target_compile_options(ucall_example_login_posix PUBLIC -DCXXOPTS_NO_EXCEPTIONS=ON)
if(LINUX)
add_library(ucall_server_uring src/engine_uring.cpp)
set(PYTHON_BACKEND ucall_server_uring)
target_link_libraries(ucall_server_uring simdjson::simdjson Threads::Threads ${URING_LIBS})
add_executable(ucall_example_login_uring examples/login/ucall_server.cpp)
target_link_libraries(ucall_example_login_uring ucall_server_uring cxxopts)
target_compile_options(ucall_example_login_uring PUBLIC -DCXXOPTS_NO_EXCEPTIONS=ON)
endif()
if(UCALL_BUILD_EXAMPLES)
add_executable(ucall_example_redis examples/redis/ucall_server.cpp)
target_link_libraries(ucall_example_redis ucall_server_posix)
find_package(Torch)
add_executable(ucall_example_pytorcs examples/pytorch/ucall_server.cpp)
target_link_libraries(ucall_example_pytorcs ucall_server_posix "${TORCH_LIBRARIES}")
endif()
# Python bindings
find_package(Python3 REQUIRED Development.Module)
include_directories(${Python_INCLUDE_DIRS})
if(LINUX)
Python3_add_library(py_ucall_uring src/python.c)
target_include_directories(py_ucall_uring PUBLIC src/ include/)
target_link_libraries(py_ucall_uring PRIVATE ucall_server_uring base64)
set_target_properties(py_ucall_uring PROPERTIES OUTPUT_NAME uring)
target_compile_definitions(py_ucall_uring PRIVATE UCALL_PYTHON_MODULE_NAME=uring)
endif()
Python3_add_library(py_ucall_posix src/python.c)
target_include_directories(py_ucall_posix PUBLIC src/ include/)
target_link_libraries(py_ucall_posix PRIVATE ucall_server_posix base64)
set_target_properties(py_ucall_posix PROPERTIES OUTPUT_NAME posix)
target_compile_definitions(py_ucall_posix PRIVATE UCALL_PYTHON_MODULE_NAME=posix)