Skip to content

Commit c398e85

Browse files
authored
Add Boost.Asio workflow (#1887)
* Add glz_asio library with asio version autoselection - Create glz_asio target that links Boost.Asio if it's found, or downloads standalone asio - Update all networking tests to use glz_asio * Add github actions workflow that tests glaze using Boost.Asio * Fix wrong target name * Update boost workflow to be similar to clang-linux-latest * Add gcc, clang and boost versions * Fix wrong g++ compiler name * Fix compiler matrix * Add workaround for clang-17's libc++
1 parent db2de6b commit c398e85

File tree

14 files changed

+106
-61
lines changed

14 files changed

+106
-61
lines changed

.github/workflows/boost-asio.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: boost-asio
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- feature/*
8+
paths-ignore:
9+
- '**/*.md'
10+
- 'docs/**'
11+
pull_request:
12+
branches:
13+
- main
14+
paths-ignore:
15+
- '**/*.md'
16+
- 'docs/**'
17+
workflow_dispatch:
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
compiler:
26+
- { name: clang, version: 17 }
27+
- { name: clang, version: 18 }
28+
- { name: clang, version: 20 }
29+
- { name: gcc, version: 12 }
30+
- { name: gcc, version: 13 }
31+
- { name: gcc, version: 14 }
32+
boost_version: [1.88.0, 1.73.0]
33+
34+
env:
35+
CC: ${{matrix.compiler.name}}-${{matrix.compiler.version}}
36+
CXX: ${{ matrix.compiler.name == 'gcc' && 'g++' || 'clang++' }}-${{matrix.compiler.version}}
37+
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- name: Install clang
42+
if: matrix.compiler.name == 'clang'
43+
run: |
44+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
45+
echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-${{ matrix.compiler.version }} main" | sudo tee /etc/apt/sources.list.d/llvm.list
46+
sudo apt-get update
47+
# Clang 17's libc++ does not compile, so we use the default libc++-dev and libc++abi-dev
48+
if [ "${{ matrix.compiler.version }}" = "17" ]; then
49+
sudo apt-get install -y --fix-missing clang-${{ matrix.compiler.version }} libc++-dev libc++abi-dev
50+
else
51+
sudo apt-get install -y --fix-missing clang-${{ matrix.compiler.version }} libc++-${{ matrix.compiler.version }}-dev libc++abi-${{ matrix.compiler.version }}-dev
52+
fi
53+
echo "PATH=/usr/lib/llvm-${{ matrix.compiler.version }}/bin:$PATH" >> $GITHUB_ENV
54+
55+
- name: Install Boost
56+
uses: MarkusJx/install-boost@v2
57+
with:
58+
boost_version: ${{ matrix.boost_version }}
59+
60+
- name: Configure CMake
61+
run: |
62+
CMAKE_CXX_FLAGS=""
63+
CMAKE_EXE_LINKER_FLAGS=""
64+
if [ "${{ matrix.compiler.name }}" = "clang" ]; then
65+
CMAKE_CXX_FLAGS="-stdlib=libc++"
66+
CMAKE_EXE_LINKER_FLAGS="-stdlib=libc++ -lc++abi"
67+
fi
68+
cmake -B ${{github.workspace}}/build \
69+
-DCMAKE_BUILD_TYPE=Debug \
70+
-DCMAKE_CXX_STANDARD=23 \
71+
-DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS" \
72+
-DCMAKE_EXE_LINKER_FLAGS="$CMAKE_EXE_LINKER_FLAGS"
73+
74+
- name: Build
75+
run: cmake --build build -j $(nproc)
76+
77+
- name: Test
78+
working-directory: build
79+
run: ctest -j $(nproc) --output-on-failure

tests/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ add_code_coverage_all_targets()
2020

2121
add_library(glz_test_common INTERFACE)
2222
target_compile_features(glz_test_common INTERFACE cxx_std_23)
23-
target_link_libraries(glz_test_common INTERFACE ut::ut glaze::glaze)
23+
target_link_libraries(glz_test_common INTERFACE ut::ut glaze::glaze glz_asio)
2424
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
2525
target_compile_options(glz_test_common INTERFACE -fno-exceptions -fno-rtti)
2626
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
@@ -35,7 +35,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
3535
target_compile_options(glz_test_common INTERFACE -Wall -Wextra -pedantic)
3636
endif()
3737

38-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
38+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
3939
target_compile_options(glz_test_common INTERFACE -ftime-trace -fsanitize=address -fsanitize-address-use-after-scope -fsanitize=undefined)
4040
target_link_options(glz_test_common INTERFACE -ftime-trace -fsanitize=address -fsanitize-address-use-after-scope -fsanitize=undefined)
4141
endif()
@@ -46,7 +46,7 @@ endif()
4646

4747
add_library(glz_test_exceptions INTERFACE)
4848
target_compile_features(glz_test_exceptions INTERFACE cxx_std_23)
49-
target_link_libraries(glz_test_exceptions INTERFACE ut::ut glaze::glaze)
49+
target_link_libraries(glz_test_exceptions INTERFACE ut::ut glaze::glaze glz_asio)
5050
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
5151
target_compile_options(glz_test_exceptions INTERFACE)
5252
target_compile_options(glz_test_exceptions INTERFACE -Wall -Wextra -pedantic)

tests/networking_tests/CMakeLists.txt

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
FetchContent_Declare(
2-
asio
3-
GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git
4-
GIT_TAG asio-1-32-0
5-
GIT_SHALLOW TRUE
6-
)
7-
FetchContent_MakeAvailable(asio)
1+
find_package(Boost QUIET CONFIG COMPONENTS system)
2+
3+
if(Boost_FOUND)
4+
add_library(glz_asio INTERFACE)
5+
target_link_libraries(glz_asio INTERFACE Boost::system)
6+
target_compile_definitions(glz_asio INTERFACE BOOST_ASIO_DYN_LINK)
7+
else()
8+
FetchContent_Declare(
9+
asio
10+
GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git
11+
GIT_TAG asio-1-32-0
12+
GIT_SHALLOW TRUE
13+
)
14+
FetchContent_MakeAvailable(asio)
15+
add_library(glz_asio INTERFACE)
16+
target_include_directories(glz_asio INTERFACE ${asio_SOURCE_DIR}/asio/include)
17+
endif()
18+
819

920
# HTTP Examples
1021
add_subdirectory(http_examples)
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
project(asio_repe)
22

3-
FetchContent_Declare(
4-
asio
5-
GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git
6-
GIT_TAG asio-1-32-0
7-
GIT_SHALLOW TRUE
8-
)
9-
FetchContent_MakeAvailable(asio)
10-
113
add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cpp)
124

