Skip to content

Commit

Permalink
Added CI build for macos
Browse files Browse the repository at this point in the history
Added Github Actions build for Linux, Windows and Mac
  • Loading branch information
jgaa committed Aug 17, 2024
1 parent b063b5a commit cb2b65f
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 42 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: CI

on:
push:
pull_request:
schedule:
- cron: '0 0 1 * *' # This line schedules the workflow to run at 00:00 on the first day of every month

defaults:
run:
shell: bash

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
compiler: gcc
- os: ubuntu-latest
compiler: clang
- os: windows-latest
compiler: msvc
- os: macos-latest
compiler:

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: true

- name: Cache
uses: actions/cache@v4
with:
path: |
~/vcpkg
~/vcpkg_installed
${{ env.HOME }}/.cache/vcpkg/archives
${{ env.XDG_CACHE_HOME }}/vcpkg/archives
${{ env.LOCALAPPDATA }}\vcpkg\archives
${{ env.APPDATA }}\vcpkg\archives
key: ${{ runner.os }}-${{ matrix.compiler }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('./vcpkg.json')}}
restore-keys: |
${{ runner.os }}-${{ env.BUILD_TYPE }}-
- name: Setup Cpp
uses: aminya/setup-cpp@v1
with:
compiler: ${{ matrix.compiler }}
vcvarsall: ${{ contains(matrix.os, 'windows') }}
cmake: true
ninja: true
vcpkg: true
cppcheck: false

- name: Install compiler for Macos
if: startsWith(matrix.os, 'macos')
run: |
brew install llvm
- name: Prepare the PATH
run: |
if [[ "${{ runner.os }}" == "Windows" ]]; then
echo "$env:USERPROFILE\vcpkg" >> $GITHUB_PATH
echo "$env:USERPROFILE\ninja" >> $GITHUB_PATH
else
echo "$HOME/vcpkg" >> $GITHUB_PATH
echo "$HOME/ninja" >> $GITHUB_PATH
fi
- name: Install dependencies
run: |
cp -v ci/vcpkg/vcpkg.json .
vcpkg install
- name: Build project
run: |
pushd ~
if [ -d build ]; then
echo "Build dir exists"
ls -la build
else
mkdir -v build
fi
cd build
pwd
set -x
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}
cmake --build .
popd
continue-on-error: true

- name: Dump diagnostics
if: failure()
run: |
cd ~/build
echo "---------------------------------"
cat build.ninja
echo "---------------------------------"
- name: Run Unit Tests
run: |
pushd ~/build
ctest -R UNITTESTS . -C Release
popd
21 changes: 10 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (DEFINED ENV{RESTC_CPP_VERSION})
endif()

if (NOT DEFINED RESTC_CPP_VERSION)
set(RESTC_CPP_VERSION 0.100.0)
set(RESTC_CPP_VERSION 0.101.0)
endif()

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

include(CheckCXXCompilerFlag)

check_cxx_compiler_flag("-std=c++20" COMPILER_SUPPORTS_CXX20)
check_cxx_compiler_flag("-std=c++17" COMPILER_SUPPORTS_CXX17)

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

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

if (WIN32)
include(cmake_scripts/pch.cmake)
ADD_MSVC_PRECOMPILED_HEADER(restc-cpp/restc-cpp.h src/pch.cpp ACTUAL_SOURCES)
set(SOURCES ${ACTUAL_SOURCES} src/pch.cpp ${HEADERS} ${RESFILES})
else()
set(SOURCES ${ACTUAL_SOURCES})
endif()
set(SOURCES ${ACTUAL_SOURCES})

add_library(${PROJECT_NAME} ${SOURCES})
set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_OUTPUT_NAME restc-cppD)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![CI](https://github.com/jgaa/restc-cpp/actions/workflows/ci.yaml/badge.svg)](https://github.com/jgaa/restc-cpp/actions/workflows/ci.yaml)

# Introduction to the restc-cpp C++ library
<i>The magic that takes the pain out of accessing JSON API's from C++ </i>

Expand Down
62 changes: 31 additions & 31 deletions ci/jenkins/Jenkinsfile.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pipeline {
agent { label 'main' }

environment {
RESTC_CPP_VERSION = "0.100.0"
RESTC_CPP_VERSION = "0.101.0"

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

stage('macOS') {
agent {label 'macos'}

// environment {
// CPPFLAGS = "-I/usr/local/opt/openssl/include -I/usr/local/opt/zlib/include -I/usr/local/opt/boost/include/"
// LDFLAGS = "-L/usr/local/opt/openssl/lib -L/usr/local/opt/zlib/lib -L/usr/local/opt/boost/lib/"
// }

steps {
echo "Building on macos in ${WORKSPACE}"
sh 'brew install openssl boost zlib rapidjson googletest cmake ninja'
checkout scm
sh 'pwd; ls -la'
sh 'rm -rf build'
sh 'mkdir build'
sh 'cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make -j4'

echo 'Getting ready to run tests'
script {
try {
sh 'cd build && ctest --no-compress-output -T Test'
} catch (exc) {
echo 'Testing failed'
currentBuild.result = 'UNSTABLE'
}
}
}
}

stage('Ubuntu Noble') {
agent {
dockerfile {
Expand Down Expand Up @@ -530,36 +559,7 @@ pipeline {
sh 'rm -rf build-fedora'
}
}
//
// stage('Centos7') {
// agent {
// dockerfile {
// filename 'Dockerfile.centos7'
// dir 'ci/jenkins'
// label 'docker'
// }
// }
//
// steps {
// echo "Building on Centos7 in ${WORKSPACE}"
// checkout scm
// sh 'pwd; ls -la'
// sh 'rm -rf build'
// sh 'mkdir build'
// sh 'cd build && source scl_source enable devtoolset-7 && cmake -DCMAKE_BUILD_TYPE=Release -DBOOST_ROOT=/opt/boost .. && make'
//
// echo 'Getting ready to run tests'
// script {
// try {
// sh 'cd build && ctest --no-compress-output -T Test'
// } catch (exc) {
//
// unstable(message: "${STAGE_NAME} - Testing failed")
// }
// }
// }
// }


stage('Windows X64 with vcpkg') {

agent {label 'windows'}
Expand Down
22 changes: 22 additions & 0 deletions ci/vcpkg/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "restc-cpp",
"license": "MIT",
"dependencies": [
"boost-scope-exit",
"boost-system",
"boost-context",
"boost-coroutine",
"boost-filesystem",
"boost-asio",
"boost-chrono",
"boost-date-time",
"boost-log",
"boost-uuid",
"boost-program-options",
"boost-functional",
"zlib",
"openssl",
"gtest",
"rapidjson"
]
}
2 changes: 2 additions & 0 deletions tests/unit/HttpReplyTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ TEST(HttpReply, SimpleHeader)
EXPECT_EQ("0", *reply.GetHeader("Content-Length"));

});

EXPECT_NO_THROW(f.get());
}

TEST(HttpReply, SimpleSegmentedHeader)
Expand Down

0 comments on commit cb2b65f

Please sign in to comment.