test.yaml 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. name: test
  2. on:
  3. push:
  4. pull_request:
  5. workflow_dispatch:
  6. inputs:
  7. gtest_filter:
  8. description: 'Google Test filter'
  9. test_linux:
  10. description: 'Test on Linux'
  11. type: boolean
  12. default: true
  13. test_macos:
  14. description: 'Test on MacOS'
  15. type: boolean
  16. default: true
  17. test_windows:
  18. description: 'Test on Windows'
  19. type: boolean
  20. default: true
  21. concurrency:
  22. group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
  23. cancel-in-progress: true
  24. env:
  25. # Exclude *_Online tests by default — they hit external services and flake on
  26. # CI runners. Run with workflow_dispatch + a custom filter to include them.
  27. GTEST_FILTER: ${{ github.event.inputs.gtest_filter || '-*_Online' }}
  28. jobs:
  29. style-check:
  30. runs-on: ubuntu-latest
  31. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
  32. continue-on-error: true
  33. steps:
  34. - name: checkout
  35. uses: actions/checkout@v4
  36. - name: run style check
  37. run: |
  38. clang-format --version
  39. cd test && make style_check
  40. build-and-test-on-32bit:
  41. runs-on: ubuntu-latest
  42. if: >
  43. (github.event_name == 'push') ||
  44. (github.event_name == 'pull_request' &&
  45. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  46. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_linux == 'true')
  47. strategy:
  48. matrix:
  49. config:
  50. - arch_flags: -m32
  51. arch_suffix: :i386
  52. name: (32-bit)
  53. steps:
  54. - name: checkout
  55. uses: actions/checkout@v4
  56. - name: install libraries
  57. run: |
  58. sudo dpkg --add-architecture i386
  59. sudo apt-get update
  60. sudo apt-get install -y libc6-dev${{ matrix.config.arch_suffix }} libstdc++-13-dev${{ matrix.config.arch_suffix }} \
  61. libssl-dev${{ matrix.config.arch_suffix }} libcurl4-openssl-dev${{ matrix.config.arch_suffix }} \
  62. zlib1g-dev${{ matrix.config.arch_suffix }} libbrotli-dev${{ matrix.config.arch_suffix }} \
  63. libzstd-dev${{ matrix.config.arch_suffix }}
  64. - name: build and run tests
  65. run: cd test && make test EXTRA_CXXFLAGS="${{ matrix.config.arch_flags }}"
  66. ubuntu:
  67. runs-on: ubuntu-latest
  68. if: >
  69. (github.event_name == 'push') ||
  70. (github.event_name == 'pull_request' &&
  71. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  72. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_linux == 'true')
  73. strategy:
  74. fail-fast: false
  75. matrix:
  76. tls_backend: [openssl, mbedtls, wolfssl]
  77. name: ubuntu (${{ matrix.tls_backend }})
  78. steps:
  79. - name: checkout
  80. uses: actions/checkout@v4
  81. - name: install common libraries
  82. run: |
  83. sudo apt-get update
  84. sudo apt-get install -y libcurl4-openssl-dev zlib1g-dev libbrotli-dev libzstd-dev
  85. - name: install OpenSSL
  86. if: matrix.tls_backend == 'openssl'
  87. run: sudo apt-get install -y libssl-dev
  88. - name: install Mbed TLS
  89. if: matrix.tls_backend == 'mbedtls'
  90. run: sudo apt-get install -y libmbedtls-dev
  91. - name: install wolfSSL
  92. if: matrix.tls_backend == 'wolfssl'
  93. run: sudo apt-get install -y libwolfssl-dev
  94. - name: build and run tests (OpenSSL)
  95. if: matrix.tls_backend == 'openssl'
  96. run: cd test && make test_split && make test_openssl_parallel
  97. env:
  98. LSAN_OPTIONS: suppressions=lsan_suppressions.txt
  99. - name: build and run tests (Mbed TLS)
  100. if: matrix.tls_backend == 'mbedtls'
  101. run: cd test && make test_split_mbedtls && make test_mbedtls_parallel
  102. - name: build and run tests (wolfSSL)
  103. if: matrix.tls_backend == 'wolfssl'
  104. run: cd test && make test_split_wolfssl && make test_wolfssl_parallel
  105. - name: run fuzz test target
  106. if: matrix.tls_backend == 'openssl'
  107. run: cd test && make fuzz_test
  108. - name: build and run WebSocket heartbeat test
  109. if: matrix.tls_backend == 'openssl'
  110. run: cd test && make test_websocket_heartbeat && ./test_websocket_heartbeat
  111. - name: build and run ThreadPool test
  112. run: cd test && make test_thread_pool && ./test_thread_pool
  113. # Ubuntu 26.04's apt ships Mbed TLS 3.6, giving 3.x coverage that
  114. # ubuntu-latest (24.04 = 2.28) and macOS (Homebrew = 4.x) no longer provide.
  115. # Uses the 26.04 public-preview image; fold into the main ubuntu matrix once
  116. # ubuntu-latest moves to 26.04.
  117. ubuntu-2604-mbedtls:
  118. runs-on: ubuntu-26.04
  119. if: >
  120. (github.event_name == 'push') ||
  121. (github.event_name == 'pull_request' &&
  122. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  123. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_linux == 'true')
  124. name: ubuntu-26.04 (mbedtls 3.x)
  125. steps:
  126. - name: checkout
  127. uses: actions/checkout@v4
  128. - name: install common libraries
  129. run: |
  130. sudo apt-get update
  131. sudo apt-get install -y libcurl4-openssl-dev zlib1g-dev libbrotli-dev libzstd-dev
  132. - name: install Mbed TLS
  133. run: sudo apt-get install -y libmbedtls-dev
  134. - name: build and run tests (Mbed TLS)
  135. run: cd test && make test_split_mbedtls && make test_mbedtls_parallel
  136. # BoringSSL is Google's fork of OpenSSL. It has no API stability guarantee
  137. # and is not packaged by distros, so we build it from source. cpp-httplib
  138. # treats it as an OpenSSL backend variant via the OPENSSL_IS_BORINGSSL
  139. # macro (see httplib.h). This job is best-effort: continue-on-error keeps
  140. # upstream API drift from blocking PRs while still surfacing breakage.
  141. ubuntu-boringssl:
  142. runs-on: ubuntu-latest
  143. if: >
  144. (github.event_name == 'push') ||
  145. (github.event_name == 'pull_request' &&
  146. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  147. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_linux == 'true')
  148. continue-on-error: true
  149. name: ubuntu (boringssl, best-effort)
  150. env:
  151. # Tracking HEAD keeps us honest about upstream churn. If breakage
  152. # becomes routine, replace HEAD with a 40-char commit SHA; the
  153. # resolve step uses the SHA directly when it matches that shape.
  154. BORINGSSL_REF: HEAD
  155. BORINGSSL_PREFIX: ${{ github.workspace }}/boringssl-install
  156. steps:
  157. - name: checkout
  158. uses: actions/checkout@v4
  159. - name: install common libraries
  160. run: |
  161. sudo apt-get update
  162. sudo apt-get install -y libcurl4-openssl-dev zlib1g-dev libbrotli-dev libzstd-dev
  163. - name: resolve BoringSSL commit
  164. id: boringssl-rev
  165. # Accept either a ref name (resolved via git ls-remote) or a full
  166. # 40-char SHA used directly. ls-remote does not list arbitrary
  167. # commit SHAs, so pinning requires the second path.
  168. run: |
  169. if [[ "${BORINGSSL_REF}" =~ ^[0-9a-f]{40}$ ]]; then
  170. sha="${BORINGSSL_REF}"
  171. echo "Using pinned BoringSSL SHA: ${sha}"
  172. else
  173. sha=$(git ls-remote https://boringssl.googlesource.com/boringssl "${BORINGSSL_REF}" | awk '{print $1}')
  174. if [ -z "$sha" ]; then
  175. echo "Failed to resolve BoringSSL ref ${BORINGSSL_REF}" >&2
  176. exit 1
  177. fi
  178. echo "Resolved ${BORINGSSL_REF} -> ${sha}"
  179. fi
  180. echo "sha=${sha}" >> "$GITHUB_OUTPUT"
  181. - name: cache BoringSSL build
  182. id: boringssl-cache
  183. uses: actions/cache@v4
  184. with:
  185. path: ${{ env.BORINGSSL_PREFIX }}
  186. key: boringssl-${{ runner.os }}-${{ steps.boringssl-rev.outputs.sha }}
  187. - name: build BoringSSL
  188. if: steps.boringssl-cache.outputs.cache-hit != 'true'
  189. run: |
  190. set -e
  191. git clone https://boringssl.googlesource.com/boringssl boringssl
  192. cd boringssl
  193. git checkout "${{ steps.boringssl-rev.outputs.sha }}"
  194. cmake -S . -B build \
  195. -DCMAKE_BUILD_TYPE=Release \
  196. -DBUILD_SHARED_LIBS=OFF \
  197. -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
  198. -DCMAKE_INSTALL_PREFIX="${BORINGSSL_PREFIX}"
  199. cmake --build build -j"$(nproc)" --target install
  200. - name: build and run tests (BoringSSL)
  201. # Override OPENSSL_SUPPORT to point the existing OpenSSL Makefile path
  202. # at BoringSSL's prefix. BoringSSL defines OPENSSL_IS_BORINGSSL in
  203. # <openssl/base.h>, which httplib.h and test.cc use to switch on API
  204. # differences (e.g. SAN-only hostname verification, no CN fallback).
  205. #
  206. # BoringSSL's public headers (<openssl/stack.h>) use std::enable_if_t,
  207. # so consumers must compile with C++14 or later. cpp-httplib itself
  208. # supports C++11, but anyone pairing it with BoringSSL inherits this
  209. # constraint. EXTRA_CXXFLAGS appends after the Makefile's -std=c++11
  210. # and the later flag wins.
  211. run: |
  212. cd test
  213. BORINGSSL_FLAGS="-DCPPHTTPLIB_OPENSSL_SUPPORT -I${BORINGSSL_PREFIX}/include -L${BORINGSSL_PREFIX}/lib -lssl -lcrypto -lpthread"
  214. make test_split OPENSSL_SUPPORT="${BORINGSSL_FLAGS}" EXTRA_CXXFLAGS="-std=c++17"
  215. make test_openssl_parallel OPENSSL_SUPPORT="${BORINGSSL_FLAGS}" EXTRA_CXXFLAGS="-std=c++17"
  216. env:
  217. LSAN_OPTIONS: suppressions=lsan_suppressions.txt
  218. # macOS counterpart of the BoringSSL job. Same best-effort posture; the
  219. # extra framework links cover the macOS Keychain integration that
  220. # httplib.h auto-enables for any TLS backend on macOS.
  221. macos-boringssl:
  222. runs-on: macos-latest
  223. if: >
  224. (github.event_name == 'push') ||
  225. (github.event_name == 'pull_request' &&
  226. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  227. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_macos == 'true')
  228. continue-on-error: true
  229. name: macos (boringssl, best-effort)
  230. env:
  231. BORINGSSL_REF: HEAD
  232. BORINGSSL_PREFIX: ${{ github.workspace }}/boringssl-install
  233. steps:
  234. - name: checkout
  235. uses: actions/checkout@v4
  236. - name: resolve BoringSSL commit
  237. id: boringssl-rev
  238. # Accept either a ref name (resolved via git ls-remote) or a full
  239. # 40-char SHA used directly. ls-remote does not list arbitrary
  240. # commit SHAs, so pinning requires the second path.
  241. run: |
  242. if [[ "${BORINGSSL_REF}" =~ ^[0-9a-f]{40}$ ]]; then
  243. sha="${BORINGSSL_REF}"
  244. echo "Using pinned BoringSSL SHA: ${sha}"
  245. else
  246. sha=$(git ls-remote https://boringssl.googlesource.com/boringssl "${BORINGSSL_REF}" | awk '{print $1}')
  247. if [ -z "$sha" ]; then
  248. echo "Failed to resolve BoringSSL ref ${BORINGSSL_REF}" >&2
  249. exit 1
  250. fi
  251. echo "Resolved ${BORINGSSL_REF} -> ${sha}"
  252. fi
  253. echo "sha=${sha}" >> "$GITHUB_OUTPUT"
  254. - name: cache BoringSSL build
  255. id: boringssl-cache
  256. uses: actions/cache@v4
  257. with:
  258. path: ${{ env.BORINGSSL_PREFIX }}
  259. key: boringssl-${{ runner.os }}-${{ steps.boringssl-rev.outputs.sha }}
  260. - name: build BoringSSL
  261. if: steps.boringssl-cache.outputs.cache-hit != 'true'
  262. run: |
  263. set -e
  264. git clone https://boringssl.googlesource.com/boringssl boringssl
  265. cd boringssl
  266. git checkout "${{ steps.boringssl-rev.outputs.sha }}"
  267. cmake -S . -B build \
  268. -DCMAKE_BUILD_TYPE=Release \
  269. -DBUILD_SHARED_LIBS=OFF \
  270. -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
  271. -DCMAKE_INSTALL_PREFIX="${BORINGSSL_PREFIX}"
  272. cmake --build build -j"$(sysctl -n hw.ncpu)" --target install
  273. - name: build and run tests (BoringSSL)
  274. run: |
  275. cd test
  276. # CoreFoundation/Security frameworks satisfy the Keychain integration
  277. # auto-enabled in httplib.h for macOS TLS builds.
  278. BORINGSSL_FLAGS="-DCPPHTTPLIB_OPENSSL_SUPPORT -I${BORINGSSL_PREFIX}/include -L${BORINGSSL_PREFIX}/lib -lssl -lcrypto -framework CoreFoundation -framework Security"
  279. make test_split OPENSSL_SUPPORT="${BORINGSSL_FLAGS}" EXTRA_CXXFLAGS="-std=c++17"
  280. make test_openssl_parallel OPENSSL_SUPPORT="${BORINGSSL_FLAGS}" EXTRA_CXXFLAGS="-std=c++17"
  281. env:
  282. LSAN_OPTIONS: suppressions=lsan_suppressions.txt
  283. # Reproducer for https://github.com/yhirose/cpp-httplib/issues/2431.
  284. # On Linux/glibc, getaddrinfo_with_timeout() schedules an asynchronous
  285. # DNS lookup with getaddrinfo_a(GAI_NOWAIT) using a stack-local gaicb.
  286. # When gai_suspend() hits the connection timeout, gai_cancel() is called
  287. # but does not block; the resolver worker can later write back into the
  288. # destroyed stack frame. To make the worker actually reach that write,
  289. # the test job runs a loopback UDP responder (test/dns_test_fixture.py)
  290. # that delays its reply past the test's 1s timeout, and uses an iptables
  291. # NAT rule so glibc's lookups land on that fixture instead of a real
  292. # nameserver. With ASAN's detect_stack_use_after_return enabled, the
  293. # late write-back is reported as a stack-use-after-return.
  294. issue-2431-repro:
  295. runs-on: ubuntu-latest
  296. if: >
  297. (github.event_name == 'push') ||
  298. (github.event_name == 'pull_request' &&
  299. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  300. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_linux == 'true')
  301. name: issue-2431 repro (Linux + ASAN)
  302. # Bound the whole job in case anything in the test harness hangs
  303. # unexpectedly. With the fixture in place a normal run is well under
  304. # a minute either way (ASAN abort on broken HEAD, clean pass on fix).
  305. timeout-minutes: 5
  306. env:
  307. DNS_FIXTURE_PORT: "15353"
  308. DNS_FIXTURE_DELAY: "3"
  309. steps:
  310. - name: checkout
  311. uses: actions/checkout@v4
  312. - name: install libraries
  313. run: |
  314. sudo apt-get update
  315. sudo apt-get install -y libssl-dev zlib1g-dev libbrotli-dev \
  316. libzstd-dev libcurl4-openssl-dev iptables util-linux iproute2
  317. - name: start loopback DNS test fixture
  318. run: |
  319. # Force glibc through its DNS code path: Ubuntu's default
  320. # nsswitch short-circuits to NOTFOUND through mdns4_minimal,
  321. # which would skip the buggy code entirely.
  322. sudo sed -i 's/^hosts:.*/hosts: dns/' /etc/nsswitch.conf
  323. # Run the loopback fixture (delayed UDP responder).
  324. python3 test/dns_test_fixture.py "$DNS_FIXTURE_PORT" "$DNS_FIXTURE_DELAY" \
  325. >/tmp/dns_fixture.log 2>&1 &
  326. echo $! | sudo tee /tmp/dns_fixture.pid >/dev/null
  327. # Wait for the fixture to start listening.
  328. for _ in $(seq 1 50); do
  329. if ss -lun "( sport = :$DNS_FIXTURE_PORT )" | grep -q ":$DNS_FIXTURE_PORT"; then
  330. break
  331. fi
  332. sleep 0.1
  333. done
  334. ss -lun "( sport = :$DNS_FIXTURE_PORT )" | grep -q ":$DNS_FIXTURE_PORT" \
  335. || { echo "fixture failed to start"; cat /tmp/dns_fixture.log; exit 1; }
  336. # Send the test process's DNS lookups to the loopback fixture.
  337. # NAT only the local OUTPUT chain; conntrack handles the reply path.
  338. sudo iptables -t nat -I OUTPUT -p udp --dport 53 \
  339. -j REDIRECT --to-port "$DNS_FIXTURE_PORT"
  340. # Sanity check: a query must take at least the fixture delay
  341. # and resolve to NXDOMAIN (proving traffic reaches the fixture).
  342. start=$(date +%s)
  343. getent hosts unresolvable-host.invalid >/dev/null 2>&1 || true
  344. elapsed=$(( $(date +%s) - start ))
  345. if [ "$elapsed" -lt 2 ]; then
  346. echo "ERROR: lookup returned in ${elapsed}s; fixture not in path" >&2
  347. exit 1
  348. fi
  349. echo "[ok] DNS lookups are routed to the test fixture (took ${elapsed}s)"
  350. - name: build test binary
  351. run: cd test && make test
  352. - name: run GetAddrInfoAsyncCancelTest
  353. run: |
  354. cd test
  355. ARCH=$(uname -m)
  356. CPPHTTPLIB_TEST_ISSUE_2431=1 \
  357. ASAN_OPTIONS=detect_stack_use_after_return=1 \
  358. LSAN_OPTIONS=suppressions=lsan_suppressions.txt \
  359. setarch "$ARCH" -R \
  360. ./test --gtest_filter='GetAddrInfoAsyncCancelTest.*'
  361. - name: tear down test fixture
  362. if: always()
  363. run: |
  364. sudo iptables -t nat -F OUTPUT || true
  365. if [ -f /tmp/dns_fixture.pid ]; then
  366. sudo kill "$(cat /tmp/dns_fixture.pid)" 2>/dev/null || true
  367. fi
  368. macos:
  369. runs-on: macos-latest
  370. if: >
  371. (github.event_name == 'push') ||
  372. (github.event_name == 'pull_request' &&
  373. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  374. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_macos == 'true')
  375. strategy:
  376. fail-fast: false
  377. matrix:
  378. tls_backend: [openssl, mbedtls, wolfssl]
  379. name: macos (${{ matrix.tls_backend }})
  380. steps:
  381. - name: checkout
  382. uses: actions/checkout@v4
  383. - name: install Mbed TLS
  384. if: matrix.tls_backend == 'mbedtls'
  385. run: brew install mbedtls
  386. - name: install wolfSSL
  387. if: matrix.tls_backend == 'wolfssl'
  388. run: brew install wolfssl
  389. - name: build and run tests (OpenSSL)
  390. if: matrix.tls_backend == 'openssl'
  391. run: cd test && make test_split && make test_openssl_parallel
  392. env:
  393. LSAN_OPTIONS: suppressions=lsan_suppressions.txt
  394. - name: build and run tests (Mbed TLS)
  395. if: matrix.tls_backend == 'mbedtls'
  396. run: cd test && make test_split_mbedtls && make test_mbedtls_parallel
  397. - name: build and run tests (wolfSSL)
  398. if: matrix.tls_backend == 'wolfssl'
  399. run: cd test && make test_split_wolfssl && make test_wolfssl_parallel
  400. - name: run fuzz test target
  401. if: matrix.tls_backend == 'openssl'
  402. run: cd test && make fuzz_test
  403. - name: build and run WebSocket heartbeat test
  404. if: matrix.tls_backend == 'openssl'
  405. run: cd test && make test_websocket_heartbeat && ./test_websocket_heartbeat
  406. - name: build and run ThreadPool test
  407. run: cd test && make test_thread_pool && ./test_thread_pool
  408. ios-parse-check:
  409. runs-on: macos-latest
  410. if: >
  411. (github.event_name == 'push') ||
  412. (github.event_name == 'pull_request' &&
  413. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  414. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_macos == 'true')
  415. name: ios header parse check (not officially supported)
  416. steps:
  417. - name: checkout
  418. uses: actions/checkout@v4
  419. - name: install OpenSSL headers
  420. run: brew install openssl@3
  421. - name: verify header parses on iOS target
  422. run: |
  423. IOS_SDK=$(xcrun --sdk iphoneos --show-sdk-path)
  424. OPENSSL_INC=$(brew --prefix openssl@3)/include
  425. echo "Using iOS SDK: $IOS_SDK"
  426. echo '#include "httplib.h"' | clang++ \
  427. -isysroot "$IOS_SDK" \
  428. -target arm64-apple-ios16.0 \
  429. -std=c++11 \
  430. -DCPPHTTPLIB_OPENSSL_SUPPORT \
  431. -I"$OPENSSL_INC" \
  432. -I. -Wall -Wextra \
  433. -fsyntax-only -x c++ -
  434. - name: verify CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN is rejected on iOS
  435. run: |
  436. IOS_SDK=$(xcrun --sdk iphoneos --show-sdk-path)
  437. OPENSSL_INC=$(brew --prefix openssl@3)/include
  438. out=$(echo '#include "httplib.h"' | clang++ \
  439. -isysroot "$IOS_SDK" \
  440. -target arm64-apple-ios16.0 \
  441. -std=c++11 \
  442. -DCPPHTTPLIB_OPENSSL_SUPPORT \
  443. -DCPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN \
  444. -I"$OPENSSL_INC" \
  445. -I. \
  446. -fsyntax-only -x c++ - 2>&1 || true)
  447. if echo "$out" | grep -q "only supported on macOS"; then
  448. echo "OK: #error fired as expected"
  449. else
  450. echo "FAIL: expected #error did not fire"
  451. echo "--- compiler output ---"
  452. echo "$out"
  453. exit 1
  454. fi
  455. windows:
  456. runs-on: windows-latest
  457. permissions:
  458. contents: read
  459. issues: write
  460. if: >
  461. (github.event_name == 'push') ||
  462. (github.event_name == 'pull_request' &&
  463. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  464. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_windows == 'true')
  465. strategy:
  466. fail-fast: false
  467. matrix:
  468. config:
  469. - with_ssl: false
  470. compiled: false
  471. run_tests: true
  472. name: without SSL
  473. - with_ssl: true
  474. compiled: false
  475. run_tests: true
  476. name: with SSL
  477. - with_ssl: false
  478. compiled: true
  479. run_tests: false
  480. name: compiled
  481. name: windows ${{ matrix.config.name }}
  482. steps:
  483. - name: Prepare Git for Checkout on Windows
  484. run: |
  485. git config --global core.autocrlf false
  486. git config --global core.eol lf
  487. - name: Checkout
  488. uses: actions/checkout@v4
  489. - name: Export GitHub Actions cache environment variables
  490. uses: actions/github-script@v7
  491. with:
  492. script: |
  493. core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
  494. core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
  495. - name: Setup msbuild on windows
  496. uses: microsoft/setup-msbuild@v2
  497. - name: Cache vcpkg packages
  498. id: vcpkg-cache
  499. uses: actions/cache@v4
  500. with:
  501. path: C:/vcpkg/installed
  502. key: vcpkg-installed-windows-gtest-curl-zlib-brotli-zstd
  503. - name: Install vcpkg dependencies
  504. if: steps.vcpkg-cache.outputs.cache-hit != 'true'
  505. run: vcpkg install gtest curl zlib brotli zstd
  506. - name: Install OpenSSL
  507. if: ${{ matrix.config.with_ssl }}
  508. run: choco install openssl
  509. - name: Configure CMake ${{ matrix.config.name }}
  510. run: >
  511. cmake -B build -S .
  512. -DCMAKE_BUILD_TYPE=Release
  513. -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake
  514. -DHTTPLIB_TEST=ON
  515. -DHTTPLIB_COMPILE=${{ matrix.config.compiled && 'ON' || 'OFF' }}
  516. -DHTTPLIB_USE_OPENSSL_IF_AVAILABLE=${{ matrix.config.with_ssl && 'ON' || 'OFF' }}
  517. -DHTTPLIB_REQUIRE_ZLIB=ON
  518. -DHTTPLIB_REQUIRE_BROTLI=ON
  519. -DHTTPLIB_REQUIRE_ZSTD=ON
  520. -DHTTPLIB_REQUIRE_OPENSSL=${{ matrix.config.with_ssl && 'ON' || 'OFF' }}
  521. - name: Build ${{ matrix.config.name }}
  522. run: cmake --build build --config Release -- /v:m /clp:ShowCommandLine
  523. - name: Run tests ${{ matrix.config.name }}
  524. if: ${{ matrix.config.run_tests }}
  525. shell: pwsh
  526. working-directory: build/test
  527. run: |
  528. $shards = 4
  529. $procs = @()
  530. for ($i = 0; $i -lt $shards; $i++) {
  531. $log = "shard_${i}.log"
  532. $procs += Start-Process -FilePath ./Release/httplib-test.exe `
  533. -ArgumentList "--gtest_color=yes","--gtest_filter=${{ github.event.inputs.gtest_filter || '-*_Online' }}" `
  534. -NoNewWindow -PassThru -RedirectStandardOutput $log -RedirectStandardError "${log}.err" `
  535. -Environment @{ GTEST_TOTAL_SHARDS="$shards"; GTEST_SHARD_INDEX="$i" }
  536. }
  537. $procs | Wait-Process
  538. $failed = $false
  539. for ($i = 0; $i -lt $shards; $i++) {
  540. $log = "shard_${i}.log"
  541. $proc = $procs[$i]
  542. $hasPassed = Select-String -Path $log -Pattern "\[ PASSED \]" -Quiet
  543. $hasFailed = Select-String -Path $log -Pattern "\[ FAILED \]" -Quiet
  544. if ($hasPassed -and -not $hasFailed -and $proc.ExitCode -eq 0) {
  545. $passed = (Select-String -Path $log -Pattern "\[ PASSED \]").Line
  546. Write-Host "Shard ${i}: $passed"
  547. } else {
  548. Write-Host "=== Shard $i FAILED (exit=$($proc.ExitCode)) ==="
  549. Get-Content $log
  550. if (Test-Path "${log}.err") { Get-Content "${log}.err" }
  551. $failed = $true
  552. }
  553. }
  554. if ($failed) { exit 1 }
  555. Write-Host "All shards passed."
  556. - name: Report flaky failure on issue #2533
  557. if: failure() && matrix.config.name == 'without SSL' && github.event_name == 'push'
  558. continue-on-error: true
  559. shell: pwsh
  560. working-directory: build/test
  561. env:
  562. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  563. run: |
  564. $summary = ""
  565. for ($i = 0; $i -lt 4; $i++) {
  566. $log = "shard_${i}.log"
  567. if (Test-Path $log) {
  568. $failedLines = Select-String -Path $log -Pattern "\[ FAILED \]"
  569. if ($failedLines) {
  570. $summary += "**Shard ${i}:**`n" + (($failedLines | ForEach-Object { $_.Line }) -join "`n") + "`n`n"
  571. }
  572. }
  573. }
  574. if (-not $summary) {
  575. $summary = "_Could not extract failed test name from shard logs; see the run for details._`n`n"
  576. }
  577. $runUrl = "$($env:GITHUB_SERVER_URL)/$($env:GITHUB_REPOSITORY)/actions/runs/$($env:GITHUB_RUN_ID)"
  578. $body = "Reoccurred on push: $runUrl`n`nCommit: $($env:GITHUB_SHA)`n`n$summary"
  579. gh issue comment 2533 --repo $env:GITHUB_REPOSITORY --body $body
  580. env:
  581. VCPKG_ROOT: "C:/vcpkg"
  582. VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"