Skip to content

Commit 4e444f2

Browse files
authored
Merge pull request #23 from sir-gon/develop
[CONFIG] [Github Actions] C/C++ for windows.
2 parents a99ebd3 + d549c07 commit 4e444f2

File tree

9 files changed

+159
-14
lines changed

9 files changed

+159
-14
lines changed

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

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

44
on: # yamllint disable-line rule:truthy
55
push:
@@ -10,13 +10,11 @@ on: # yamllint disable-line rule:truthy
1010
workflow_dispatch:
1111

1212
jobs:
13-
build:
13+
test:
1414
name: C/C++ CMake CI Test
1515
strategy:
1616
matrix:
17-
os: ["ubuntu-24.04", "macos-14"
18-
# , "windows-2022"
19-
]
17+
os: ["ubuntu-24.04"]
2018
runs-on: ${{ matrix.os }}
2119

2220
steps:

.github/workflows/c-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/c-windows.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 --test-dir ${{ github.workspace }}/build/default

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set(CMAKE_C_STANDARD 11)
1414
set(CMAKE_C_STANDARD_REQUIRED ON)
1515
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1616

17-
SET(GCC_COVERAGE_COMPILE_FLAGS "-fsanitize=address -fprofile-arcs -ftest-coverage -g -O0")
17+
SET(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage -g -O0")
1818
SET(GCC_COVERAGE_LINK_FLAGS "--coverage")
1919
SET(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
2020
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")

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
}

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Algorithm Exercises (C / GNU11)
22

3-
[![C/C++ CI](https://github.com/sir-gon/algorithm-exercises-c/actions/workflows/c.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-c/actions/workflows/c.yml)
3+
[![C/C++ CMake/GNU Linux CI Test](https://github.com/sir-gon/algorithm-exercises-c/actions/workflows/c-linux.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-c/actions/workflows/c-linux.yml)
4+
[![C/C++ CMake/LLVM MacOS CI Test](https://github.com/sir-gon/algorithm-exercises-c/actions/workflows/c-macos.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-c/actions/workflows/c-macos.yml)
5+
[![C/C++ CMake/MSVC Windows CI Test](https://github.com/sir-gon/algorithm-exercises-c/actions/workflows/c-windows.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-c/actions/workflows/c-windows.yml)
6+
47
[![CppCheck Lint](https://github.com/sir-gon/algorithm-exercises-c/actions/workflows/cppcheck.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-c/actions/workflows/cppcheck.yml)
58
[![Markdown Lint](https://github.com/sir-gon/algorithm-exercises-c/actions/workflows/markdown-lint.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-c/actions/workflows/markdown-lint.yml)
69
[![YAML lint](https://github.com/sir-gon/algorithm-exercises-c/actions/workflows/yamllint.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-c/actions/workflows/yamllint.yml)
@@ -34,9 +37,6 @@ Developed with TDD.
3437
[![CMake](https://img.shields.io/badge/CMake-%23008FBA.svg?style=for-the-badge&logo=cmake&logoColor=white)](https://cmake.org/)
3538
[![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=for-the-badge&logo=docker&logoColor=white)](https://www.docker.com/)
3639

37-
> [!WARNING]
38-
> Not supported on Windows yet.
39-
4040
Go to [Install and run](#install-and-run)
4141

4242
## What is this?

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
extern "C" {
55
#endif
66

7-
long HACKERRANK_WARMUP_aVeryBigSum(int ar_count, const long *ar);
7+
long long HACKERRANK_WARMUP_aVeryBigSum(int ar_count, const long *ar);
88

99
#ifdef __cplusplus
1010
} // extern "C"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* @link Problem definition [[docs/hackerrank/warmup/a_very_big_sum.md]]
55
*/
66

7-
long HACKERRANK_WARMUP_aVeryBigSum(int ar_count, const long *ar) {
8-
long total = 0;
7+
long long HACKERRANK_WARMUP_aVeryBigSum(int ar_count, const long *ar) {
8+
long long total = 0;
99

1010
for (int i = 0; i < ar_count; i++) {
1111
total += ar[i];

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
@@ -26,7 +26,7 @@ TEST_CASE("aVeryBigSum JSON Test Cases",
2626
std::vector<long> input_vector = testcase["input"];
2727
const long *input_array = input_vector.data();
2828

29-
long result = HACKERRANK_WARMUP_aVeryBigSum(size, input_array);
29+
long long result = HACKERRANK_WARMUP_aVeryBigSum(size, input_array);
3030
CHECK(result == testcase["expected"]);
3131
}
3232
}

0 commit comments

Comments
 (0)