Skip to content

Commit cb2b65f

Browse files
committed
Added CI build for macos
Added Github Actions build for Linux, Windows and Mac
1 parent b063b5a commit cb2b65f

File tree

6 files changed

+174
-42
lines changed

6 files changed

+174
-42
lines changed

.github/workflows/ci.yaml

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: '0 0 1 * *' # This line schedules the workflow to run at 00:00 on the first day of every month
8+
9+
defaults:
10+
run:
11+
shell: bash
12+
13+
jobs:
14+
build:
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
matrix:
18+
include:
19+
- os: ubuntu-latest
20+
compiler: gcc
21+
- os: ubuntu-latest
22+
compiler: clang
23+
- os: windows-latest
24+
compiler: msvc
25+
- os: macos-latest
26+
compiler:
27+
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
with:
32+
submodules: true
33+
34+
- name: Cache
35+
uses: actions/cache@v4
36+
with:
37+
path: |
38+
~/vcpkg
39+
~/vcpkg_installed
40+
${{ env.HOME }}/.cache/vcpkg/archives
41+
${{ env.XDG_CACHE_HOME }}/vcpkg/archives
42+
${{ env.LOCALAPPDATA }}\vcpkg\archives
43+
${{ env.APPDATA }}\vcpkg\archives
44+
key: ${{ runner.os }}-${{ matrix.compiler }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('./vcpkg.json')}}
45+
restore-keys: |
46+
${{ runner.os }}-${{ env.BUILD_TYPE }}-
47+
48+
- name: Setup Cpp
49+
uses: aminya/setup-cpp@v1
50+
with:
51+
compiler: ${{ matrix.compiler }}
52+
vcvarsall: ${{ contains(matrix.os, 'windows') }}
53+
cmake: true
54+
ninja: true
55+
vcpkg: true
56+
cppcheck: false
57+
58+
- name: Install compiler for Macos
59+
if: startsWith(matrix.os, 'macos')
60+
run: |
61+
brew install llvm
62+
63+
- name: Prepare the PATH
64+
run: |
65+
if [[ "${{ runner.os }}" == "Windows" ]]; then
66+
echo "$env:USERPROFILE\vcpkg" >> $GITHUB_PATH
67+
echo "$env:USERPROFILE\ninja" >> $GITHUB_PATH
68+
else
69+
echo "$HOME/vcpkg" >> $GITHUB_PATH
70+
echo "$HOME/ninja" >> $GITHUB_PATH
71+
fi
72+
73+
- name: Install dependencies
74+
run: |
75+
cp -v ci/vcpkg/vcpkg.json .
76+
vcpkg install
77+
78+
- name: Build project
79+
run: |
80+
pushd ~
81+
if [ -d build ]; then
82+
echo "Build dir exists"
83+
ls -la build
84+
else
85+
mkdir -v build
86+
fi
87+
cd build
88+
pwd
89+
set -x
90+
cmake -DVCPKG_INSTALLED_DIR=~/vcpkg_installed -DVCPKG_VERBOSE=ON -DRESTC_CPP_THREADED_CTX=ON -DCMAKE_BUILD_TYPE=Release -G "Ninja" -DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake ${GITHUB_WORKSPACE}
91+
cmake --build .
92+
popd
93+
continue-on-error: true
94+
95+
- name: Dump diagnostics
96+
if: failure()
97+
run: |
98+
cd ~/build
99+
echo "---------------------------------"
100+
cat build.ninja
101+
echo "---------------------------------"
102+
103+
- name: Run Unit Tests
104+
run: |
105+
pushd ~/build
106+
ctest -R UNITTESTS . -C Release
107+
popd

CMakeLists.txt

+10-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (DEFINED ENV{RESTC_CPP_VERSION})
1111
endif()
1212

1313
if (NOT DEFINED RESTC_CPP_VERSION)
14-
set(RESTC_CPP_VERSION 0.100.0)
14+
set(RESTC_CPP_VERSION 0.101.0)
1515
endif()
1616

1717
if(NOT DEFINED RESTC_BOOST_VERSION)
@@ -24,9 +24,14 @@ message(STATUS "Building restc-cpp version ${PROJECT_VERSION}")
2424

2525
include(CheckCXXCompilerFlag)
2626

27-
check_cxx_compiler_flag("-std=c++20" COMPILER_SUPPORTS_CXX20)
28-
check_cxx_compiler_flag("-std=c++17" COMPILER_SUPPORTS_CXX17)
29-
27+
if (MSVC)
28+
# Thank you Microsoft. Its so nice of you to give us all these meaningful reasons to stay up all night.
29+
check_cxx_compiler_flag("/std:c++20" COMPILER_SUPPORTS_CXX20)
30+
check_cxx_compiler_flag("/std:c++17" COMPILER_SUPPORTS_CXX17)
31+
else()
32+
check_cxx_compiler_flag("-std=c++20" COMPILER_SUPPORTS_CXX20)
33+
check_cxx_compiler_flag("-std=c++17" COMPILER_SUPPORTS_CXX17)
34+
endif()
3035

