Skip to content
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
8 changes: 3 additions & 5 deletions .github/workflows/c.yml → .github/workflows/c-linux.yml
Original file line number Diff line number Diff line change
@@ -1,5 +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 @@ -10,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/c-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
78 changes: 78 additions & 0 deletions .github/workflows/c-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
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 --test-dir ${{ github.workspace }}/build/default
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(CMAKE_C_STANDARD 11)
set(CMAKE_C_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_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage -g -O0")
SET(GCC_COVERAGE_LINK_FLAGS "--coverage")
SET(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
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"
}
]
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Algorithm Exercises (C / GNU11)

[![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)
[![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)
[![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)
[![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)

[![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)
[![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)
[![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)
Expand Down Expand Up @@ -34,9 +37,6 @@ Developed with TDD.
[![CMake](https://img.shields.io/badge/CMake-%23008FBA.svg?style=for-the-badge&logo=cmake&logoColor=white)](https://cmake.org/)
[![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=for-the-badge&logo=docker&logoColor=white)](https://www.docker.com/)

> [!WARNING]
> Not supported on Windows yet.

Go to [Install and run](#install-and-run)

## What is this?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
extern "C" {
#endif

long HACKERRANK_WARMUP_aVeryBigSum(int ar_count, const long *ar);
long long HACKERRANK_WARMUP_aVeryBigSum(int ar_count, const long *ar);

#ifdef __cplusplus
} // extern "C"
Expand Down
4 changes: 2 additions & 2 deletions src/lib/exercises/src/hackerrank/warmup/a_very_big_sum.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* @link Problem definition [[docs/hackerrank/warmup/a_very_big_sum.md]]
*/

long HACKERRANK_WARMUP_aVeryBigSum(int ar_count, const long *ar) {
long total = 0;
long long HACKERRANK_WARMUP_aVeryBigSum(int ar_count, const long *ar) {
long long total = 0;

for (int i = 0; i < ar_count; i++) {
total += ar[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ TEST_CASE("aVeryBigSum JSON Test Cases",
std::vector<long> input_vector = testcase["input"];
const long *input_array = input_vector.data();

long result = HACKERRANK_WARMUP_aVeryBigSum(size, input_array);
long long result = HACKERRANK_WARMUP_aVeryBigSum(size, input_array);
CHECK(result == testcase["expected"]);
}
}