Skip to content

Commit 36e174d

Browse files
authored
Merge pull request #72 from sir-gon/develop
[CONFIG] [Github Actions] build / test environments splitted by OS.
2 parents af55920 + 86275d4 commit 36e174d

File tree

10 files changed

+177
-22
lines changed

10 files changed

+177
-22
lines changed

.github/workflows/cpp.yml renamed to .github/workflows/cpp-linux.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
2-
3-
name: C/C++ CMake CI Test
2+
name: C/C++ CMake/GNU Linux CI Test
43

54
on: # yamllint disable-line rule:truthy
65
push:
@@ -11,13 +10,11 @@ on: # yamllint disable-line rule:truthy
1110
workflow_dispatch:
1211

1312
jobs:
14-
build:
13+
test:
1514
name: C/C++ CMake CI Test
1615
strategy:
1716
matrix:
18-
os: ["ubuntu-24.04", "macos-14"
19-
# , "windows-2022"
20-
]
17+
os: ["ubuntu-24.04"]
2118
runs-on: ${{ matrix.os }}
2219

2320
steps:

.github/workflows/cpp-macos.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
name: C/C++ CMake/LLVM MacOS CI Test
3+
4+
on: # yamllint disable-line rule:truthy
5+
push:
6+
branches: ["main"]
7+
pull_request:
8+
# The branches below must be a subset of the branches above
9+
branches: ["main"]
10+
workflow_dispatch:
11+
12+
jobs:
13+
test:
14+
name: C/C++ CMake CI Test
15+
strategy:
16+
matrix:
17+
os: ["macos-14"]
18+
runs-on: ${{ matrix.os }}
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
23+
24+
- name: Install
25+
shell: bash
26+
run: |
27+
if [ "$RUNNER_OS" == "macOS" ]; then
28+
brew install vcpkg
29+
git clone https://github.com/microsoft/vcpkg "$HOME/vcpkg"
30+
export VCPKG_ROOT="$HOME/vcpkg"
31+
echo "VCPKG_ROOT=$HOME/vcpkg" >> $GITHUB_ENV
32+
elif [ "$RUNNER_OS" == "Linux" ]; then
33+
echo "VCPKG_ROOT=/usr/local/share/vcpkg" >> $GITHUB_ENV
34+
elif [ "$RUNNER_OS" == "Windows" ]; then
35+
echo "VCPKG_ROOT=C:/vcpkg" >> $GITHUB_ENV
36+
fi
37+
38+
- name: Check Tools
39+
run: |
40+
echo "-----------"
41+
make --version
42+
echo "-----------"
43+
cmake --version
44+
echo "-----------"
45+
vcpkg --version
46+
echo "-----------"
47+
48+
- name: Install dependencies
49+
run: |
50+
make dependencies
51+
52+
- name: Build
53+
run: |
54+
make build
55+
56+
- name: Test
57+
run: |
58+
make test

.github/workflows/cpp-windows.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
name: C/C++ CMake/MSVC Windows CI Test
3+
4+
on: # yamllint disable-line rule:truthy
5+
push:
6+
branches: ["main"]
7+
pull_request:
8+
# The branches below must be a subset of the branches above
9+
branches: ["main"]
10+
workflow_dispatch:
11+
12+
jobs:
13+
test:
14+
name: C/C++ CMake CI Test
15+
strategy:
16+
matrix:
17+
os: ["windows-2022"]
18+
arch:
19+
- amd64
20+
- amd64_x86
21+
# - amd64_arm64
22+
23+
runs-on: ${{ matrix.os }}
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
28+
29+
- name: Install
30+
shell: bash
31+
run: |
32+
if [ "$RUNNER_OS" == "macOS" ]; then
33+
brew install vcpkg
34+
git clone https://github.com/microsoft/vcpkg "$HOME/vcpkg"
35+
export VCPKG_ROOT="$HOME/vcpkg"
36+
echo "VCPKG_ROOT=$HOME/vcpkg" >> $GITHUB_ENV
37+
elif [ "$RUNNER_OS" == "Linux" ]; then
38+
echo "VCPKG_ROOT=/usr/local/share/vcpkg" >> $GITHUB_ENV
39+
elif [ "$RUNNER_OS" == "Windows" ]; then
40+
echo "VCPKG_ROOT=C:/vcpkg" >> $GITHUB_ENV
41+
fi
42+
43+
- name: Check Tools
44+
run: |
45+
echo "-----------"
46+
make --version
47+
echo "-----------"
48+
cmake --version
49+
echo "-----------"
50+
vcpkg --version
51+
echo "-----------"
52+
53+
- uses: ilammy/msvc-dev-cmd@v1
54+
with:
55+
arch: ${{ matrix.arch }}
56+
57+
- name: Install dependencies
58+
run: |
59+
vcpkg --x-wait-for-lock integrate install
60+
vcpkg --x-wait-for-lock install
61+
62+
- name: Pre Build
63+
run: >
64+
cmake.exe
65+
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
66+
-DCMAKE_BUILD_TYPE=Debug
67+
-DCMAKE_C_COMPILER=cl
68+
-DCMAKE_CXX_COMPILER=cl
69+
-S${{ github.workspace }}
70+
-B${{ github.workspace }}/build/default -G "MinGW Makefiles"
71+
72+
- name: Build
73+
run: |
74+
cmake --build build/default
75+
76+
- name: Test
77+
run: >
78+
ctest
79+
-C Debug
80+
-T test
81+
--rerun-failed
82+
--output-on-failure
83+
--test-dir ${{ github.workspace }}/build/default

CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,25 @@ list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
1010
# This must be in the top-level CMakeLists.txt to enable CMake/CTest support.
1111
include(CTest)
1212

13+
set(CMAKE_C_STANDARD 11)
14+
set(CMAKE_C_STANDARD_REQUIRED ON)
1315
set(CMAKE_CXX_STANDARD 17)
1416
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1517
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1618

1719
SET(GCC_COVERAGE_COMPILE_FLAGS "-fsanitize=address -fprofile-arcs -ftest-coverage -g -O0")
1820
SET(GCC_COVERAGE_LINK_FLAGS "--coverage")
19-
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
20-
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
21+
22+
if (CMAKE_GENERATOR MATCHES "Unix Makefiles")
23+
24+
SET(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
25+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
26+
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
27+
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
28+
29+
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
30+
31+
endif ()
2132

2233
add_subdirectory(src/lib/exercises)
2334

CMakePresets.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010
},
1111
"generator": "Unix Makefiles",
1212
"binaryDir": "${sourceDir}/build/default"
13+
},
14+
{
15+
"name": "windows",
16+
"cacheVariables": {
17+
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
18+
"CMAKE_BUILD_TYPE": "Debug",
19+
"CMAKE_C_COMPILER": "cl",
20+
"CMAKE_CXX_COMPILER": "cl"
21+
},
22+
"generator": "MinGW Makefiles",
23+
"binaryDir": "${sourceDir}/build/default"
1324
}
1425
]
1526
}

src/lib/exercises/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
file (GLOB_RECURSE SOURCES "src/*.cpp")
1+
file (GLOB_RECURSE SOURCES "src/*.c" "src/*.cpp")
22
add_library(exercises STATIC ${SOURCES})
33

44
target_include_directories(exercises
@@ -7,11 +7,6 @@ target_include_directories(exercises
77
$<INSTALL_INTERFACE:include>
88
)
99

10-
target_compile_options(exercises
11-
PUBLIC
12-
-save-temps
13-
)
14-
1510
install(TARGETS exercises
1611
EXPORT exercisesConfig
1712
ARCHIVE DESTINATION lib

src/lib/exercises/include/exercises/hackerrank/warmup/a_very_big_sum.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#pragma once
44

55
namespace hackerrank::warmup {
6-
long aVeryBigSum(const std::vector<long> &ar);
6+
long long aVeryBigSum(const std::vector<long> &ar);
77
}

src/lib/exercises/src/hackerrank/warmup/a_very_big_sum.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
namespace hackerrank::warmup {
1111

12-
long aVeryBigSum(const std::vector<long> &ar) {
13-
const long INIT_VALUE = 0L;
12+
long long aVeryBigSum(const std::vector<long> &ar) {
13+
const long long INIT_VALUE = 0L;
1414
return std::accumulate(ar.begin(), ar.end(), INIT_VALUE);
1515
}
1616

src/lib/exercises/src/hackerrank/warmup/mini_max_sum.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ std::string miniMaxSumCalculate(const std::vector<int> &arr) {
1717
throw std::invalid_argument("List too short. Pass at least 2 elements.");
1818
}
1919

20-
long tsum = 0;
21-
long tmin = arr[0];
22-
long tmax = arr[1];
20+
long long tsum = 0;
21+
long long tmin = arr[0];
22+
long long tmax = arr[1];
2323

2424
for (const int &value : arr) {
25-
auto cvalue = (long)value;
25+
auto cvalue = (long long)value;
2626
tsum += cvalue;
2727
tmin = std::min(tmin, cvalue);
2828
tmax = std::max(tmax, cvalue);

src/tests/unit/lib/hackerrank/warmup/a_very_big_sum.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ TEST_CASE("aVeryBigSum JSON Test Cases",
2222
json data = json::parse(f);
2323

2424
for (auto testcase : data) {
25-
long result = hackerrank::warmup::aVeryBigSum(testcase["input"]);
25+
long long result = hackerrank::warmup::aVeryBigSum(testcase["input"]);
2626
CHECK(result == testcase["expected"]);
2727
}
2828
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy