Skip to content

Commit b8e2cba

Browse files
committed
Merge remote-tracking branch 'origin/master' into pr/solarispika/2116
2 parents 06debee + 27ee115 commit b8e2cba

File tree

15 files changed

+3282
-511
lines changed

15 files changed

+3282
-511
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Release Docker Image
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
jobs:
9+
build-and-push:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0 # Fetch all history and tags
16+
17+
- name: Extract tag (manual)
18+
if: github.event_name == 'workflow_dispatch'
19+
id: set_tag_manual
20+
run: |
21+
# Checkout the latest tag and set output
22+
git fetch --tags
23+
LATEST_TAG=$(git describe --tags --abbrev=0)
24+
git checkout $LATEST_TAG
25+
echo "tag=${LATEST_TAG#v}" >> $GITHUB_OUTPUT
26+
27+
- name: Extract tag (release)
28+
if: github.event_name == 'release'
29+
id: set_tag_release
30+
run: echo "tag=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
35+
- name: Log in to Docker Hub
36+
uses: docker/login-action@v3
37+
with:
38+
username: ${{ secrets.DOCKERHUB_USERNAME }}
39+
password: ${{ secrets.DOCKERHUB_TOKEN }}
40+
41+
- name: Build and push Docker image
42+
uses: docker/build-push-action@v5
43+
with:
44+
context: .
45+
file: ./Dockerfile
46+
push: true
47+
platforms: linux/amd64,linux/arm64 # Build for both amd64 and arm64
48+
# Use extracted tag without leading 'v'
49+
tags: |
50+
yhirose4dockerhub/cpp-httplib-server:latest
51+
yhirose4dockerhub/cpp-httplib-server:${{ steps.set_tag_manual.outputs.tag || steps.set_tag_release.outputs.tag }}

