Skip to content

[CONFIG] [Github Actions] build / test environments splitted by OS. #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .github/workflows/cpp.yml → .github/workflows/cpp-linux.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---

name: C/C++ CMake CI Test
name: C/C++ CMake/GNU Linux CI Test

on: # yamllint disable-line rule:truthy
push:
Expand All @@ -11,13 +10,11 @@ on: # yamllint disable-line rule:truthy
workflow_dispatch:

jobs:
build:
test:
name: C/C++ CMake CI Test
strategy:
matrix:
os: ["ubuntu-24.04", "macos-14"
# , "windows-2022"
]
os: ["ubuntu-24.04"]
runs-on: ${{ matrix.os }}

steps:
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/cpp-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
name: C/C++ CMake/LLVM MacOS CI Test

on: # yamllint disable-line rule:truthy
push:
branches: ["main"]
pull_request:
# The branches below must be a subset of the branches above
branches: ["main"]
workflow_dispatch:

jobs:
test:
name: C/C++ CMake CI Test
strategy:
matrix:
os: ["macos-14"]
runs-on: ${{ matrix.os }}

steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Install
shell: bash
run: |
if [ "$RUNNER_OS" == "macOS" ]; then
brew install vcpkg
git clone https://github.com/microsoft/vcpkg "$HOME/vcpkg"
export VCPKG_ROOT="$HOME/vcpkg"
echo "VCPKG_ROOT=$HOME/vcpkg" >> $GITHUB_ENV
elif [ "$RUNNER_OS" == "Linux" ]; then
echo "VCPKG_ROOT=/usr/local/share/vcpkg" >> $GITHUB_ENV
elif [ "$RUNNER_OS" == "Windows" ]; then
echo "VCPKG_ROOT=C:/vcpkg" >> $GITHUB_ENV
fi

- name: Check Tools
run: |
echo "-----------"
make --version
echo "-----------"
cmake --version
echo "-----------"
vcpkg --version
echo "-----------"

- name: Install dependencies
run: |
make dependencies

- name: Build
run: |
make build

- name: Test
run: |
make test
83 changes: 83 additions & 0 deletions .github/workflows/cpp-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
name: C/C++ CMake/MSVC Windows CI Test

on: # yamllint disable-line rule:truthy
push:
branches: ["main"]
pull_request:
# The branches below must be a subset of the branches above
branches: ["main"]
workflow_dispatch:

jobs:
test:
name: C/C++ CMake CI Test
strategy:
matrix:
os: ["windows-2022"]
arch:
- amd64
- amd64_x86
# - amd64_arm64

runs-on: ${{ matrix.os }}

steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Install
shell: bash
run: |
if [ "$RUNNER_OS" == "macOS" ]; then
brew install vcpkg
git clone https://github.com/microsoft/vcpkg "$HOME/vcpkg"
export VCPKG_ROOT="$HOME/vcpkg"
echo "VCPKG_ROOT=$HOME/vcpkg" >> $GITHUB_ENV
elif [ "$RUNNER_OS" == "Linux" ]; then
echo "VCPKG_ROOT=/usr/local/share/vcpkg" >> $GITHUB_ENV
elif [ "$RUNNER_OS" == "Windows" ]; then
echo "VCPKG_ROOT=C:/vcpkg" >> $GITHUB_ENV
fi

- name: Check Tools
run: |
echo "-----------"
make --version
echo "-----------"
cmake --version
echo "-----------"
vcpkg --version
echo "-----------"

- uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.arch }}

- name: Install dependencies
run: |
vcpkg --x-wait-for-lock integrate install
vcpkg --x-wait-for-lock install

- name: Pre Build
run: >
cmake.exe
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_C_COMPILER=cl
-DCMAKE_CXX_COMPILER=cl
-S${{ github.workspace }}
-B${{ github.workspace }}/build/default -G "MinGW Makefiles"

- name: Build
run: |
cmake --build build/default

- name: Test
run: >
ctest
-C Debug
-T test
--rerun-failed
--output-on-failure
--test-dir ${{ github.workspace }}/build/default
15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,25 @@ list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
# This must be in the top-level CMakeLists.txt to enable CMake/CTest support.
include(CTest)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

SET(GCC_COVERAGE_COMPILE_FLAGS "-fsanitize=address -fprofile-arcs -ftest-coverage -g -O0")
SET(GCC_COVERAGE_LINK_FLAGS "--coverage")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")

if (CMAKE_GENERATOR MATCHES "Unix Makefiles")

SET(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")

SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")

endif ()

add_subdirectory(src/lib/exercises)

Expand Down
11 changes: 11 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
},
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/build/default"
},
{
"name": "windows",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl"
},
"generator": "MinGW Makefiles",
"binaryDir": "${sourceDir}/build/default"
}
]
}
7 changes: 1 addition & 6 deletions src/lib/exercises/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
file (GLOB_RECURSE SOURCES "src/*.cpp")
file (GLOB_RECURSE SOURCES "src/*.c" "src/*.cpp")
add_library(exercises STATIC ${SOURCES})

target_include_directories(exercises
Expand All @@ -7,11 +7,6 @@ target_include_directories(exercises
$<INSTALL_INTERFACE:include>
)

target_compile_options(exercises
PUBLIC
-save-temps
)

install(TARGETS exercises
EXPORT exercisesConfig
ARCHIVE DESTINATION lib
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#pragma once

namespace hackerrank::warmup {
long aVeryBigSum(const std::vector<long> &ar);
long long aVeryBigSum(const std::vector<long> &ar);
}
4 changes: 2 additions & 2 deletions src/lib/exercises/src/hackerrank/warmup/a_very_big_sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

namespace hackerrank::warmup {

long aVeryBigSum(const std::vector<long> &ar) {
const long INIT_VALUE = 0L;
long long aVeryBigSum(const std::vector<long> &ar) {
const long long INIT_VALUE = 0L;
return std::accumulate(ar.begin(), ar.end(), INIT_VALUE);
}

Expand Down
8 changes: 4 additions & 4 deletions src/lib/exercises/src/hackerrank/warmup/mini_max_sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ std::string miniMaxSumCalculate(const std::vector<int> &arr) {
throw std::invalid_argument("List too short. Pass at least 2 elements.");
}

long tsum = 0;
long tmin = arr[0];
long tmax = arr[1];
long long tsum = 0;
long long tmin = arr[0];
long long tmax = arr[1];

for (const int &value : arr) {
auto cvalue = (long)value;
auto cvalue = (long long)value;
tsum += cvalue;
tmin = std::min(tmin, cvalue);
tmax = std::max(tmax, cvalue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ TEST_CASE("aVeryBigSum JSON Test Cases",
json data = json::parse(f);

for (auto testcase : data) {
long result = hackerrank::warmup::aVeryBigSum(testcase["input"]);
long long result = hackerrank::warmup::aVeryBigSum(testcase["input"]);
CHECK(result == testcase["expected"]);
}
}