diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..59d0684 --- /dev/null +++ b/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: Google +SortIncludes: Never diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..0241386 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,38 @@ +name: Linter + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths-ignore: + - '**.md' + - 'docs/**' + push: + branches: + - main + paths-ignore: + - '**.md' + - 'docs/**' + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Run clang-format + uses: jidicula/clang-format-action@c74383674bf5f7c69f60ce562019c1c94bc1421a # v4.13.0 + with: + clang-format-version: '17' + fallback-style: 'Google' + + - uses: chartboost/ruff-action@e18ae971ccee1b2d7bbef113930f00c670b78da4 # v1.0.0 + name: Lint with Ruff + with: + version: 0.5.1 diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml new file mode 100644 index 0000000..08d8cd2 --- /dev/null +++ b/.github/workflows/macos.yml @@ -0,0 +1,33 @@ +name: macos CI + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths-ignore: + - '**.md' + - 'docs/**' + push: + branches: + - main + paths-ignore: + - '**.md' + - 'docs/**' + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + ubuntu-build: + runs-on: macos-latest + steps: + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + - name: Prepare + run: cmake -B build + - name: Build + run: cmake --build build -j=2 + - name: Test + run: ctest --output-on-failure --test-dir build \ No newline at end of file diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml new file mode 100644 index 0000000..6b5c572 --- /dev/null +++ b/.github/workflows/ubuntu.yml @@ -0,0 +1,41 @@ +name: Ubuntu 24.04 CI + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths-ignore: + - '**.md' + - 'docs/**' + push: + branches: + - main + paths-ignore: + - '**.md' + - 'docs/**' + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + ubuntu-build: + runs-on: ubuntu-24.04 + strategy: + matrix: + shared: [ON, OFF] + cxx: [g++-14] + steps: + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + - name: Setup Ninja + run: sudo apt-get install ninja-build + - name: Prepare + run: cmake -DBUILD_SHARED_LIBS=${{matrix.shared}} -G Ninja -B build + env: + CXX: ${{matrix.cxx}} + - name: Build + run: cmake --build build -j=2 + - name: Test + run: ctest --output-on-failure --test-dir build diff --git a/.github/workflows/visual-studio.yml b/.github/workflows/visual-studio.yml new file mode 100644 index 0000000..34a5fe3 --- /dev/null +++ b/.github/workflows/visual-studio.yml @@ -0,0 +1,42 @@ +name: VS17 CI + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths-ignore: + - '**.md' + - 'docs/**' + push: + branches: + - main + paths-ignore: + - '**.md' + - 'docs/**' + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + ci: + name: windows-vs17 + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + include: + - {gen: Visual Studio 17 2022, arch: x64, config: Release} + - {gen: Visual Studio 17 2022, arch: x64, config: Debug} + steps: + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + - name: Configure + run: | + cmake -G "${{matrix.gen}}" -A ${{matrix.arch}} -B build + - name: Build + run: cmake --build build --config "${{matrix.config}}" --verbose + - name: Run tests + working-directory: build + run: ctest -C "${{matrix.config}}" --output-on-failure diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..13f15f0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +cmake-build-debug +build +.idea diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..e4fba21 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.12 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3e23ec7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,42 @@ +cmake_minimum_required(VERSION 3.28) +project(ncrypto) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED True) +if (NOT CMAKE_BUILD_TYPE) + message(STATUS "No build type selected, default to Release") + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) +endif() + +option(NCRYPTO_DEVELOPMENT_CHECKS "Enable development checks" OFF) + +include(GNUInstallDirs) +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) + +add_subdirectory(src) +enable_testing() +add_subdirectory(tests) + +install( + FILES include/ncrypto.h + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + COMPONENT ncrypto_development +) + +install( + TARGETS ncrypto + EXPORT ncrypto_targets + RUNTIME COMPONENT ncrypto_runtime + LIBRARY COMPONENT ncrypto_runtime + NAMELINK_COMPONENT ncrypto_development + ARCHIVE COMPONENT ncrypto_development + INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) diff --git a/include/ncrypto.h b/include/ncrypto.h new file mode 100644 index 0000000..e69de29 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..655257f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,38 @@ +[project] +name = "ncrypto" +requires-python = ">=3.12" + +[tool.ruff] +line-length = 120 +target-version = "py312" + +[tool.ruff.format] +quote-style = "single" +indent-style = "space" +docstring-code-format = true + +[tool.ruff.lint] +select = [ + "C90", # McCabe cyclomatic complexity + "E", # pycodestyle + "F", # Pyflakes + "ICN", # flake8-import-conventions + "INT", # flake8-gettext + "PLC", # Pylint conventions + "PLE", # Pylint errors + "PLR09", # Pylint refactoring: max-args, max-branches, max returns, max-statements + "PYI", # flake8-pyi + "RSE", # flake8-raise + "RUF", # Ruff-specific rules + "T10", # flake8-debugger + "TCH", # flake8-type-checking + "TID", # flake8-tidy-imports + "W", # pycodestyle + "YTT", # flake8-2020 + "ANN" # flake8-annotations +] +ignore = [ + "E722", # Do not use bare `except` + "ANN101", # Missing type annotation for self in method + "TID252", # Prefer absolute imports over relative imports from parent modules +] \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..0311ede --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,6 @@ +add_library(ncrypto ncrypto.cpp) +target_include_directories(ncrypto + PUBLIC + $ + $ +) diff --git a/src/ncrypto.cpp b/src/ncrypto.cpp new file mode 100644 index 0000000..e69de29 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..1625c8c --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,10 @@ +include(GoogleTest) +include(CTest) +add_executable(basic basic.cpp) +target_link_libraries( + basic + GTest::gtest_main +) +target_link_libraries(basic ncrypto) +add_test(basic_test basic) +gtest_discover_tests(basic) diff --git a/tests/basic.cpp b/tests/basic.cpp new file mode 100644 index 0000000..4172c5a --- /dev/null +++ b/tests/basic.cpp @@ -0,0 +1,5 @@ +#include + +#include + +TEST(basic, test_it) { SUCCEED(); } diff --git a/tools/run-clang-format.sh b/tools/run-clang-format.sh new file mode 100755 index 0000000..ce1a664 --- /dev/null +++ b/tools/run-clang-format.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +# Copyright 2023 Yagiz Nizipli and Daniel Lemire + +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +set -e +COMMAND=$* +SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" +MAINSOURCE=$SCRIPTPATH/.. +ALL_FILES=$(cd $MAINSOURCE && git ls-tree --full-tree --name-only -r HEAD | grep -e ".*\.\(c\|h\|cc\|cpp\|hh\)\$") + +if clang-format-17 --version 2>/dev/null | grep -qF 'version 17.'; then + cd $MAINSOURCE; clang-format-17 --style=file --verbose -i "$@" $ALL_FILES + exit 0 +elif clang-format --version 2>/dev/null | grep -qF 'version 17.'; then + cd $MAINSOURCE; clang-format --style=file --verbose -i "$@" $ALL_FILES + exit 0 +fi +echo "Trying to use docker" +command -v docker >/dev/null 2>&1 || { echo >&2 "Please install docker. E.g., go to https://www.docker.com/products/docker-desktop Type 'docker' to diagnose the problem."; exit 1; } +docker info >/dev/null 2>&1 || { echo >&2 "Docker server is not running? type 'docker info'."; exit 1; } + +if [ -t 0 ]; then DOCKER_ARGS=-it; fi +docker pull kszonek/clang-format-17 + +docker run --rm $DOCKER_ARGS -v "$MAINSOURCE":"$MAINSOURCE":Z -w "$MAINSOURCE" -u "$(id -u $USER):$(id -g $USER)" kszonek/clang-format-17 --style=file --verbose -i "$@" $ALL_FILES