Skip to content

Commit 1fd7fa5

Browse files
authored
add project skeleton (#1)
1 parent 7d54e4f commit 1fd7fa5

15 files changed

+303
-0
lines changed

.clang-format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BasedOnStyle: Google
2+
SortIncludes: Never

.github/workflows/linter.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Linter
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
paths-ignore:
7+
- '**.md'
8+
- 'docs/**'
9+
push:
10+
branches:
11+
- main
12+
paths-ignore:
13+
- '**.md'
14+
- 'docs/**'
15+
16+
permissions:
17+
contents: read
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
lint:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
28+
29+
- name: Run clang-format
30+
uses: jidicula/clang-format-action@c74383674bf5f7c69f60ce562019c1c94bc1421a # v4.13.0
31+
with:
32+
clang-format-version: '17'
33+
fallback-style: 'Google'
34+
35+
- uses: chartboost/ruff-action@e18ae971ccee1b2d7bbef113930f00c670b78da4 # v1.0.0
36+
name: Lint with Ruff
37+
with:
38+
version: 0.5.1

.github/workflows/macos.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: macos CI
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
paths-ignore:
7+
- '**.md'
8+
- 'docs/**'
9+
push:
10+
branches:
11+
- main
12+
paths-ignore:
13+
- '**.md'
14+
- 'docs/**'
15+
16+
permissions:
17+
contents: read
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
ubuntu-build:
25+
runs-on: macos-latest
26+
steps:
27+
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
28+
- name: Prepare
29+
run: cmake -B build
30+
- name: Build
31+
run: cmake --build build -j=2
32+
- name: Test
33+
run: ctest --output-on-failure --test-dir build

.github/workflows/ubuntu.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Ubuntu 24.04 CI
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
paths-ignore:
7+
- '**.md'
8+
- 'docs/**'
9+
push:
10+
branches:
11+
- main
12+
paths-ignore:
13+
- '**.md'
14+
- 'docs/**'
15+
16+
permissions:
17+
contents: read
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
ubuntu-build:
25+
runs-on: ubuntu-24.04
26+
strategy:
27+
matrix:
28+
shared: [ON, OFF]
29+
cxx: [g++-14]
30+
steps:
31+
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
32+
- name: Setup Ninja
33+
run: sudo apt-get install ninja-build
34+
- name: Prepare
35+
run: cmake -DBUILD_SHARED_LIBS=${{matrix.shared}} -G Ninja -B build
36+
env:
37+
CXX: ${{matrix.cxx}}
38+
- name: Build
39+
run: cmake --build build -j=2
40+
- name: Test
41+
run: ctest --output-on-failure --test-dir build

.github/workflows/visual-studio.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: VS17 CI
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
paths-ignore:
7+
- '**.md'
8+
- 'docs/**'
9+
push:
10+
branches:
11+
- main
12+
paths-ignore:
13+
- '**.md'
14+
- 'docs/**'
15+
16+
permissions:
17+
contents: read
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
ci:
25+
name: windows-vs17
26+
runs-on: windows-latest
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
include:
31+
- {gen: Visual Studio 17 2022, arch: x64, config: Release}
32+
- {gen: Visual Studio 17 2022, arch: x64, config: Debug}
33+
steps:
34+
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
35+
- name: Configure
36+
run: |
37+
cmake -G "${{matrix.gen}}" -A ${{matrix.arch}} -B build
38+
- name: Build
39+
run: cmake --build build --config "${{matrix.config}}" --verbose
40+
- name: Run tests
41+
working-directory: build
42+
run: ctest -C "${{matrix.config}}" --output-on-failure

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cmake-build-debug
2+
build
3+
.idea

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

CMakeLists.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
cmake_minimum_required(VERSION 3.28)
2+
project(ncrypto)
3+
4+
set(CMAKE_CXX_STANDARD 20)
5+
set(CMAKE_CXX_STANDARD_REQUIRED True)
6+
if (NOT CMAKE_BUILD_TYPE)
7+
message(STATUS "No build type selected, default to Release")
8+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
9+
endif()
10+
11+
option(NCRYPTO_DEVELOPMENT_CHECKS "Enable development checks" OFF)
12+
13+
include(GNUInstallDirs)
14+
include(FetchContent)
15+
16+
FetchContent_Declare(
17+
googletest
18+
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
19+
)
20+
# For Windows: Prevent overriding the parent project's compiler/linker settings
21+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
22+
FetchContent_MakeAvailable(googletest)
23+
24+
add_subdirectory(src)
25+
enable_testing()
26+
add_subdirectory(tests)
27+
28+
install(
29+
FILES include/ncrypto.h
30+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
31+
COMPONENT ncrypto_development
32+
)
33+
34+
install(
35+
TARGETS ncrypto
36+
EXPORT ncrypto_targets
37+
RUNTIME COMPONENT ncrypto_runtime
38+
LIBRARY COMPONENT ncrypto_runtime
39+
NAMELINK_COMPONENT ncrypto_development
40+
ARCHIVE COMPONENT ncrypto_development
41+
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
42+
)

include/ncrypto.h

Whitespace-only changes.

pyproject.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[project]
2+
name = "ncrypto"
3+
requires-python = ">=3.12"
4+
5+
[tool.ruff]
6+
line-length = 120
7+
target-version = "py312"
8+
9+
[tool.ruff.format]
10+
quote-style = "single"
11+
indent-style = "space"
12+
docstring-code-format = true
13+
14+
[tool.ruff.lint]
15+
select = [
16+
"C90", # McCabe cyclomatic complexity
17+
"E", # pycodestyle
18+
"F", # Pyflakes
19+
"ICN", # flake8-import-conventions
20+
"INT", # flake8-gettext
21+
"PLC", # Pylint conventions
22+
"PLE", # Pylint errors
23+
"PLR09", # Pylint refactoring: max-args, max-branches, max returns, max-statements
24+
"PYI", # flake8-pyi
25+
"RSE", # flake8-raise
26+
"RUF", # Ruff-specific rules
27+
"T10", # flake8-debugger
28+
"TCH", # flake8-type-checking
29+
"TID", # flake8-tidy-imports
30+
"W", # pycodestyle
31+
"YTT", # flake8-2020
32+
"ANN" # flake8-annotations
33+
]
34+
ignore = [
35+
"E722", # Do not use bare `except`
36+
"ANN101", # Missing type annotation for self in method
37+
"TID252", # Prefer absolute imports over relative imports from parent modules
38+
]

src/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
add_library(ncrypto ncrypto.cpp)
2+
target_include_directories(ncrypto
3+
PUBLIC
4+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
5+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
6+
)

src/ncrypto.cpp

Whitespace-only changes.

tests/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
include(GoogleTest)
2+
include(CTest)
3+
add_executable(basic basic.cpp)
4+
target_link_libraries(
5+
basic
6+
GTest::gtest_main
7+
)
8+
target_link_libraries(basic ncrypto)
9+
add_test(basic_test basic)
10+
gtest_discover_tests(basic)

tests/basic.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <ncrypto.h>
2+
3+
#include <gtest/gtest.h>
4+
5+
TEST(basic, test_it) { SUCCEED(); }

tools/run-clang-format.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2023 Yagiz Nizipli and Daniel Lemire
4+
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
# this software and associated documentation files (the "Software"), to deal in
7+
# the Software without restriction, including without limitation the rights to
8+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
# the Software, and to permit persons to whom the Software is furnished to do so,
10+
# subject to the following conditions:
11+
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
set -e
23+
COMMAND=$*
24+
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
25+
MAINSOURCE=$SCRIPTPATH/..
26+
ALL_FILES=$(cd $MAINSOURCE && git ls-tree --full-tree --name-only -r HEAD | grep -e ".*\.\(c\|h\|cc\|cpp\|hh\)\$")
27+
28+
if clang-format-17 --version 2>/dev/null | grep -qF 'version 17.'; then
29+
cd $MAINSOURCE; clang-format-17 --style=file --verbose -i "$@" $ALL_FILES
30+
exit 0
31+
elif clang-format --version 2>/dev/null | grep -qF 'version 17.'; then
32+
cd $MAINSOURCE; clang-format --style=file --verbose -i "$@" $ALL_FILES
33+
exit 0
34+
fi
35+
echo "Trying to use docker"
36+
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; }
37+
docker info >/dev/null 2>&1 || { echo >&2 "Docker server is not running? type 'docker info'."; exit 1; }
38+
39+
if [ -t 0 ]; then DOCKER_ARGS=-it; fi
40+
docker pull kszonek/clang-format-17
41+
42+
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

0 commit comments

Comments
 (0)