Skip to content

Commit 4792ead

Browse files
committed
Add GitHub Actions workflow for C++20 streaming tests and update CMakeLists for new test executable
1 parent cfcbee9 commit 4792ead

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

.github/workflows/test-stream.yaml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: test-stream
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
inputs:
8+
gtest_filter:
9+
description: 'Google Test filter'
10+
test_linux:
11+
description: 'Test on Linux'
12+
type: boolean
13+
default: true
14+
test_macos:
15+
description: 'Test on MacOS'
16+
type: boolean
17+
default: true
18+
test_windows:
19+
description: 'Test on Windows'
20+
type: boolean
21+
default: true
22+
23+
concurrency:
24+
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
25+
cancel-in-progress: true
26+
27+
env:
28+
GTEST_FILTER: ${{ github.event.inputs.gtest_filter || '*' }}
29+
30+
jobs:
31+
ubuntu:
32+
runs-on: ubuntu-24.04
33+
if: >
34+
(github.event_name == 'push') ||
35+
(github.event_name == 'pull_request' &&
36+
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
37+
(github.event_name == 'workflow_dispatch' && github.event.inputs.test_linux == 'true')
38+
steps:
39+
- name: checkout
40+
uses: actions/checkout@v4
41+
- name: install libraries
42+
run: |
43+
sudo apt-get update
44+
sudo apt-get install -y libssl-dev libcurl4-openssl-dev \
45+
zlib1g-dev libbrotli-dev libzstd-dev
46+
- name: build and run C++20 streaming tests
47+
run: cd test && make test-stream && ./test-stream --gtest_filter="${GTEST_FILTER}"
48+
49+
macos:
50+
runs-on: macos-latest
51+
if: >
52+
(github.event_name == 'push') ||
53+
(github.event_name == 'pull_request' &&
54+
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
55+
(github.event_name == 'workflow_dispatch' && github.event.inputs.test_macos == 'true')
56+
steps:
57+
- name: checkout
58+
uses: actions/checkout@v4
59+
- name: build and run C++20 streaming tests
60+
run: cd test && make test-stream && ./test-stream --gtest_filter="${GTEST_FILTER}"
61+
62+
windows:
63+
runs-on: windows-latest
64+
if: >
65+
(github.event_name == 'push') ||
66+
(github.event_name == 'pull_request' &&
67+
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
68+
(github.event_name == 'workflow_dispatch' && github.event.inputs.test_windows == 'true')
69+
strategy:
70+
matrix:
71+
config:
72+
- with_ssl: false
73+
name: without SSL
74+
- with_ssl: true
75+
name: with SSL
76+
name: windows ${{ matrix.config.name }}
77+
steps:
78+
- name: Prepare Git for Checkout on Windows
79+
run: |
80+
git config --global core.autocrlf false
81+
git config --global core.eol lf
82+
- name: Checkout
83+
uses: actions/checkout@v4
84+
- name: Export GitHub Actions cache environment variables
85+
uses: actions/github-script@v7
86+
with:
87+
script: |
88+
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
89+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
90+
- name: Setup msbuild on windows
91+
uses: microsoft/setup-msbuild@v2
92+
- name: Install vcpkg dependencies
93+
run: vcpkg install gtest curl zlib brotli zstd
94+
- name: Install OpenSSL
95+
if: ${{ matrix.config.with_ssl }}
96+
run: choco install openssl
97+
- name: Configure CMake ${{ matrix.config.name }}
98+
run: >
99+
cmake -B build -S .
100+
-DCMAKE_BUILD_TYPE=Release
101+
-DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake
102+
-DHTTPLIB_TEST=ON
103+
-DHTTPLIB_REQUIRE_ZLIB=ON
104+
-DHTTPLIB_REQUIRE_BROTLI=ON
105+
-DHTTPLIB_REQUIRE_ZSTD=ON
106+
-DHTTPLIB_REQUIRE_OPENSSL=${{ matrix.config.with_ssl && 'ON' || 'OFF' }}
107+
- name: Build ${{ matrix.config.name }}
108+
run: cmake --build build --config Release -- /v:m /clp:ShowCommandLine
109+
- name: Run C++20 streaming tests ${{ matrix.config.name }}
110+
run: ctest --output-on-failure --test-dir build -C Release -R "httplib-test-stream"
111+
112+
env:
113+
VCPKG_ROOT: "C:/vcpkg"
114+
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ target_link_libraries(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
277277
$<$<PLATFORM_ID:Windows>:crypt32>
278278
# Needed for API from MacOS Security framework
279279
"$<$<AND:$<PLATFORM_ID:Darwin>,$<BOOL:${HTTPLIB_IS_USING_OPENSSL}>,$<BOOL:${HTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN}>>:-framework CoreFoundation -framework Security>"
280+
# Needed for non-blocking getaddrinfo on macOS
281+
"$<$<AND:$<PLATFORM_ID:Darwin>,$<BOOL:${HTTPLIB_USE_NON_BLOCKING_GETADDRINFO}>>:-framework CoreFoundation -framework CFNetwork>"
280282
# Can't put multiple targets in a single generator expression or it bugs out.
281283
$<$<BOOL:${HTTPLIB_IS_USING_BROTLI}>:Brotli::common>
282284
$<$<BOOL:${HTTPLIB_IS_USING_BROTLI}>:Brotli::encoder>

test/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,28 @@ target_compile_options(httplib-test PRIVATE "$<$<CXX_COMPILER_ID:MSVC>:/utf-8;/b
3131
target_link_libraries(httplib-test PRIVATE httplib GTest::gtest_main CURL::libcurl)
3232
gtest_discover_tests(httplib-test)
3333

34+
# C++20 streaming API tests
35+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang|MSVC")
36+
# Check for C++20 support
37+
include(CheckCXXCompilerFlag)
38+
check_cxx_compiler_flag("-std=c++20" COMPILER_SUPPORTS_CXX20)
39+
if(MSVC)
40+
set(COMPILER_SUPPORTS_CXX20 TRUE)
41+
endif()
42+
43+
if(COMPILER_SUPPORTS_CXX20)
44+
add_executable(httplib-test-stream test-stream.cc)
45+
target_compile_features(httplib-test-stream PRIVATE cxx_std_20)
46+
target_compile_options(httplib-test-stream PRIVATE
47+
"$<$<CXX_COMPILER_ID:MSVC>:/utf-8;/bigobj>"
48+
)
49+
target_link_libraries(httplib-test-stream PRIVATE httplib GTest::gtest_main)
50+
gtest_discover_tests(httplib-test-stream)
51+
else()
52+
message(STATUS "C++20 not supported, skipping test-stream")
53+
endif()
54+
endif()
55+
3456
file(
3557
COPY www www2 www3 ca-bundle.crt image.jpg
3658
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}

0 commit comments

Comments
 (0)