.github/workflows/test.yaml

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
clang-format --version
4141
cd test && make style_check
4242
43-
ubuntu:
43+
build-error-check-on-32bit:
4444
runs-on: ubuntu-latest
4545
if: >
4646
(github.event_name == 'push') ||
@@ -53,10 +53,28 @@ jobs:
5353
- arch_flags: -m32
5454
arch_suffix: :i386
5555
name: (32-bit)
56-
- arch_flags:
57-
arch_suffix:
58-
name: (64-bit)
59-
name: ubuntu ${{ matrix.config.name }}
56+
steps:
57+
- name: checkout
58+
uses: actions/checkout@v4
59+
- name: install libraries
60+
run: |
61+
sudo dpkg --add-architecture i386
62+
sudo apt-get update
63+
sudo apt-get install -y libc6-dev${{ matrix.config.arch_suffix }} libstdc++-13-dev${{ matrix.config.arch_suffix }} \
64+
libssl-dev${{ matrix.config.arch_suffix }} libcurl4-openssl-dev${{ matrix.config.arch_suffix }} \
65+
zlib1g-dev${{ matrix.config.arch_suffix }} libbrotli-dev${{ matrix.config.arch_suffix }} \
66+
libzstd-dev${{ matrix.config.arch_suffix }}
67+
- name: build and run tests (expect failure)
68+
run: cd test && make test EXTRA_CXXFLAGS="${{ matrix.config.arch_flags }}"
69+
continue-on-error: true
70+
71+
ubuntu:
72+
runs-on: ubuntu-latest
73+
if: >
74+
(github.event_name == 'push') ||
75+
(github.event_name == 'pull_request' &&
76+
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
77+
(github.event_name == 'workflow_dispatch' && github.event.inputs.test_linux == 'true')
6078
steps:
6179
- name: checkout
6280
uses: actions/checkout@v4

.gitignore

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
tags
22

3+
# Ignore executables (no extension) but not source files
34
example/server
5+
!example/server.*
46
example/client
7+
!example/client.*
58
example/hello
9+
!example/hello.*
610
example/simplecli
11+
!example/simplecli.*
712
example/simplesvr
13+
!example/simplesvr.*
814
example/benchmark
15+
!example/benchmark.*
916
example/redirect
10-
example/sse*
17+
!example/redirect.*
18+
example/ssecli
19+
example/ssesvr
1120
example/upload
21+
!example/upload.*
1222
example/one_time_request
23+
!example/one_time_request.*
1324
example/server_and_client
25+
!example/server_and_client.*
26+
example/accept_header
27+
!example/accept_header.*
1428
example/*.pem
1529
test/httplib.cc
1630
test/httplib.h

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/mirrors-clang-format
3+
rev: v18.1.8 # 最新バージョンを使用
4+
hooks:
5+
- id: clang-format
6+
files: \.(cpp|cc|h)$
7+
args: [-i] # インプレースで修正

CMakeLists.txt

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[[
22
Build options:
3-
* BUILD_SHARED_LIBS (default off) builds as a shared library (if HTTPLIB_COMPILE is ON)
3+
* Standard BUILD_SHARED_LIBS is supported and sets HTTPLIB_SHARED default value.
44
* HTTPLIB_USE_OPENSSL_IF_AVAILABLE (default on)
55
* HTTPLIB_USE_ZLIB_IF_AVAILABLE (default on)
66
* HTTPLIB_USE_BROTLI_IF_AVAILABLE (default on)
@@ -14,6 +14,7 @@
1414
* HTTPLIB_USE_WINDOWS_AUTOMATIC_ROOT_CERTIFICATES_UPDATE (default on)
1515
* HTTPLIB_COMPILE (default off)
1616
* HTTPLIB_INSTALL (default on)
17+
* HTTPLIB_SHARED (default off) builds as a shared library (if HTTPLIB_COMPILE is ON)
1718
* HTTPLIB_TEST (default off)
1819
* BROTLI_USE_STATIC_LIBS - tells Cmake to use the static Brotli libs (only works if you have them installed).
1920
* OPENSSL_USE_STATIC_LIBS - tells Cmake to use the static OpenSSL libs (only works if you have them installed).
@@ -111,12 +112,34 @@ option(HTTPLIB_USE_NON_BLOCKING_GETADDRINFO "Enables the non-blocking alternativ
111112
option(HTTPLIB_REQUIRE_ZSTD "Requires ZSTD to be found & linked, or fails build." OFF)
112113
option(HTTPLIB_USE_ZSTD_IF_AVAILABLE "Uses ZSTD (if available) to enable zstd support." ON)
113114
option(HTTPLIB_USE_WINDOWS_AUTOMATIC_ROOT_CERTIFICATES_UPDATE "Enable automatic root certificates update on Windows." ON)
114-
# Defaults to static library
115-
option(BUILD_SHARED_LIBS "Build the library as a shared library instead of static. Has no effect if using header-only." OFF)
116-
if (BUILD_SHARED_LIBS AND WIN32 AND HTTPLIB_COMPILE)
117-
# Necessary for Windows if building shared libs
118-
# See https://stackoverflow.com/a/40743080
119-
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
115+
# Defaults to static library but respects standard BUILD_SHARED_LIBS if set
116+
include(CMakeDependentOption)
117+
cmake_dependent_option(HTTPLIB_SHARED "Build the library as a shared library instead of static. Has no effect if using header-only."
118+
"${BUILD_SHARED_LIBS}" HTTPLIB_COMPILE OFF
119+
)
120+
if(HTTPLIB_SHARED)
121+
set(HTTPLIB_LIB_TYPE SHARED)
122+
if(WIN32)
123+
# Necessary for Windows if building shared libs
124+
# See https://stackoverflow.com/a/40743080
125+
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
126+
endif()
127+
else()
128+
set(HTTPLIB_LIB_TYPE STATIC)
129+
endif()
130+
131+
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
132+
if(CMAKE_SYSTEM_VERSION)
133+
if(${CMAKE_SYSTEM_VERSION} VERSION_LESS "10.0.0")
134+
message(SEND_ERROR "Windows ${CMAKE_SYSTEM_VERSION} or lower is not supported. Please use Windows 10 or later.")
135+
endif()
136+
else()
137+
set(CMAKE_SYSTEM_VERSION "10.0.19041.0")
138+
message(WARNING "The target is Windows but CMAKE_SYSTEM_VERSION is not set, the default system version is set to Windows 10.")
139+
endif()
140+
endif()
141+
if(CMAKE_SIZEOF_VOID_P LESS 8)
142+
message(WARNING "Pointer size ${CMAKE_SIZEOF_VOID_P} is not supported. Please use a 64-bit compiler.")
120143
endif()
121144

122145
# Set some variables that are used in-tree and while building based on our options
@@ -218,8 +241,7 @@ if(HTTPLIB_COMPILE)
218241

219242
# split.py puts output in "out"
220243
set(_httplib_build_includedir "${CMAKE_CURRENT_BINARY_DIR}/out")
221-
# This will automatically be either static or shared based on the value of BUILD_SHARED_LIBS
222-
add_library(${PROJECT_NAME} "${_httplib_build_includedir}/httplib.cc")
244+
add_library(${PROJECT_NAME} ${HTTPLIB_LIB_TYPE} "${_httplib_build_includedir}/httplib.cc")
223245
target_sources(${PROJECT_NAME}
224246
PUBLIC
225247
$<BUILD_INTERFACE:${_httplib_build_includedir}/httplib.h>
@@ -245,8 +267,8 @@ add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
245267
target_compile_features(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC} cxx_std_11)
246268

247269
target_include_directories(${PROJECT_NAME} SYSTEM ${_INTERFACE_OR_PUBLIC}
248-
$<BUILD_INTERFACE:${_httplib_build_includedir}>
249-
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
270+
$<BUILD_INTERFACE:${_httplib_build_includedir}>
271+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
250272
)
251273

252274
# Always require threads
@@ -343,6 +365,6 @@ if(HTTPLIB_INSTALL)
343365
endif()
344366

345367
if(HTTPLIB_TEST)
346-
include(CTest)
347-
add_subdirectory(test)
368+
include(CTest)
369+
add_subdirectory(test)
348370
endif()

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ FROM scratch
88
COPY --from=builder /build/server /server
99
COPY docker/html/index.html /html/index.html
1010
EXPOSE 80
11-
CMD ["/server"]
11+
12+
ENTRYPOINT ["/server"]
13+
CMD ["--host", "0.0.0.0", "--port", "80", "--mount", "/:./html"]

0 commit comments

Comments
 (0)