From 32d7a518b2c3888052e1de2c164f04ec015f55f0 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Tue, 17 Dec 2024 15:02:40 -0300 Subject: [PATCH 1/3] [CONFIG] [Github Actions] C/C++ for windows. --- .github/workflows/c-windows.yml | 78 +++++++++++++++++++++++++++++++++ CMakeLists.txt | 2 +- CMakePresets.json | 11 +++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/c-windows.yml diff --git a/.github/workflows/c-windows.yml b/.github/workflows/c-windows.yml new file mode 100644 index 0000000..1aec910 --- /dev/null +++ b/.github/workflows/c-windows.yml @@ -0,0 +1,78 @@ +--- +name: C/C++ CMake 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/MSVC CI Test Windows + 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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 011afac..add57c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}") diff --git a/CMakePresets.json b/CMakePresets.json index 0fc602c..599d199 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -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" } ] } From a6073658180066bc759f8d31e4f2079c87ec5b2b Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Tue, 17 Dec 2024 15:03:59 -0300 Subject: [PATCH 2/3] [BUGFIX] [Hacker Rank]: Warmup: A Very Big Sum. Windows "long" type is not enough to store a very big result. --- .github/workflows/c-windows.yml | 2 +- .../include/exercises/hackerrank/warmup/a_very_big_sum.h | 2 +- src/lib/exercises/src/hackerrank/warmup/a_very_big_sum.c | 4 ++-- src/tests/unit/lib/hackerrank/warmup/a_very_big_sum.test.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/c-windows.yml b/.github/workflows/c-windows.yml index 1aec910..9e46388 100644 --- a/.github/workflows/c-windows.yml +++ b/.github/workflows/c-windows.yml @@ -18,7 +18,7 @@ jobs: arch: - amd64 - amd64_x86 - - amd64_arm64 + # - amd64_arm64 runs-on: ${{ matrix.os }} diff --git a/src/lib/exercises/include/exercises/hackerrank/warmup/a_very_big_sum.h b/src/lib/exercises/include/exercises/hackerrank/warmup/a_very_big_sum.h index 0f36726..6a9d1dc 100644 --- a/src/lib/exercises/include/exercises/hackerrank/warmup/a_very_big_sum.h +++ b/src/lib/exercises/include/exercises/hackerrank/warmup/a_very_big_sum.h @@ -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" diff --git a/src/lib/exercises/src/hackerrank/warmup/a_very_big_sum.c b/src/lib/exercises/src/hackerrank/warmup/a_very_big_sum.c index 821109e..1ef9130 100644 --- a/src/lib/exercises/src/hackerrank/warmup/a_very_big_sum.c +++ b/src/lib/exercises/src/hackerrank/warmup/a_very_big_sum.c @@ -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]; diff --git a/src/tests/unit/lib/hackerrank/warmup/a_very_big_sum.test.cpp b/src/tests/unit/lib/hackerrank/warmup/a_very_big_sum.test.cpp index f90a329..63a9464 100644 --- a/src/tests/unit/lib/hackerrank/warmup/a_very_big_sum.test.cpp +++ b/src/tests/unit/lib/hackerrank/warmup/a_very_big_sum.test.cpp @@ -26,7 +26,7 @@ TEST_CASE("aVeryBigSum JSON Test Cases", std::vector 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"]); } } From d549c07470214ec442685f63a6df4de62096c730 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Tue, 17 Dec 2024 15:55:24 -0300 Subject: [PATCH 3/3] [CONFIG] [Github Actions] build / test environments splitted by OS. --- .github/workflows/{c.yml => c-linux.yml} | 8 ++-- .github/workflows/c-macos.yml | 58 ++++++++++++++++++++++++ .github/workflows/c-windows.yml | 4 +- README.md | 8 ++-- 4 files changed, 67 insertions(+), 11 deletions(-) rename .github/workflows/{c.yml => c-linux.yml} (92%) create mode 100644 .github/workflows/c-macos.yml diff --git a/.github/workflows/c.yml b/.github/workflows/c-linux.yml similarity index 92% rename from .github/workflows/c.yml rename to .github/workflows/c-linux.yml index 764e8df..f11ec39 100644 --- a/.github/workflows/c.yml +++ b/.github/workflows/c-linux.yml @@ -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: @@ -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: diff --git a/.github/workflows/c-macos.yml b/.github/workflows/c-macos.yml new file mode 100644 index 0000000..9b8193c --- /dev/null +++ b/.github/workflows/c-macos.yml @@ -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 diff --git a/.github/workflows/c-windows.yml b/.github/workflows/c-windows.yml index 9e46388..f1aa194 100644 --- a/.github/workflows/c-windows.yml +++ b/.github/workflows/c-windows.yml @@ -1,5 +1,5 @@ --- -name: C/C++ CMake CI Test +name: C/C++ CMake/MSVC Windows CI Test on: # yamllint disable-line rule:truthy push: @@ -11,7 +11,7 @@ on: # yamllint disable-line rule:truthy jobs: test: - name: C/C++ CMake/MSVC CI Test Windows + name: C/C++ CMake CI Test strategy: matrix: os: ["windows-2022"] diff --git a/README.md b/README.md index 2915fdc..f21b008 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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?