diff --git a/.github/workflows/cpp-kowalski-test.yml b/.github/workflows/cpp-kowalski-test.yml new file mode 100644 index 0000000..f1aa8fb --- /dev/null +++ b/.github/workflows/cpp-kowalski-test.yml @@ -0,0 +1,50 @@ +name: cpp-kowalski-test + +on: + push: + branches: [main] + paths: ['cpp/kowalski/**'] + pull_request: + branches: ['**'] + paths: ['cpp/kowalski/**'] + +jobs: + cpp-kowalski-test: + runs-on: ubuntu-latest + + defaults: + run: + working-directory: cpp/kowalski + + steps: + - name: checkout code + uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Setup Cpp + uses: aminya/setup-cpp@v1 + with: + compiler: llvm + vcvarsall: true + clangtidy: true + clangformat: true + cmake: true + ninja: true + + - name: configure + run: cmake -S . -B ./build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + + - name: build + run: cmake --build ./build + + - name: test + run: ctest --test-dir ./build --output-on-failure + + - name: lint + run: | + find . -name '*.cc' -not -path './build/*' | xargs clang-tidy -p build/ + + - name: format check + run: | + find . \( -name '*.cc' -o -name '*.h' \) -not -path './build/*' | xargs clang-format --dry-run --Werror diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..9d5d29e --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,8 @@ +repos: + - repo: https://github.com/pocc/pre-commit-hooks + rev: v1.3.5 + hooks: + - id: clang-tidy + args: [-p=cpp/kowalski/build] + - id: clang-format + args: [-i] diff --git a/src/cpp/README.md b/cpp/README.md similarity index 100% rename from src/cpp/README.md rename to cpp/README.md diff --git a/cpp/kowalski/.clang-tidy b/cpp/kowalski/.clang-tidy new file mode 100644 index 0000000..74b8e6e --- /dev/null +++ b/cpp/kowalski/.clang-tidy @@ -0,0 +1,15 @@ +Checks: > + bugprone-*, + clang-analyzer-*, + cppcoreguidelines-*, + modernize-*, + performance-*, + portability-*, + readability-*, + -modernize-use-trailing-return-type, + -readability-magic-numbers, + -cppcoreguidelines-avoid-magic-numbers + +WarningsAsErrors: '' +HeaderFilterRegex: '.*' +FormatStyle: file diff --git a/cpp/kowalski/CMakeLists.txt b/cpp/kowalski/CMakeLists.txt new file mode 100644 index 0000000..365a7e8 --- /dev/null +++ b/cpp/kowalski/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.23) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +project(entropylex-kowalski LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + + +include(FetchContent) + +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip +) + +# For Windows: Prevent overriding the parent project's compiler/linker settings +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) +enable_testing() + +add_executable(main.test tests/main.test.cc) +target_link_libraries( + main.test + GTest::gtest_main +) + +include(GoogleTest) +gtest_discover_tests(main.test) + +add_executable(entropylex + main.cc + entropylex8.h +) diff --git a/cpp/kowalski/entropylex8.h b/cpp/kowalski/entropylex8.h new file mode 100644 index 0000000..36e795c --- /dev/null +++ b/cpp/kowalski/entropylex8.h @@ -0,0 +1,11 @@ +#ifndef ENTROPYLEX8_H_ +#define ENTROPYLEX8_H_ +#include +#include + +struct EntropyLex8 { +public: + std::array lookup_; +}; + +#endif // ENTROPYLEX8_H_ diff --git a/cpp/kowalski/main.cc b/cpp/kowalski/main.cc new file mode 100644 index 0000000..eb79522 --- /dev/null +++ b/cpp/kowalski/main.cc @@ -0,0 +1,7 @@ +#include "entropylex8.h" +#include + +int main() { + std::cout << "EntropyLex starting...\n"; + return 0; +} diff --git a/cpp/kowalski/setup.md b/cpp/kowalski/setup.md new file mode 100644 index 0000000..8f104f0 --- /dev/null +++ b/cpp/kowalski/setup.md @@ -0,0 +1,40 @@ +# Setup + +## Build & Test + +```bash +cmake -S . -B ./build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON +cmake --build ./build +ctest --test-dir ./build --output-on-failure +``` + +## Lint & Format + +Requires `compile_commands.json` (generated above). + +```bash +# lint +find . -name '*.cc' -not -path './build/*' | xargs clang-tidy -p build/ + +# format check +find . \( -name '*.cc' -o -name '*.h' \) -not -path './build/*' | xargs clang-format --dry-run --Werror + +# format fix +find . \( -name '*.cc' -o -name '*.h' \) -not -path './build/*' | xargs clang-format -i +``` + +## Pre-commit Hook + +```bash +# requires python installed +pip install pre-commit +pre-commit install +``` + +Runs clang-tidy/clang-format on staged files at commit time. Build `./build` at least once first so `compile_commands.json` exists. + +Run against all files manually: +```bash +pre-commit run --all-files +``` + diff --git a/cpp/kowalski/tests/main.test.cc b/cpp/kowalski/tests/main.test.cc new file mode 100644 index 0000000..0fb924e --- /dev/null +++ b/cpp/kowalski/tests/main.test.cc @@ -0,0 +1,14 @@ +#ifndef CPP_KOWALSKI_TESTS_MAIN_TEST_CC_ +#define CPP_KOWALSKI_TESTS_MAIN_TEST_CC_ + +#include + +// Demonstrate some basic assertions. +TEST(HelloTest, BasicAssertions) { + // Expect two strings not to be equal. + EXPECT_STRNE("hello", "world"); + // Expect equality. + EXPECT_EQ(7 * 6, 42); +} + +#endif // CPP_KOWALSKI_TESTS_MAIN_TEST_CC_