13-
target_include_directories(${PROJECT_NAME} PRIVATE include ${asio_SOURCE_DIR}/asio/include)
145
target_link_libraries(${PROJECT_NAME} PRIVATE glz_test_exceptions)

tests/networking_tests/http_client_test/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ project(http_client_test)
22

33
add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cpp)
44

5-
target_include_directories(${PROJECT_NAME} PRIVATE include ${asio_SOURCE_DIR}/asio/include)
65
target_link_libraries(${PROJECT_NAME} PRIVATE glz_test_exceptions)
76

87
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})

tests/networking_tests/http_examples/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ project(http_examples)
22

33
add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cpp)
44

5-
target_include_directories(${PROJECT_NAME} PRIVATE include ${asio_SOURCE_DIR}/asio/include)
65
target_link_libraries(${PROJECT_NAME} PRIVATE glz_test_exceptions)
76

87
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})

tests/networking_tests/http_router_test/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ project(http_router_test)
22

33
add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cpp)
44

5-
target_include_directories(${PROJECT_NAME} PRIVATE include ${asio_SOURCE_DIR}/asio/include)
65
target_link_libraries(${PROJECT_NAME} PRIVATE glz_test_exceptions)
76

87
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})

tests/networking_tests/http_server_api_tests/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ project(http_server_api_tests)
22

33
add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cpp)
44

5-
target_include_directories(${PROJECT_NAME} PRIVATE include ${asio_SOURCE_DIR}/asio/include)
65
target_link_libraries(${PROJECT_NAME} PRIVATE glz_test_exceptions)
76

87
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})

tests/networking_tests/https_test/CMakeLists.txt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ project(https_test)
55
# Only build if OpenSSL is available
66
find_package(OpenSSL REQUIRED)
77

8-
FetchContent_Declare(
9-
asio
10-
GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git
11-
GIT_TAG asio-1-32-0
12-
GIT_SHALLOW TRUE
13-
)
14-
FetchContent_MakeAvailable(asio)
8+
159

1610
# Test if we can actually compile with OpenSSL headers
1711
include(CheckCXXSourceCompiles)
@@ -33,9 +27,7 @@ if(OPENSSL_HEADERS_AVAILABLE)
3327
OpenSSL::SSL
3428
OpenSSL::Crypto
3529
)
36-
target_compile_definitions(${PROJECT_NAME} PRIVATE GLZ_ENABLE_SSL)
37-
target_include_directories(${PROJECT_NAME} PRIVATE include ${asio_SOURCE_DIR}/asio/include)
38-
target_compile_definitions(${PROJECT_NAME} PRIVATE SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
30+
target_compile_definitions(${PROJECT_NAME} PRIVATE GLZ_ENABLE_SSL SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
3931

4032
# Set C++ standard
4133
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_23)
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
project(openapi_test)
22

3-
FetchContent_Declare(
4-
asio
5-
GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git
6-
GIT_TAG asio-1-32-0
7-
GIT_SHALLOW TRUE
8-
)
9-
FetchContent_MakeAvailable(asio)
3+
104

115
add_executable(openapi_test openapi_test.cpp)
12-
target_include_directories(openapi_test PRIVATE include ${asio_SOURCE_DIR}/asio/include)
136
target_link_libraries(openapi_test PRIVATE glz_test_exceptions)

0 commit comments

Comments
 (0)