3136
if (NOT DEFINED INSTALL_RAPIDJSON_HEADERS)
3237
option(INSTALL_RAPIDJSON_HEADERS "Install rapidjson headers when make install is executed" ON)
@@ -229,13 +234,7 @@ if (RESTC_CPP_WITH_ZLIB)
229234
set(ACTUAL_SOURCES ${ACTUAL_SOURCES} src/ZipReaderImpl.cpp)
230235
endif()
231236

232-
if (WIN32)
233-
include(cmake_scripts/pch.cmake)
234-
ADD_MSVC_PRECOMPILED_HEADER(restc-cpp/restc-cpp.h src/pch.cpp ACTUAL_SOURCES)
235-
set(SOURCES ${ACTUAL_SOURCES} src/pch.cpp ${HEADERS} ${RESFILES})
236-
else()
237-
set(SOURCES ${ACTUAL_SOURCES})
238-
endif()
237+
set(SOURCES ${ACTUAL_SOURCES})
239238

240239
add_library(${PROJECT_NAME} ${SOURCES})
241240
set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_OUTPUT_NAME restc-cppD)

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![CI](https://github.com/jgaa/restc-cpp/actions/workflows/ci.yaml/badge.svg)](https://github.com/jgaa/restc-cpp/actions/workflows/ci.yaml)
2+
13
# Introduction to the restc-cpp C++ library
24
<i>The magic that takes the pain out of accessing JSON API's from C++ </i>
35

ci/jenkins/Jenkinsfile.groovy

+31-31
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pipeline {
44
agent { label 'main' }
55

66
environment {
7-
RESTC_CPP_VERSION = "0.100.0"
7+
RESTC_CPP_VERSION = "0.101.0"
88

99
// It is not possible to get the current IP number when running in the sandbox, and
1010
// Jenkinsfiles always runs in the sandbox.
@@ -24,6 +24,35 @@ pipeline {
2424
stage('Build') {
2525
parallel {
2626

27+
stage('macOS') {
28+
agent {label 'macos'}
29+
30+
// environment {
31+
// CPPFLAGS = "-I/usr/local/opt/openssl/include -I/usr/local/opt/zlib/include -I/usr/local/opt/boost/include/"
32+
// LDFLAGS = "-L/usr/local/opt/openssl/lib -L/usr/local/opt/zlib/lib -L/usr/local/opt/boost/lib/"
33+
// }
34+
35+
steps {
36+
echo "Building on macos in ${WORKSPACE}"
37+
sh 'brew install openssl boost zlib rapidjson googletest cmake ninja'
38+
checkout scm
39+
sh 'pwd; ls -la'
40+
sh 'rm -rf build'
41+
sh 'mkdir build'
42+
sh 'cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make -j4'
43+
44+
echo 'Getting ready to run tests'
45+
script {
46+
try {
47+
sh 'cd build && ctest --no-compress-output -T Test'
48+
} catch (exc) {
49+
echo 'Testing failed'
50+
currentBuild.result = 'UNSTABLE'
51+
}
52+
}
53+
}
54+
}
55+
2756
stage('Ubuntu Noble') {
2857
agent {
2958
dockerfile {
@@ -530,36 +559,7 @@ pipeline {
530559
sh 'rm -rf build-fedora'
531560
}
532561
}
533-
//
534-
// stage('Centos7') {
535-
// agent {
536-
// dockerfile {
537-
// filename 'Dockerfile.centos7'
538-
// dir 'ci/jenkins'
539-
// label 'docker'
540-
// }
541-
// }
542-
//
543-
// steps {
544-
// echo "Building on Centos7 in ${WORKSPACE}"
545-
// checkout scm
546-
// sh 'pwd; ls -la'
547-
// sh 'rm -rf build'
548-
// sh 'mkdir build'
549-
// sh 'cd build && source scl_source enable devtoolset-7 && cmake -DCMAKE_BUILD_TYPE=Release -DBOOST_ROOT=/opt/boost .. && make'
550-
//
551-
// echo 'Getting ready to run tests'
552-
// script {
553-
// try {
554-
// sh 'cd build && ctest --no-compress-output -T Test'
555-
// } catch (exc) {
556-
//
557-
// unstable(message: "${STAGE_NAME} - Testing failed")
558-
// }
559-
// }
560-
// }
561-
// }
562-
562+
563563
stage('Windows X64 with vcpkg') {
564564

565565
agent {label 'windows'}

ci/vcpkg/vcpkg.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "restc-cpp",
3+
"license": "MIT",
4+
"dependencies": [
5+
"boost-scope-exit",
6+
"boost-system",
7+
"boost-context",
8+
"boost-coroutine",
9+
"boost-filesystem",
10+
"boost-asio",
11+
"boost-chrono",
12+
"boost-date-time",
13+
"boost-log",
14+
"boost-uuid",
15+
"boost-program-options",
16+
"boost-functional",
17+
"zlib",
18+
"openssl",
19+
"gtest",
20+
"rapidjson"
21+
]
22+
}

tests/unit/HttpReplyTests.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ TEST(HttpReply, SimpleHeader)
102102
EXPECT_EQ("0", *reply.GetHeader("Content-Length"));
103103

104104
});
105+
106+
EXPECT_NO_THROW(f.get());
105107
}
106108

107109
TEST(HttpReply, SimpleSegmentedHeader)

0 commit comments

Comments
 (0)