From 1767c5e89bdc87412f57c1d6cffbb25364976b86 Mon Sep 17 00:00:00 2001 From: msclock Date: Wed, 10 Apr 2024 16:14:05 +0800 Subject: [PATCH] init Signed-off-by: msclock --- .clang-format | 228 ++++++ .clang-tidy | 78 ++ .cppcheck-suppressions.txt | 2 + .devcontainer/devcontainer.json | 38 + .editorconfig | 20 + .gitattributes | 7 + .github/codecov.yml | 12 + .github/codeql-config.yml | 6 + .github/matchers/pylint.json | 32 + .github/workflows/cd.yml | 111 +++ .github/workflows/ci.yml | 201 ++++++ .github/workflows/codeql.yml | 75 ++ .github/workflows/renovate.yml | 52 ++ .github/workflows/semantic-release.yml | 61 ++ .gitignore | 368 ++++++++++ .markdownlint.yaml | 10 + .pre-commit-config.yaml | 151 ++++ .releaserc.js | 67 ++ .renovaterc.json | 176 +++++ .vscode/launch.json | 32 + .vscode/settings.json | 107 +++ CMakeLists.txt | 33 + CMakePresets.json | 19 + LICENSE | 21 + README.md | 40 ++ cmake/ConfigureVersion.cmake | 48 ++ cmake/ConfigureWarningsAndHardening.cmake | 117 +++ cmake/presets/arch/x64.json | 20 + cmake/presets/base.json | 48 ++ cmake/presets/compilers/gcc.json | 13 + cmake/presets/compilers/llvm.json | 21 + cmake/presets/compilers/mingw.json | 9 + cmake/presets/compilers/msvc.json | 18 + cmake/presets/default.json | 47 ++ cmake/presets/generators/ninja.json | 41 ++ cmake/presets/os/darwin.json | 28 + cmake/presets/os/linux.json | 28 + cmake/presets/os/windows.json | 28 + cmake/presets/toolchains/vcpkg.json | 16 + cmake/presets/triplets/x64-linux.json | 18 + cmake/presets/triplets/x64-mingw-dynamic.json | 18 + cmake/presets/triplets/x64-mingw-static.json | 18 + cmake/presets/triplets/x64-osx.json | 18 + cmake/presets/triplets/x64-windows.json | 18 + cmake/presets/x64-linux-gcc.json | 53 ++ cmake/presets/x64-linux-llvm.json | 53 ++ .../x64-mingw-dynamic-windows-mingw.json | 54 ++ .../x64-mingw-static-windows-mingw.json | 53 ++ cmake/presets/x64-osx-gcc.json | 53 ++ cmake/presets/x64-osx-llvm.json | 53 ++ cmake/presets/x64-windows-llvm.json | 56 ++ cmake/presets/x64-windows-msvc.json | 53 ++ cmake/vcpkg/bootstrap/vcpkg-config.cmake | 20 + cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake | 205 ++++++ .../bootstrap/vcpkg_chainload_toolchain.cmake | 45 ++ cmake/vcpkg/bootstrap/vcpkg_configure.cmake | 55 ++ cmake/vcpkg/bootstrap/vcpkg_export_mode.cmake | 97 +++ .../vcpkg/bootstrap/vcpkg_load_triplet.cmake | 225 ++++++ .../vcpkg_skip_install_on_reconfigure.cmake | 47 ++ cmake/vcpkg/ports/README.md | 3 + cmake/vcpkg/ports/python3/portfile.cmake | 3 + cmake/vcpkg/ports/python3/vcpkg.json | 7 + cmake/vcpkg/scripts/build_type.cmake | 26 + cmake/vcpkg/scripts/toolchains/README.md | 3 + cmake/vcpkg/triplets/README.md | 22 + cmake/vcpkg/vcpkg.toolchain.cmake | 47 ++ copier.yml | 226 ++++++ docs/api/index.md | 17 + docs/conf.py | 120 ++++ docs/contributing.md | 2 + docs/index.md | 35 + includes/codecov.yml.jinja | 12 + includes/copier-answers-sample.yml | 25 + .../licenses/Apache Software License.jinja | 201 ++++++ ...Boost Software License 1.0 (BSL-1.0).jinja | 23 + ...GNU Affero General Public License v3.jinja | 661 +++++++++++++++++ ...NU General Public License v3 (GPLv3).jinja | 674 ++++++++++++++++++ ...r General Public License v3 (LGPLv3).jinja | 165 +++++ includes/licenses/MIT License.jinja | 21 + ...Mozilla Public License 2.0 (MPL 2.0).jinja | 373 ++++++++++ .../licenses/The Unlicense (Unlicense).jinja | 24 + includes/utilities.jinja | 5 + includes/variable.jinja | 69 ++ includes/version_compare.jinja | 23 + noxfile.py | 131 ++++ pyproject.toml | 158 ++++ src/CMakeLists.txt | 12 + src/_core/CMakeLists.txt | 26 + src/_core/include/_core.hpp | 3 + src/_core/src/pybind.cpp | 14 + src/ss_pybind11/__init__.py | 12 + src/ss_pybind11/_core.pyi | 3 + src/ss_pybind11/_version.pyi | 4 + src/ss_pybind11/py.typed | 0 template/.clang-format | 228 ++++++ template/.clang-tidy | 78 ++ template/.cppcheck-suppressions.txt | 2 + template/.editorconfig | 20 + template/.gitattributes | 7 + template/.gitignore.jinja | 370 ++++++++++ template/.markdownlint.yaml | 10 + template/.pre-commit-config.yaml.jinja | 151 ++++ template/.releaserc.js | 67 ++ template/.renovaterc.json.jinja | 190 +++++ template/.vscode/launch.json.jinja | 32 + template/.vscode/settings.json | 107 +++ template/CMakeLists.txt.jinja | 41 ++ template/CMakePresets.json | 19 + template/LICENSE.jinja | 2 + template/README.md.jinja | 48 ++ .../devcontainer.json.jinja | 38 + .../css/mkdocstrings.css | 32 + .../includes/abbreviations.md | 1 + .../index.md.jinja | 1 + ... == 'mkdocs' %]mkdocs.yml[% endif %].jinja | 126 ++++ ...bind11' %]contributing.md[% endif %].jinja | 2 + .../api/index.md | 17 + .../conf.py.jinja | 130 ++++ .../index.md.jinja | 35 + ...ss-cpp' %]CONTRIBUTING.md[% endif %].jinja | 63 ++ ...cov == true %]codecov.yml[% endif %].jinja | 1 + ...eql == true %]codeql-config.yml[% endif %] | 6 + .../matchers/pylint.json | 32 + ...deql == true %]codeql.yml[% endif %].jinja | 75 ++ .../workflows/cd.yml.jinja | 111 +++ .../workflows/ci.yml.jinja | 208 ++++++ .../workflows/renovate.yml.jinja | 52 ++ .../workflows/semantic-release.yml.jinja | 61 ++ ...managed' %].gitlab-ci.yml[% endif %].jinja | 7 + ...cov == true %]codecov.yml[% endif %].jinja | 1 + template/cmake/ConfigureVersion.cmake | 48 ++ .../cmake/ConfigureWarningsAndHardening.cmake | 117 +++ ...onfigureConanDependencies.cmake[% endif %] | 37 + ...]ConfigureCPMDependencies.cmake[% endif %] | 34 + template/cmake/presets/arch/x64.json | 20 + template/cmake/presets/base.json | 48 ++ template/cmake/presets/compilers/gcc.json | 13 + template/cmake/presets/compilers/llvm.json | 21 + template/cmake/presets/compilers/mingw.json | 9 + template/cmake/presets/compilers/msvc.json | 18 + template/cmake/presets/default.json | 47 ++ template/cmake/presets/generators/ninja.json | 41 ++ template/cmake/presets/os/darwin.json | 28 + template/cmake/presets/os/linux.json | 28 + template/cmake/presets/os/windows.json | 28 + template/cmake/presets/toolchains/vcpkg.json | 16 + .../cmake/presets/triplets/x64-linux.json | 18 + .../presets/triplets/x64-mingw-dynamic.json | 18 + .../presets/triplets/x64-mingw-static.json | 18 + template/cmake/presets/triplets/x64-osx.json | 18 + .../cmake/presets/triplets/x64-windows.json | 18 + template/cmake/presets/x64-linux-gcc.json | 53 ++ template/cmake/presets/x64-linux-llvm.json | 53 ++ .../x64-mingw-dynamic-windows-mingw.json | 54 ++ .../x64-mingw-static-windows-mingw.json | 53 ++ template/cmake/presets/x64-osx-gcc.json | 53 ++ template/cmake/presets/x64-osx-llvm.json | 53 ++ template/cmake/presets/x64-windows-llvm.json | 56 ++ template/cmake/presets/x64-windows-msvc.json | 53 ++ .../cmake/vcpkg/bootstrap/vcpkg-config.cmake | 20 + .../vcpkg/bootstrap/vcpkg_bootstrap.cmake | 205 ++++++ .../bootstrap/vcpkg_chainload_toolchain.cmake | 45 ++ .../vcpkg/bootstrap/vcpkg_configure.cmake | 55 ++ .../vcpkg/bootstrap/vcpkg_export_mode.cmake | 97 +++ .../vcpkg/bootstrap/vcpkg_load_triplet.cmake | 225 ++++++ .../vcpkg_skip_install_on_reconfigure.cmake | 47 ++ template/cmake/vcpkg/ports/README.md | 3 + .../cmake/vcpkg/ports/python3/portfile.cmake | 3 + template/cmake/vcpkg/ports/python3/vcpkg.json | 7 + template/cmake/vcpkg/scripts/build_type.cmake | 26 + .../cmake/vcpkg/scripts/toolchains/README.md | 3 + template/cmake/vcpkg/triplets/README.md | 22 + .../cmake/vcpkg/vcpkg.toolchain.cmake.jinja | 47 ++ template/noxfile.py.jinja | 132 ++++ template/pyproject.toml.jinja | 205 ++++++ template/src/CMakeLists.txt | 12 + template/src/_core/CMakeLists.txt | 26 + template/src/_core/include/_core.hpp | 3 + template/src/_core/src/pybind.cpp | 14 + .../src/{{ module_name }}/__init__.py.jinja | 12 + template/src/{{ module_name }}/_core.pyi | 3 + template/src/{{ module_name }}/_version.pyi | 4 + template/src/{{ module_name }}/py.typed | 0 template/tests/test_compiled.py.jinja | 8 + template/tests/test_package.py.jinja | 9 + template/vcpkg.json.jinja | 82 +++ template/{{_copier_conf.answers_file}}.jinja | 1 + tests/test_compiled.py | 8 + tests/test_package.py | 9 + vcpkg.json | 57 ++ 190 files changed, 11623 insertions(+) create mode 100644 .clang-format create mode 100644 .clang-tidy create mode 100644 .cppcheck-suppressions.txt create mode 100644 .devcontainer/devcontainer.json create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .github/codecov.yml create mode 100644 .github/codeql-config.yml create mode 100644 .github/matchers/pylint.json create mode 100644 .github/workflows/cd.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/codeql.yml create mode 100644 .github/workflows/renovate.yml create mode 100644 .github/workflows/semantic-release.yml create mode 100644 .gitignore create mode 100644 .markdownlint.yaml create mode 100644 .pre-commit-config.yaml create mode 100644 .releaserc.js create mode 100644 .renovaterc.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 CMakeLists.txt create mode 100644 CMakePresets.json create mode 100644 LICENSE create mode 100644 README.md create mode 100644 cmake/ConfigureVersion.cmake create mode 100644 cmake/ConfigureWarningsAndHardening.cmake create mode 100644 cmake/presets/arch/x64.json create mode 100644 cmake/presets/base.json create mode 100644 cmake/presets/compilers/gcc.json create mode 100644 cmake/presets/compilers/llvm.json create mode 100644 cmake/presets/compilers/mingw.json create mode 100644 cmake/presets/compilers/msvc.json create mode 100644 cmake/presets/default.json create mode 100644 cmake/presets/generators/ninja.json create mode 100644 cmake/presets/os/darwin.json create mode 100644 cmake/presets/os/linux.json create mode 100644 cmake/presets/os/windows.json create mode 100644 cmake/presets/toolchains/vcpkg.json create mode 100644 cmake/presets/triplets/x64-linux.json create mode 100644 cmake/presets/triplets/x64-mingw-dynamic.json create mode 100644 cmake/presets/triplets/x64-mingw-static.json create mode 100644 cmake/presets/triplets/x64-osx.json create mode 100644 cmake/presets/triplets/x64-windows.json create mode 100644 cmake/presets/x64-linux-gcc.json create mode 100644 cmake/presets/x64-linux-llvm.json create mode 100644 cmake/presets/x64-mingw-dynamic-windows-mingw.json create mode 100644 cmake/presets/x64-mingw-static-windows-mingw.json create mode 100644 cmake/presets/x64-osx-gcc.json create mode 100644 cmake/presets/x64-osx-llvm.json create mode 100644 cmake/presets/x64-windows-llvm.json create mode 100644 cmake/presets/x64-windows-msvc.json create mode 100644 cmake/vcpkg/bootstrap/vcpkg-config.cmake create mode 100644 cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake create mode 100644 cmake/vcpkg/bootstrap/vcpkg_chainload_toolchain.cmake create mode 100644 cmake/vcpkg/bootstrap/vcpkg_configure.cmake create mode 100644 cmake/vcpkg/bootstrap/vcpkg_export_mode.cmake create mode 100644 cmake/vcpkg/bootstrap/vcpkg_load_triplet.cmake create mode 100644 cmake/vcpkg/bootstrap/vcpkg_skip_install_on_reconfigure.cmake create mode 100644 cmake/vcpkg/ports/README.md create mode 100644 cmake/vcpkg/ports/python3/portfile.cmake create mode 100644 cmake/vcpkg/ports/python3/vcpkg.json create mode 100644 cmake/vcpkg/scripts/build_type.cmake create mode 100644 cmake/vcpkg/scripts/toolchains/README.md create mode 100644 cmake/vcpkg/triplets/README.md create mode 100644 cmake/vcpkg/vcpkg.toolchain.cmake create mode 100644 copier.yml create mode 100644 docs/api/index.md create mode 100644 docs/conf.py create mode 100644 docs/contributing.md create mode 100644 docs/index.md create mode 100644 includes/codecov.yml.jinja create mode 100644 includes/copier-answers-sample.yml create mode 100644 includes/licenses/Apache Software License.jinja create mode 100644 includes/licenses/Boost Software License 1.0 (BSL-1.0).jinja create mode 100644 includes/licenses/GNU Affero General Public License v3.jinja create mode 100644 includes/licenses/GNU General Public License v3 (GPLv3).jinja create mode 100644 includes/licenses/GNU Lesser General Public License v3 (LGPLv3).jinja create mode 100644 includes/licenses/MIT License.jinja create mode 100644 includes/licenses/Mozilla Public License 2.0 (MPL 2.0).jinja create mode 100644 includes/licenses/The Unlicense (Unlicense).jinja create mode 100644 includes/utilities.jinja create mode 100644 includes/variable.jinja create mode 100644 includes/version_compare.jinja create mode 100644 noxfile.py create mode 100644 pyproject.toml create mode 100644 src/CMakeLists.txt create mode 100644 src/_core/CMakeLists.txt create mode 100644 src/_core/include/_core.hpp create mode 100644 src/_core/src/pybind.cpp create mode 100644 src/ss_pybind11/__init__.py create mode 100644 src/ss_pybind11/_core.pyi create mode 100644 src/ss_pybind11/_version.pyi create mode 100644 src/ss_pybind11/py.typed create mode 100644 template/.clang-format create mode 100644 template/.clang-tidy create mode 100644 template/.cppcheck-suppressions.txt create mode 100644 template/.editorconfig create mode 100644 template/.gitattributes create mode 100644 template/.gitignore.jinja create mode 100644 template/.markdownlint.yaml create mode 100644 template/.pre-commit-config.yaml.jinja create mode 100644 template/.releaserc.js create mode 100644 template/.renovaterc.json.jinja create mode 100644 template/.vscode/launch.json.jinja create mode 100644 template/.vscode/settings.json create mode 100644 template/CMakeLists.txt.jinja create mode 100644 template/CMakePresets.json create mode 100644 template/LICENSE.jinja create mode 100644 template/README.md.jinja create mode 100644 template/[% if create_devcontainer == true %].devcontainer[% endif %]/devcontainer.json.jinja create mode 100644 template/[% if docs_type == 'mkdocs' %]docs[% endif %]/css/mkdocstrings.css create mode 100644 template/[% if docs_type == 'mkdocs' %]docs[% endif %]/includes/abbreviations.md create mode 100644 template/[% if docs_type == 'mkdocs' %]docs[% endif %]/index.md.jinja create mode 100644 template/[% if docs_type == 'mkdocs' %]mkdocs.yml[% endif %].jinja create mode 100644 template/[% if docs_type == 'sphinx' %]docs[% endif %]/[% if repo_name == 'ss-pybind11' %]contributing.md[% endif %].jinja create mode 100644 template/[% if docs_type == 'sphinx' %]docs[% endif %]/api/index.md create mode 100644 template/[% if docs_type == 'sphinx' %]docs[% endif %]/conf.py.jinja create mode 100644 template/[% if docs_type == 'sphinx' %]docs[% endif %]/index.md.jinja create mode 100644 template/[% if repo_name == 'ss-cpp' %]CONTRIBUTING.md[% endif %].jinja create mode 100644 template/[% if repo_platform == 'github' %].github[% endif %]/[% if use_codecov == true %]codecov.yml[% endif %].jinja create mode 100644 template/[% if repo_platform == 'github' %].github[% endif %]/[% if use_codeql == true %]codeql-config.yml[% endif %] create mode 100644 template/[% if repo_platform == 'github' %].github[% endif %]/matchers/pylint.json create mode 100644 template/[% if repo_platform == 'github' %].github[% endif %]/workflows/[% if use_codeql == true %]codeql.yml[% endif %].jinja create mode 100644 template/[% if repo_platform == 'github' %].github[% endif %]/workflows/cd.yml.jinja create mode 100644 template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja create mode 100644 template/[% if repo_platform == 'github' %].github[% endif %]/workflows/renovate.yml.jinja create mode 100644 template/[% if repo_platform == 'github' %].github[% endif %]/workflows/semantic-release.yml.jinja create mode 100644 template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab-ci.yml[% endif %].jinja create mode 100644 template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/[% if use_codecov == true %]codecov.yml[% endif %].jinja create mode 100644 template/cmake/ConfigureVersion.cmake create mode 100644 template/cmake/ConfigureWarningsAndHardening.cmake create mode 100644 template/cmake/[% if use_conan == true %]ConfigureConanDependencies.cmake[% endif %] create mode 100644 template/cmake/[% if use_cpm == true %]ConfigureCPMDependencies.cmake[% endif %] create mode 100644 template/cmake/presets/arch/x64.json create mode 100644 template/cmake/presets/base.json create mode 100644 template/cmake/presets/compilers/gcc.json create mode 100644 template/cmake/presets/compilers/llvm.json create mode 100644 template/cmake/presets/compilers/mingw.json create mode 100644 template/cmake/presets/compilers/msvc.json create mode 100644 template/cmake/presets/default.json create mode 100644 template/cmake/presets/generators/ninja.json create mode 100644 template/cmake/presets/os/darwin.json create mode 100644 template/cmake/presets/os/linux.json create mode 100644 template/cmake/presets/os/windows.json create mode 100644 template/cmake/presets/toolchains/vcpkg.json create mode 100644 template/cmake/presets/triplets/x64-linux.json create mode 100644 template/cmake/presets/triplets/x64-mingw-dynamic.json create mode 100644 template/cmake/presets/triplets/x64-mingw-static.json create mode 100644 template/cmake/presets/triplets/x64-osx.json create mode 100644 template/cmake/presets/triplets/x64-windows.json create mode 100644 template/cmake/presets/x64-linux-gcc.json create mode 100644 template/cmake/presets/x64-linux-llvm.json create mode 100644 template/cmake/presets/x64-mingw-dynamic-windows-mingw.json create mode 100644 template/cmake/presets/x64-mingw-static-windows-mingw.json create mode 100644 template/cmake/presets/x64-osx-gcc.json create mode 100644 template/cmake/presets/x64-osx-llvm.json create mode 100644 template/cmake/presets/x64-windows-llvm.json create mode 100644 template/cmake/presets/x64-windows-msvc.json create mode 100644 template/cmake/vcpkg/bootstrap/vcpkg-config.cmake create mode 100644 template/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake create mode 100644 template/cmake/vcpkg/bootstrap/vcpkg_chainload_toolchain.cmake create mode 100644 template/cmake/vcpkg/bootstrap/vcpkg_configure.cmake create mode 100644 template/cmake/vcpkg/bootstrap/vcpkg_export_mode.cmake create mode 100644 template/cmake/vcpkg/bootstrap/vcpkg_load_triplet.cmake create mode 100644 template/cmake/vcpkg/bootstrap/vcpkg_skip_install_on_reconfigure.cmake create mode 100644 template/cmake/vcpkg/ports/README.md create mode 100644 template/cmake/vcpkg/ports/python3/portfile.cmake create mode 100644 template/cmake/vcpkg/ports/python3/vcpkg.json create mode 100644 template/cmake/vcpkg/scripts/build_type.cmake create mode 100644 template/cmake/vcpkg/scripts/toolchains/README.md create mode 100644 template/cmake/vcpkg/triplets/README.md create mode 100644 template/cmake/vcpkg/vcpkg.toolchain.cmake.jinja create mode 100644 template/noxfile.py.jinja create mode 100644 template/pyproject.toml.jinja create mode 100644 template/src/CMakeLists.txt create mode 100644 template/src/_core/CMakeLists.txt create mode 100644 template/src/_core/include/_core.hpp create mode 100644 template/src/_core/src/pybind.cpp create mode 100644 template/src/{{ module_name }}/__init__.py.jinja create mode 100644 template/src/{{ module_name }}/_core.pyi create mode 100644 template/src/{{ module_name }}/_version.pyi create mode 100644 template/src/{{ module_name }}/py.typed create mode 100644 template/tests/test_compiled.py.jinja create mode 100644 template/tests/test_package.py.jinja create mode 100644 template/vcpkg.json.jinja create mode 100644 template/{{_copier_conf.answers_file}}.jinja create mode 100644 tests/test_compiled.py create mode 100644 tests/test_package.py create mode 100644 vcpkg.json diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..a36591a --- /dev/null +++ b/.clang-format @@ -0,0 +1,228 @@ +--- +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html +--- +Language: Cpp +# Do not offset access specifiers (public, protected, private) +AccessModifierOffset: -4 +# Align parameters after opening brackets (round, angle, square) +AlignAfterOpenBracket: Align +# Do not align consecutive assignments +AlignConsecutiveAssignments: false +# Do not align consecutive declarations +AlignConsecutiveDeclarations: false +# Align consecutive macros +AlignConsecutiveMacros: true +# Align escaped newlines to the left +AlignEscapedNewlines: Left +# Align operands of binary and ternary expressions horizontally +AlignOperands: true +# Align trailing comments +AlignTrailingComments: true +# Allow all function arguments on the next line +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +# Do not allow short blocks (e.g., while blocks) on a single line +AllowShortBlocksOnASingleLine: false +# Do not allow short case labels on a single line +AllowShortCaseLabelsOnASingleLine: false +# Do not allow non-empty functions defined outside of a class on a single line +AllowShortFunctionsOnASingleLine: Inline +# Do not allow short if statements on a single line +AllowShortIfStatementsOnASingleLine: false +# Do not allow short loop blocks on a single line +AllowShortLoopsOnASingleLine: false +# Do not break after the return type in function definitions, unless it exceeds the column limit +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +# Do not break before multiline strings +AlwaysBreakBeforeMultilineStrings: false +# Always break after template declarations +AlwaysBreakTemplateDeclarations: Yes +# Do not require each function argument to be on a separate line +BinPackArguments: false +# Do not require each function parameter to be on a separate line +BinPackParameters: false +# Configure brace wrapping style +BraceWrapping: + # Do not break after case labels + AfterCaseLabel: false + # Do not break after class definitions + AfterClass: false + # Do not break after control statements + AfterControlStatement: false + # Do not break after enum definitions + AfterEnum: false + # Do not break after function definitions + AfterFunction: false + # Do not break after namespace definitions + AfterNamespace: false + # Do not break after struct definitions + AfterStruct: false + # Do not break after union definitions + AfterUnion: false + # Do not break after extern blocks + AfterExternBlock: false + # Break before catch statements + BeforeCatch: true + # Break before else statements + BeforeElse: true + # Do not break before lambda bodies + BeforeLambdaBody: false + # Break before while statements + BeforeWhile: true + # Do not indent braces + IndentBraces: false + # Allow empty function bodies on a single line + SplitEmptyFunction: false + # Allow empty statements on a single line + SplitEmptyRecord: false + # Allow empty namespaces on a single line + SplitEmptyNamespace: false +# Break before binary operators, except for assignment operators +BreakBeforeBinaryOperators: NonAssignment +# Customize break before braces in BraceWrapping +BreakBeforeBraces: Custom +# Do not break after commas in inheritance lists +BreakBeforeInheritanceComma: false +# Break before colons in inheritance lists, but not before commas +BreakInheritanceList: BeforeColon +# Break before ternary operators +BreakBeforeTernaryOperators: true +# Do not break after commas in constructor initializer lists +BreakConstructorInitializersBeforeComma: false +# Break before colons in constructor initializer lists, but not before commas +BreakConstructorInitializers: BeforeColon +# Allow breaking string literals +BreakStringLiterals: true +# Column limit for each line +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +# Do not allow different namespaces to be defined on the same line +CompactNamespaces: false +# Constructor initializer lists should either be all on one line or one per line +ConstructorInitializerAllOnOneLineOrOnePerLine: true +# Indent constructor initializer lists by 4 spaces +ConstructorInitializerIndentWidth: 4 +# Indent continuation lines by 4 spaces +ContinuationIndentWidth: 4 +# No spaces around variable initialization lists +Cpp11BracedListStyle: true +DerivePointerAlignment: true +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +# Automatically add comments at the end of namespaces +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: ^ + Priority: 2 + - Regex: StdAfx.h + Priority: -1 + - Regex: ^<.*\.h> + Priority: 1 + - Regex: ^<.* + Priority: 2 + - Regex: .* + Priority: 3 +IncludeIsMainRegex: ([-_](test|unittest))?$ +# Indent case labels inside switch statements +IndentCaseLabels: true +# Indent code blocks inside extern blocks +IndentExternBlock: Indent +# Do not indent preprocessor directives +IndentPPDirectives: None +# Use 4 spaces for indentation +IndentWidth: 4 +# Do not indent wrapped function names after the return type +IndentWrappedFunctionNames: false +# Do not keep empty lines at the start of code blocks +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +# Do not allow consecutive empty lines +MaxEmptyLinesToKeep: 1 +# Do not indent contents inside namespaces +NamespaceIndentation: None +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +# * and & should be placed next to the type name +PointerAlignment: Left +RawStringFormats: + - Language: Cpp + Delimiters: + - cc + - CC + - cpp + - Cpp + - CPP + - c++ + - C++ + CanonicalDelimiter: '' + BasedOnStyle: google + - Language: TextProto + Delimiters: + - pb + - PB + - proto + - PROTO + EnclosingFunctions: + - EqualsProto + - EquivToProto + - PARSE_PARTIAL_TEXT_PROTO + - PARSE_TEST_PROTO + - PARSE_TEXT_PROTO + - ParseTextOrDie + - ParseTextProtoOrDie + CanonicalDelimiter: '' + BasedOnStyle: google +# Allow reflowing of comments +ReflowComments: true +# Allow sorting of #include statements +SortIncludes: true +# Allow sorting of using declarations +SortUsingDeclarations: true +# Do not include spaces after C-style casts +SpaceAfterCStyleCast: false +# Require a space after the template keyword +SpaceAfterTemplateKeyword: true +# Require spaces around assignment operators +SpaceBeforeAssignmentOperators: true +# Do not include spaces before C++11 braced initializer lists +SpaceBeforeCpp11BracedList: false +# Require a space before the colon in constructor initializers +SpaceBeforeCtorInitializerColon: true +# Require a space before the colon in inheritance statements +SpaceBeforeInheritanceColon: true +# Require a space after control statement keywords (if, for, while, etc.) +SpaceBeforeParens: ControlStatements +# Require a space before the colon in range-based for loops +SpaceBeforeRangeBasedForLoopColon: true +# Do not include spaces inside empty parentheses +SpaceInEmptyParentheses: false +# Require a space before // in trailing comments +SpacesBeforeTrailingComments: 1 +# Do not include spaces around angle brackets +SpacesInAngles: false +# Do not include spaces around C-style cast parentheses +SpacesInCStyleCastParentheses: false +# Do not include spaces around parentheses +SpacesInParentheses: false +# Do not include spaces around square brackets +SpacesInSquareBrackets: false +Standard: Auto +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseTab: Never diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..820d51d --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,78 @@ +Checks: > + *, + -abseil-*, + -altera-*, + -android-*, + -boost-*, + -cert-*, + -cppcoreguidelines-*, + -darwin-*, + -fuchsia-*, + -google-*, + -hicpp-*, + -linuxkernel-*, + -llvm-*, + -llvmlibc-*, + -mpi-*, + -objc-*, + -openmp-*, + -zircon-*, + cert-err34-c, + google-explicit-constructor, + cppcoreguidelines-rvalue-reference-param-not-moved, + -bugprone-assignment-in-if-condition, + -bugprone-branch-clone, + -bugprone-easily-swappable-parameters, + -bugprone-empty-catch, + -bugprone-macro-parentheses, + -bugprone-narrowing-conversions, + -bugprone-signed-char-misuse, + -bugprone-switch-missing-default-case, + -bugprone-unchecked-optional-access, + -clang-analyzer-*, + -concurrency-mt-unsafe, + -misc-const-correctness, + -misc-no-recursion, + -misc-non-private-member-variables-in-classes, + -misc-throw-by-value-catch-by-reference, + -misc-use-anonymous-namespace, + -misc-include-cleaner, + -misc-unused-using-decls, + -modernize-avoid-c-arrays, + -modernize-deprecated-ios-base-aliases, + -modernize-loop-convert, + -modernize-macro-to-enum, + -modernize-raw-string-literal, + -modernize-replace-auto-ptr, + -modernize-return-braced-init-list, + -modernize-type-traits, + -modernize-use-auto, + -modernize-use-nodiscard, + -modernize-use-trailing-return-type, + -modernize-concat-nested-namespaces, + -performance-avoid-endl, + -performance-enum-size, + -performance-inefficient-string-concatenation, + -performance-no-automatic-move, + -performance-noexcept-swap, + -portability-simd-intrinsics, + -portability-std-allocator-const, + -readability-avoid-const-params-in-decls, + -readability-avoid-nested-conditional-operator, + -readability-braces-around-statements, + -readability-container-data-pointer, + -readability-function-cognitive-complexity, + -readability-function-size, + -readability-identifier-length, + -readability-identifier-naming, + -readability-implicit-bool-conversion, + -readability-isolate-declaration, + -readability-magic-numbers, + -readability-suspicious-call-argument, + -readability-uppercase-literal-suffix +HeaderFilterRegex: (src)\/[a-z]+\.hpp +CheckOptions: + - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic + value: '1' + - key: readability-simplify-boolean-expr.SimplifyDeMorgan + value: '0' diff --git a/.cppcheck-suppressions.txt b/.cppcheck-suppressions.txt new file mode 100644 index 0000000..3384b4a --- /dev/null +++ b/.cppcheck-suppressions.txt @@ -0,0 +1,2 @@ +// Limit analysis of branches. Use --check-level=exhaustive to analyze all branches. +normalCheckLevelMaxBranches diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..b9fd25f --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,38 @@ +// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at: +// https://github.com/devcontainers/images/tree/main/src/base-ubuntu +{ + "name": "ss-pybind11", + "image": "mcr.microsoft.com/devcontainers/base:ubuntu-22.04", + "capAdd": [ + // Enable ptrace-based debugging for C++ + "SYS_PTRACE" + ], + "securityOpt": [ + "seccomp=unconfined" + ], + // https://github.com/devcontainers/features + // Using features in vscode requires access github with uncomment the below + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "username": "vscode" + }, + "ghcr.io/devcontainers/features/docker-in-docker:2": {}, + "ghcr.io/devcontainers/features/python:1": {}, + "ghcr.io/msclock/features/vcpkg:2": {} + }, + "customizations": { + "vscode": { + "extensions": [ + "EditorConfig.EditorConfig", + "mhutchie.git-graph", + "ms-vscode.cmake-tools" + ] + } + }, + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": { + "git-completions": "echo 'source /usr/share/bash-completion/completions/git' >> ~/.bashrc" + }, + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + "remoteUser": "vscode" +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..4f6c70c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +# EditorConfig is awesome: https://EditorConfig.org + +root = true + +[*] +end_of_line = lf +charset = utf-8 +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{yml,yaml,json,toml,jinja,css,js,cmake}] +indent_size = 2 + +[CMakeLists.txt] +indent_size = 2 + +[Makefile] +indent_style = tab diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a7fe8ee --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +# Keep compatilibity between windows and unix-like OS +* text=auto eol=lf +*.{cmd,[cC][mM][dD]} text eol=crlf +*.{bat,[bB][aA][tT]} text eol=crlf + +# Archive Format +*.tar.gz filter=lfs diff=lfs merge=lfs -text diff --git a/.github/codecov.yml b/.github/codecov.yml new file mode 100644 index 0000000..83fd753 --- /dev/null +++ b/.github/codecov.yml @@ -0,0 +1,12 @@ +codecov: + notify: + after_n_builds: 1 +coverage: + status: + project: + default: + target: auto + threshold: 5% + patch: + default: + informational: true diff --git a/.github/codeql-config.yml b/.github/codeql-config.yml new file mode 100644 index 0000000..8de2daf --- /dev/null +++ b/.github/codeql-config.yml @@ -0,0 +1,6 @@ +name: CodeQL config + +# https://codeql.github.com/codeql-query-help/ +query-filters: + - exclude: + id: py/commented-out-code diff --git a/.github/matchers/pylint.json b/.github/matchers/pylint.json new file mode 100644 index 0000000..e3a6bd1 --- /dev/null +++ b/.github/matchers/pylint.json @@ -0,0 +1,32 @@ +{ + "problemMatcher": [ + { + "severity": "warning", + "pattern": [ + { + "regexp": "^([^:]+):(\\d+):(\\d+): ([A-DF-Z]\\d+): \\033\\[[\\d;]+m([^\\033]+).*$", + "file": 1, + "line": 2, + "column": 3, + "code": 4, + "message": 5 + } + ], + "owner": "pylint-warning" + }, + { + "severity": "error", + "pattern": [ + { + "regexp": "^([^:]+):(\\d+):(\\d+): (E\\d+): \\033\\[[\\d;]+m([^\\033]+).*$", + "file": 1, + "line": 2, + "column": 3, + "code": 4, + "message": 5 + } + ], + "owner": "pylint-error" + } + ] +} diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..cc2f4e6 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,111 @@ +name: CD + +on: + workflow_dispatch: + release: + types: + - published + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + FORCE_COLOR: 3 + +jobs: + make_sdist: + name: Make SDist + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Build SDist + run: pipx run build --sdist + + - uses: actions/upload-artifact@v4 + with: + name: cibw-sdist + path: dist/*.tar.gz + + build_wheels: + name: Wheel on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-22.04, windows-2202, macos-12] + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: pypa/cibuildwheel@v2.22.0 + + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} + path: wheelhouse/*.whl + + upload_all: + needs: [build_wheels, make_sdist] + environment: pypi + permissions: + id-token: write + runs-on: ubuntu-latest + if: github.event_name == 'release' && github.event.action == 'published' + + steps: + - uses: actions/download-artifact@v4 + with: + pattern: cibw-* + path: dist + merge-multiple: true + + - uses: pypa/gh-action-pypi-publish@release/v1 + env: + PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }} + with: + password: ${{ secrets.PYPI_API_TOKEN }} + + pages: + name: Deploy to GitHub Pages + runs-on: ubuntu-22.04 + if: ${{ github.ref_name == github.event.repository.default_branch || (github.event_name == 'release' && github.event.action == 'published') }} + permissions: + contents: write + id-token: write + timeout-minutes: 15 + + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + ref: ${{ github.head_ref }} + + - name: Cache + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4 + with: + path: | + ~/vcpkg + ~/.cache/pip + ~/.cache/vcpkg + key: cd-pages-${{ hashFiles('vcpkg.json') }} + restore-keys: cd-pages-${{ hashFiles('vcpkg.json') }} + + - uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5 + with: + python-version: 3.x + + - name: Build Docs + run: pipx run nox -s docs + + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs/_build/html diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7a48118 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,201 @@ +name: CI + +on: + workflow_dispatch: + + push: + branches: + - master + - beta + - alpha + - '*.x' + + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + FORCE_COLOR: 3 + +jobs: + pre-commit: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + with: + fetch-depth: 0 + + - uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5 + with: + python-version: 3.x + + - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 + with: + extra_args: --hook-stage manual --all-files + + - name: Run PyLint + run: | + echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json" + pipx run nox -s pylint + + + consistency: + if: ${{ !cancelled() && ! failure() }} + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + with: + fetch-depth: 0 + + - name: Set up Git + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + + - uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5 + with: + python-version: 3.x + + - name: Install copier + run: pipx install copier==9.3.1 + + - name: Verify template + run: pipx run nox -s template_build + + - name: Test for consistency + run: | + echo "List inconsistent files:" + git status --porcelain + git diff --exit-code || ( \ + echo "# :warning: Inconsistent files found" >> $GITHUB_STEP_SUMMARY && \ + echo "The following files are inconsistent with the template:" >> $GITHUB_STEP_SUMMARY && \ + git status --porcelain | while read file; do echo "- $file"; done >> $GITHUB_STEP_SUMMARY && \ + echo "" >> $GITHUB_STEP_SUMMARY && \ + echo "Please run 'copier copy -r HEAD -f . .' to fix them." >>$GITHUB_STEP_SUMMARY && \ + exit 1 \ + ) + + + checks: + runs-on: ${{ matrix.runs-on }} + needs: [pre-commit] + strategy: + fail-fast: false + matrix: + python-version: ['3.8', '3.12'] + runs-on: [ubuntu-22.04, macos-12, windows-2022] + + include: + - python-version: pypy-3.10 + runs-on: ubuntu-22.04 + + name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }} + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Cache + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4 + with: + path: | + ~/vcpkg + ~/.cache/pip + ~/.cache/vcpkg + key: ${{ matrix.python-version }}-${{ matrix.runs-on }}-${{ hashFiles('vcpkg.json') }} + restore-keys: ${{ matrix.python-version }}-${{ matrix.runs-on }}-${{ hashFiles('vcpkg.json') }} + + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install package + run: python -m pip install .[test] + + - name: Test package + run: >- + python -m pytest -ra --cov --cov-report=xml --cov-report=term + --durations=20 + + - name: Upload coverage report + uses: codecov/codecov-action@v3.1.4 + + check-docs: + runs-on: ubuntu-22.04 + needs: [pre-commit, consistency] + timeout-minutes: 15 + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Cache + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4 + with: + path: | + ~/vcpkg + ~/.cache/pip + ~/.cache/vcpkg + key: docs-${{ hashFiles('vcpkg.json') }} + restore-keys: docs-${{ hashFiles('vcpkg.json') }} + + - uses: actions/setup-python@v5 + with: + python-version: 3.x + + - name: Checks the docs with warnings as errors + run: pipx run nox -s docs -- --check + + + - name: Checks the docs for broken links + run: pipx run nox -s docs -- --linkcheck + + + check-mkdocs-docs: + runs-on: ubuntu-22.04 + needs: [pre-commit, consistency] + timeout-minutes: 15 + + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + with: + fetch-depth: 0 + + - uses: actions/setup-python@v5 + with: + python-version: 3.x + + - name: Install copier + run: pipx install copier==9.3.1 + + - name: Apply mkdocs + run: pipx run nox -s template-build -- -d docs_type=mkdocs + + - name: Checks the docs with warnings as errors + run: pipx run nox -s docs -- --check + + + pass: + if: always() + needs: + - checks + - check-docs + - check-mkdocs-docs + runs-on: ubuntu-22.04 + timeout-minutes: 2 + permissions: + pull-requests: write + + steps: + - name: Decide whether the needed jobs succeeded or failed + uses: re-actors/alls-green@release/v1 + with: + jobs: ${{ toJSON(needs) }} + + - name: Approve pr if all jobs succeeded + if: contains(github.event.pull_request.labels.*.name, 'auto-approval') + uses: hmarr/auto-approve-action@v4 diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..da78503 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,75 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: CodeQL + +on: + push: + branches: [master] + pull_request: + # The branches below must be a subset of the branches above + branches: [master] + schedule: + - cron: 15 4 * * 3 + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-22.04 + timeout-minutes: 15 + permissions: + actions: read + contents: read + security-events: write + strategy: + fail-fast: false + matrix: + language: [cpp, python] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://git.io/codeql-language-support + + steps: + - name: Checkout repository + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + with: + fetch-depth: 0 + + - name: Initialize CodeQL + uses: github/codeql-action/init@8214744c546c1e5c8f03dde8fab3a7353211988d # v3.26.7 + with: + languages: ${{ matrix.language }} + config-file: ./.github/codeql-config.yml + + - name: Cache + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4 + with: + path: | + ~/vcpkg + ~/.cache/vcpkg + key: codeql-${{ hashFiles('vcpkg.json') }} + restore-keys: codeql-${{ hashFiles('vcpkg.json') }} + + - uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5 + with: + python-version: 3.x + + - name: Build + run: python -m pip install .[test] + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@8214744c546c1e5c8f03dde8fab3a7353211988d # v3.26.7 diff --git a/.github/workflows/renovate.yml b/.github/workflows/renovate.yml new file mode 100644 index 0000000..b56531b --- /dev/null +++ b/.github/workflows/renovate.yml @@ -0,0 +1,52 @@ +name: Renovate + +on: + schedule: + # * is a special character in YAML so you have to quote this string + - cron: '*/15 0-3 * * 1' + workflow_dispatch: + +jobs: + renovate: + container: + env: + LOG_LEVEL: debug + RENOVATE_ALLOWED_POST_UPGRADE_COMMANDS: '["^git", "^pip", "^copier", "^find"]' + RENOVATE_BRANCH_PREFIX: renovate-github/ + RENOVATE_ENABLED: ${{ vars.RENOVATE_ENABLED || true }} + RENOVATE_ENABLED_MANAGERS: '["pep621", "github-actions", "regex", "pre-commit"]' + RENOVATE_OPTIMIZE_FOR_DISABLED: 'true' + RENOVATE_PLATFORM: github + RENOVATE_REPOSITORIES: '["${{ github.repository }}"]' + RENOVATE_REPOSITORY_CACHE: enabled + image: ghcr.io/renovatebot/renovate:38.110.2@sha256:06665449c11c61011319ef8f1cd6e00a265d2692e84586f964ba368d4f67591d + options: --user root + runs-on: ubuntu-22.04 + steps: + - run: env | sort + + - name: Generate a token with GitHub App if App ID exists + id: generate-token + if: vars.BOT_APP_ID + uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1 + with: + app-id: ${{ vars.BOT_APP_ID }} + private-key: ${{ secrets.BOT_PRIVATE_KEY }} + + - name: Warn if RENOVATE_GIT_AUTHOR is set while using GitHub App token + if: steps.generate-token.outputs.token && vars.RENOVATE_GIT_AUTHOR + run: | + echo "# :warning: `RENOVATE_GIT_AUTHOR` is set explicitly while using GitHub App token" >> $GITHUB_STEP_SUMMARY + echo "Generally, Renovate automatically detects the git author and email using the token. However, explicitly setting the `RENOVATE_GIT_AUTHOR` will override this behavior." >> $GITHUB_STEP_SUMMARY + + - name: Run Renovate + env: + RENOVATE_PLATFORM_COMMIT: ${{ steps.generate-token.outputs.token && true || false }} + RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN || steps.generate-token.outputs.token }} + RENOVATE_GIT_AUTHOR: ${{ vars.RENOVATE_GIT_AUTHOR }} + run: | + if [ -z "$RENOVATE_TOKEN" ]; then + echo "RENOVATE_TOKEN is not properly configured, skipping ..." + else + renovate $RENOVATE_EXTRA_FLAG + fi diff --git a/.github/workflows/semantic-release.yml b/.github/workflows/semantic-release.yml new file mode 100644 index 0000000..4bd3d94 --- /dev/null +++ b/.github/workflows/semantic-release.yml @@ -0,0 +1,61 @@ +name: Semantic Release + +on: + workflow_run: + workflows: [CI] + types: [completed] + branches: + - master + - beta + - alpha + - '*.x' + +jobs: + semantic-release: + name: Semantic Release + runs-on: ubuntu-22.04 + if: github.event.workflow_run.conclusion == 'success' && github.repository == 'serious-scaffold/ss-pybind11' + permissions: + contents: write + id-token: write + issues: write + pull-requests: write + steps: + - name: Generate a bot token with BOT_APP_ID + id: bot_token + if: vars.BOT_APP_ID && env.BOT_PRIVATE_KEY != null + uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1 + env: + BOT_PRIVATE_KEY: ${{ secrets.BOT_PRIVATE_KEY }} + with: + app-id: ${{ vars.BOT_APP_ID }} + private-key: ${{ secrets.BOT_PRIVATE_KEY }} + + - name: Warn if use GITHUB_TOKEN + if: env._GITHUB_TOKEN == env._TO_BE_VERIFIED_TOKEN + env: + _GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + _TO_BE_VERIFIED_TOKEN: ${{ steps.bot_token.outputs.token || secrets.PAT || secrets.GITHUB_TOKEN }} + run: | + echo "# :warning: GITHUB_TOKEN is used" >> $GITHUB_STEP_SUMMARY + echo "The GITHUB_TOKEN is used instead of a bot token or PAT that will not emit the released publish event for triggering a released workflow." >> $GITHUB_STEP_SUMMARY + + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + with: + fetch-depth: 0 + token: ${{ steps.bot_token.outputs.token || secrets.PAT || secrets.GITHUB_TOKEN }} + + - uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4 + with: + node-version: 20 + + - uses: cycjimmy/semantic-release-action@v4 + id: semantic + with: + semantic_version: 22 + extra_plugins: | + @semantic-release/exec + @semantic-release/github + conventional-changelog-conventionalcommits@7 + env: + GITHUB_TOKEN: ${{ steps.bot_token.outputs.token || secrets.PAT || secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3a78d33 --- /dev/null +++ b/.gitignore @@ -0,0 +1,368 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +build +.build + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# OS specific stuff +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Common editor files +*~ +*.swp + +# Build output for this sample +*.out +/out + +# Python lint or env cache +.nox +.mypy_cache + +# Ignore things from copier +.copier-answers.yml + +# Documenation files +docs/_build + +# Vcpkg integration files +!cmake/vcpkg/**/* + +# setuptools_scm +src/*/_version.py + +# ruff +.ruff_cache/ diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 0000000..a435c58 --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,10 @@ +default: true + +# Multiple headings with the same content +MD024: false +# First line in a file should be a top-level heading +MD041: false +line_length: false +no-hard-tabs: false +whitespace: false +html: false diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..4a21d04 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,151 @@ +# To use: +# +# pre-commit run -a +# +# Or: +# +# pre-commit install # (runs every time you commit in git) +# +# To update this file: +# +# pre-commit autoupdate +# +# See https://github.com/pre-commit/pre-commit + +fail_fast: false +exclude: | + (?x)( + ^(.vscode/.*) + ) +files: '' # set '' as default + +repos: + # Standard hooks + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-added-large-files + args: [--maxkb=4096] + - id: check-case-conflict + - id: check-merge-conflict + - id: check-symlinks + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + - id: name-tests-test + args: [--pytest-test-first] + - id: requirements-txt-fixer + - id: trailing-whitespace + + # Check RST + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.10.0 + hooks: + - id: rst-backticks + - id: rst-directive-colons + - id: rst-inline-touching-normal + + # Strong lint from ruff + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.14 + hooks: + - id: ruff + args: [--fix, --show-fixes] + - id: ruff-format + + # Mypy Check + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.8.0 + hooks: + - id: mypy + files: src|tests + args: [] + additional_dependencies: + - pytest + + # Check yaml + - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v2.14.0 + hooks: + - id: pretty-format-yaml + args: + - --autofix + - --offset=2 + exclude: | + (?x)( + .copier-answers.yml + ) + + # Changes tabs to spaces + - repo: https://github.com/Lucas-C/pre-commit-hooks + rev: v1.5.5 + hooks: + - id: remove-tabs + + # CMake formatting + - repo: https://github.com/cheshirekow/cmake-format-precommit + rev: v0.6.13 + hooks: + - id: cmake-format + additional_dependencies: [pyyaml] + types: [file] + files: (\.cmake|CMakeLists.txt)(.in)?$ + exclude: | + (?x)( + ^(cmake/vcpkg/ports/.*) | + ^(cmake/vcpkg/triplets/.*) | + ^(cmake/vcpkg/scripts/toolchains/.*) + ) + + # Check pyproject + - repo: https://github.com/abravalheri/validate-pyproject + rev: v0.16 + hooks: + - id: validate-pyproject + additional_dependencies: ['validate-pyproject-schema-store[all]'] + + # Check jsonschema + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.27.3 + hooks: + - id: check-dependabot + - id: check-github-workflows + - id: check-readthedocs + + # Check for spelling + - repo: https://github.com/codespell-project/codespell + rev: v2.3.0 + hooks: + - id: codespell + args: + - -L=lang + - --check-filenames + - --write-changes + + # Check for common shell mistakes + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.9.0.6 + hooks: + - id: shellcheck + + # Clang format the codebase automatically + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v18.1.8 + hooks: + - id: clang-format + types_or: [c++, c, cuda] + + # Check for renovate config + - repo: https://github.com/renovatebot/pre-commit-hooks + rev: 38.110.2 + hooks: + - id: renovate-config-validator + stages: [manual] + + - repo: local + hooks: + - id: disallow-caps + name: Disallow improper capitalization + language: pygrep + entry: PyBind|Numpy|Cmake|CCache|Github|PyTest + exclude: .pre-commit-config.yaml diff --git a/.releaserc.js b/.releaserc.js new file mode 100644 index 0000000..f7a2872 --- /dev/null +++ b/.releaserc.js @@ -0,0 +1,67 @@ +module.exports = { + branches: [ + '+([0-9])?(.{+([0-9]),x}).x', + { + name: 'beta', + prerelease: true + }, + { + name: 'alpha', + prerelease: true + }, + 'master', + ], + dryRun: false, + plugins: [ + [ + "@semantic-release/commit-analyzer", + { + preset: "angular", + releaseRules: [ + { breaking: true, release: "major" }, + { type: "feat", release: "minor" }, + { type: "fix", release: "patch" }, + { type: "style", release: false }, + { type: "refactor", release: false }, + { type: "perf", release: "patch" }, + { type: "revert", release: "patch" }, + { type: "chore", release: false }, + { type: "build", release: false }, + { type: "ci", release: false }, + { type: "docs", release: false }, + { type: "test", release: false }, + { scope: '*no-release*', release: false }, + ], + parseOpts: { + noteKeywords: ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"] + }, + }, + ], + [ + "@semantic-release/release-notes-generator", + { + preset: "conventionalcommits", + presetConfig: { + types: [ + { type: "feat", section: "Features" }, + { type: "fix", section: "Bug Fixes" }, + { type: "style", section: "Style" }, + { type: "refactor", section: "Refactor" }, + { type: "perf", section: "Performance" }, + { type: "revert", section: "Reverts" }, + { type: "chore", section: "Chores" }, + { type: "build", section: "Build" }, + { type: "ci", section: "CI" }, + { type: "docs", section: "Docs" }, + { type: "test", section: "Tests" }, + ], + }, + parserOpts: { + headerPattern: "^(\\w*)(?:\\((?:no-release,?)?([\\w\\$\\.\\-\\* ]*)(?:,?no-release)?\\))?\\: (.*)$", + noteKeywords: ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"] + }, + }, + ], + "@semantic-release/github", + ], +}; diff --git a/.renovaterc.json b/.renovaterc.json new file mode 100644 index 0000000..e979925 --- /dev/null +++ b/.renovaterc.json @@ -0,0 +1,176 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:recommended", + "helpers:pinGitHubActionDigests", + ":enablePreCommit", + ], + "automergeType": "pr", + "automergeStrategy": "merge-commit", + "platformAutomerge": true, + "packageRules": [ + { + "matchDepTypes": [ + "action" + ], + "postUpgradeTasks": { + "commands": [ + "find template -type f -exec sed -i -E 's/{{{replace \"/\" \"\\/\" depName}}}(.*)@{{{currentDigest}}} # {{{currentValue}}}/{{{replace \"/\" \"\\/\" depName}}}\\1@{{{newDigest}}} # {{{newValue}}}/g' {} +" + ] + } + }, + { + "matchDepTypes": [ + "github-runner" + ], + "postUpgradeTasks": { + "commands": [ + "find template -type f -exec sed -i 's|{{{depName}}}-{{{currentValue}}}|{{{depName}}}-{{{newValue}}}|g' {} +" + ] + } + }, + { + "matchManagers": [ + "pre-commit" + ], + "postUpgradeTasks": { + "commands": [ + "find template -type f -name '.pre-commit-config.yaml.jinja' -exec sed -i '/{{{replace \"/\" \"\\/\" depName}}}/{N;s/rev: {{{currentValue}}}/rev: {{{newValue}}}/}' {} +" + ] + } + }, + { + "matchDepTypes": [ + "container", + "image", + "image-name", + "service-image" + ], + "postUpgradeTasks": { + "commands": [ + "find template -type f -exec sed -i 's|{{{depName}}}:{{{currentValue}}}@{{{currentDigest}}}|{{{depName}}}:{{{newValue}}}@{{{newDigest}}}|g' {} +" + ] + } + }, + { + "description": "Group vcpkg.json baseline with auto-update", + "groupName": "group vcpkg-baseline", + "extends": ["schedule:automergeMonthly"], + "addLabels": [ + "auto-approval", + "vcpkg-baseline" + ], + "matchDepTypes": [ + "vcpkg-builtin-baseline", + "registration-baseline" + ], + "matchFileNames": [ + "vcpkg.json" + ], + "automerge": true, + "postUpgradeTasks": { + "commands": [ + "find template -type f -name 'vcpkg.json.jinja' -exec sed -i 's|{{{currentDigest}}}|{{{newDigest}}}|g' {} +" + ] + } + }, + { + "description": "Group renovate docker tag and pre-commit-hooks tag", + "groupName": "renovate group", + "extends": ["schedule:automergeMonthly"], + "addLabels": [ + "auto-approval", + "renovate" + ], + "matchDatasources": [ + "docker", + "github-tags" + ], + "automerge": true, + "matchDepNames": [ + "ghcr.io/renovatebot/renovate", + "renovate/renovate", + "renovatebot/pre-commit-hooks" + ] + }, + { + "commitMessageTopic": "serious-scaffold-cpp", + "matchDepTypes": [ + "copier-template" + ], + "postUpgradeTasks": { + "commands": [ + "git stash", + "pip install copier==9.3.1", + "copier update --defaults --vcs-ref {{{newVersion}}}" + ] + }, + "semanticCommitScope": "copier-template" + }, + { + "description": "Group apt packages to avoid failure when multiple packages are outdated.", + "groupName": "apt packages", + "matchDepTypes": [ + "apt" + ] + } + ], + "customManagers": [ + { + "description": "Update python packages installed with pip or pipx", + "customType": "regex", + "datasourceTemplate": "pypi", + "fileMatch": [ + "^\\.github/workflows/.+\\.yml$", + "^\\.renovaterc\\.json$", + "^Makefile$", + "^template/.*?/workflows/.+\\.yml(\\.jinja)?$", + "^template/\\.renovaterc\\.json\\.jinja$", + "^template/Makefile\\.jinja$" + ], + "matchStrings": [ + "pipx? install.* (?.*?)==(?.*?)[\\s\";]" + ] + }, + { + "description": " Update vcpkg.json builtin-baseline with git hash", + "customType": "regex", + "currentValueTemplate": "master", + "datasourceTemplate": "git-refs", + "depNameTemplate": "https://github.com/microsoft/vcpkg", + "depTypeTemplate": "vcpkg-builtin-baseline", + "fileMatch": [ + "^vcpkg\\.json$" + ], + "matchStrings": [ + "\"builtin-baseline\": \"(?.*?)\"" + ] + }, + { + "description": "Update registration baseline with git hash", + "customType": "regex", + "currentValueTemplate": "master", + "datasourceTemplate": "git-refs", + "depTypeTemplate": "registration-baseline", + "fileMatch": [ + "^vcpkg\\.json$" + ], + "matchStrings": [ + "\"baseline\": \"(?.*?)\"[^}]+?\"repository\": \"(?.*?)\"" + ] + }, + { + "customType": "regex", + "datasourceTemplate": "git-tags", + "depNameTemplate": "https://github.com/serious-scaffold/ss-pybind11.git", + "depTypeTemplate": "copier-template", + "fileMatch": [ + "^\\.copier-answers\\.yml$" + ], + "matchStrings": [ + "_commit: (?.*?)\n" + ], + "versioningTemplate": "semver" + } + ] +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..bad5311 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,32 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${command:cmake.launchTargetPath}", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ] + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6f41f5f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,107 @@ +{ + "python.testing.pytestArgs": ["tests"], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true, + "cmake.useCMakePresets": "always", + "cmake.options.statusBarVisibility": "compact", + "files.exclude": { + "**/.clangd/**": true + }, + "files.watcherExclude": { + "**/.clangd/**": true + }, + "files.associations": { + "iosfwd": "cpp", + "type_traits": "cpp", + "algorithm": "cpp", + "any": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "cinttypes": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "deque": "cpp", + "exception": "cpp", + "filesystem": "cpp", + "format": "cpp", + "forward_list": "cpp", + "fstream": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iostream": "cpp", + "istream": "cpp", + "iterator": "cpp", + "limits": "cpp", + "list": "cpp", + "locale": "cpp", + "map": "cpp", + "memory": "cpp", + "mutex": "cpp", + "new": "cpp", + "numeric": "cpp", + "optional": "cpp", + "ostream": "cpp", + "queue": "cpp", + "random": "cpp", + "ranges": "cpp", + "ratio": "cpp", + "set": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "string": "cpp", + "system_error": "cpp", + "thread": "cpp", + "tuple": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "utility": "cpp", + "variant": "cpp", + "vector": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xstddef": "cpp", + "xstring": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp", + "string_view": "cpp", + "*.tcc": "cpp", + "cwctype": "cpp", + "memory_resource": "cpp", + "numbers": "cpp", + "semaphore": "cpp", + "codecvt": "cpp", + "source_location": "cpp" + } +} diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..30a8de7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 3.25) +message(STATUS "CMAKE VERSION:${CMAKE_VERSION}") + +if(NOT DEFINED SKBUILD_PROJECT_NAME) + set(SKBUILD_PROJECT_NAME _core) + set(SKBUILD_PROJECT_VERSION 0.0.0) +endif() + +project( + ${SKBUILD_PROJECT_NAME} + VERSION ${SKBUILD_PROJECT_VERSION} + LANGUAGES C CXX) + +set(CMAKE_CXX_STANDARD + 20 + CACHE STRING "C++ standard") +set(CMAKE_CXX_STANDARD_REQUIRED + ON + CACHE BOOL "C++ standard required") +set(CMAKE_CXX_EXTENSIONS + OFF + CACHE BOOL "C++ extensions") + +# Project default module +find_package(cmake-modules REQUIRED) +include(cmake-modules/ProjectDefault) + +# Project custom modules +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +include(ConfigureWarningsAndHardening) +include(ConfigureVersion) + +add_subdirectory(src) diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..19edd87 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,19 @@ +{ + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 25, + "patch": 0 + }, + "include": [ + "cmake/presets/default.json", + "cmake/presets/x64-linux-llvm.json", + "cmake/presets/x64-linux-gcc.json", + "cmake/presets/x64-mingw-dynamic-windows-mingw.json", + "cmake/presets/x64-mingw-static-windows-mingw.json", + "cmake/presets/x64-osx-gcc.json", + "cmake/presets/x64-osx-llvm.json", + "cmake/presets/x64-windows-llvm.json", + "cmake/presets/x64-windows-msvc.json" + ] +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b11515f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Serious Scaffold + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..15e68f4 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# Serious Scaffold Pybind11 + + + +A template of serious scaffold family based on pybind11. + +[![Documentation](https://img.shields.io/badge/Documentation-sphinx-blue)](https://serious-scaffold.github.io/ss-pybind11) +[![License](https://img.shields.io/github/license/serious-scaffold/ss-pybind11)](https://github.com/serious-scaffold/ss-pybind11/blob/master/LICENSE) +[![SS Badge](https://img.shields.io/badge/Serious%20Scaffold-pybind11-blue)](https://github.com/serious-scaffold/ss-pybind11) + +[![CI](https://github.com/serious-scaffold/ss-pybind11/actions/workflows/ci.yml/badge.svg)](https://github.com/serious-scaffold/ss-pybind11/actions/workflows/ci.yml) +[![CD](https://github.com/serious-scaffold/ss-pybind11/actions/workflows/cd.yml/badge.svg)](https://github.com/serious-scaffold/ss-pybind11/actions/workflows/cd.yml) +[![Renovate](https://github.com/serious-scaffold/ss-pybind11/actions/workflows/renovate.yml/badge.svg)](https://github.com/serious-scaffold/ss-pybind11/actions/workflows/renovate.yml) +[![Semantic Release](https://github.com/serious-scaffold/ss-pybind11/actions/workflows/semantic-release.yml/badge.svg)](https://github.com/serious-scaffold/ss-pybind11/actions/workflows/semantic-release.yml) +[![codecov](https://codecov.io/gh/serious-scaffold/ss-pybind11/branch/master/graph/badge.svg?token=123456789)](https://codecov.io/gh/serious-scaffold/ss-pybind11) +[![Release](https://img.shields.io/github/v/release/serious-scaffold/ss-pybind11)](https://github.com/serious-scaffold/ss-pybind11/releases) + +[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit) +[![clang-format](https://img.shields.io/badge/clang--format-enabled-blue)](https://github.com/pre-commit/mirrors-clang-format) +[![cmake-format](https://img.shields.io/badge/cmake--format-enabled-blue)](https://github.com/cheshirekow/cmake-format-precommit) +[![codespell](https://img.shields.io/badge/codespell-enabled-blue)](https://github.com/codespell-project/codespell) +[![markdownlint](https://img.shields.io/badge/markdownlint-enabled-blue)](https://github.com/igorshubovych/markdownlint-cli) +[![shellcheck](https://img.shields.io/badge/shellcheck-enabled-blue)](https://github.com/shellcheck-py/shellcheck-py) + +## Features + +- Project setup and template update with [copier](https://github.com/copier-org/copier/). +- Containerization for development and deployment with [dev container](https://containers.dev/). +- Continuous Integration with [GitHub Actions](https://docs.github.com/actions). +- Automate dependency updates with [Renovate](https://github.com/renovatebot/renovate). +- Use [cmake-registry](https://github.com/msclock/cmake-registry) to provide various cmake modules and scripts. +- Lint tool `pre-commit` integration with various linters, including [clang-format](https://github.com/pre-commit/mirrors-clang-format), [codespell](https://github.com/codespell-project/codespell), [markdownlint](https://github.com/igorshubovych/markdownlint-cli), and more. +- Handy Makefile for local development. +- Documentation generation with [sphinx](https://www.sphinx-doc.org/en/master/)[[furo](https://github.com/pradyunsg/furo)] or [mkdocs](https://www.mkdocs.org/)[[material](https://squidfunk.github.io/mkdocs-material/)]. +- Automatic release workflow with [semantic-release](https://github.com/semantic-release/semantic-release). +- Maintainable [documentation](https://serious-scaffold.github.io/ss-pybind11/) guides for configuration, development, security and contribution based on ss-pybind11. + +## License + +MIT License, for more details, see the [LICENSE](https://github.com/serious-scaffold/ss-pybind11/blob/master/LICENSE) file. diff --git a/cmake/ConfigureVersion.cmake b/cmake/ConfigureVersion.cmake new file mode 100644 index 0000000..569c2ea --- /dev/null +++ b/cmake/ConfigureVersion.cmake @@ -0,0 +1,48 @@ +#[[ +This file detects the git commit information and sets the version number accordingly. + +Detected variables: + - CMAKE_PROJECT_GIT_COMMIT_*: git commit information (see below) + - CMAKE_PROJECT_VERSION: version number (major.minor.patch.tweak) + - CMAKE_PROJECT_VERSION_: version numbers (as integers) + +]] + +include_guard(GLOBAL) +include(cmake-modules/configure/GitTools) + +find_package(robotology-cmake-ycm REQUIRED) +include(robotology-cmake-ycm/modules/GitInfo) +include(robotology-cmake-ycm/modules/ExtractVersion) + +# Retrieve the git commit information to CMAKE_PROJECT_GIT_WT_* variables +git_wt_info(SOURCE_DIR ${CMAKE_SOURCE_DIR} PREFIX CMAKE_PROJECT) + +# Rename CMAKE_PROJECT_GIT_WT_* variables to CMAKE_PROJECT_GIT_COMMIT_* +# variables +get_cmake_property(_vars VARIABLES) +foreach(_var IN LISTS _vars) + if(_var MATCHES "^CMAKE_PROJECT_GIT_WT_") + string(REGEX REPLACE "^CMAKE_PROJECT_GIT_WT_" "CMAKE_PROJECT_GIT_COMMIT_" + new_name "${_var}") + set(${new_name} "${${_var}}") + unset(new_name) + endif() +endforeach() + +# Set the CMAKE_PROJECT_VERSION variable +if(NOT CMAKE_PROJECT_GIT_COMMIT_TAG) + set(CMAKE_PROJECT_VERSION "0.0.0.0") +else() + set(CMAKE_PROJECT_VERSION "${CMAKE_PROJECT_GIT_COMMIT_TAG}") + + if(CMAKE_PROJECT_GIT_COMMIT_TAG_REVISION) + set(CMAKE_PROJECT_VERSION + "${CMAKE_PROJECT_VERSION}.${CMAKE_PROJECT_GIT_COMMIT_TAG_REVISION}") + endif() + + string(REGEX REPLACE "^v" "" CMAKE_PROJECT_VERSION "${CMAKE_PROJECT_VERSION}") +endif() + +# Set the CMAKE_PROJECT_VERSION_ variables +extract_version(CMAKE_PROJECT CMAKE_PROJECT REVERSE_NAME) diff --git a/cmake/ConfigureWarningsAndHardening.cmake b/cmake/ConfigureWarningsAndHardening.cmake new file mode 100644 index 0000000..784fd89 --- /dev/null +++ b/cmake/ConfigureWarningsAndHardening.cmake @@ -0,0 +1,117 @@ +#[[ +This file configures the following things: + - dynamic tools: sanitizers, valgrind. + - static tools: clang-tidy, cppcheck. + - compiler flags + - hardening options + +]] + +include_guard(GLOBAL) + +# ############################################################################## +# Sanitizer +# ############################################################################## + +set(USE_SANITIZER + OFF + CACHE BOOL "Enable sanitizer") + +include(cmake-modules/build/Sanitizer) + +# ############################################################################## +# Valgrind +# ############################################################################## + +set(USE_VALGRIND + OFF + CACHE BOOL "Enable Valgrind") +set(USE_VALGRIND_OPTIONS + --leak-check=full # Each individual leak will be shown in detail. + --show-leak-kinds=all # Show all of "definite, indirect, possible, + # reachable" leak kinds in the "full" report. + --gen-suppressions=all # gen suppress info automatically. + --track-origins=yes # Favor useful output over speed. This tracks the + # origins of uninitialized values, which could be very + # useful for memory errors. Consider turning off if + # Valgrind is unacceptably slow. + CACHE STRING "valgrind options.") + +include(cmake-modules/test/Valgrind) + +# ############################################################################## +# Clang-Tidy +# ############################################################################## + +set(USE_CLANGTIDY + OFF + CACHE BOOL "Enable Clang-Tidy") + +include(cmake-modules/build/ClangTidy) + +# ############################################################################## +# Cppcheck +# ############################################################################## + +set(USE_CPPCHECK + OFF + CACHE BOOL "Enable Cppcheck") +set(USE_CPPCHECK_SUPPRESSION_FILE + ${CMAKE_SOURCE_DIR}/.cppcheck-suppressions.txt + CACHE STRING + "Customize the path to the Cppcheck suppressions file of the project") + +include(cmake-modules/build/Cppcheck) + +# ############################################################################## +# CompilerFlags +# ############################################################################## + +include(cmake-modules/build/CompilerFlags) + +# ############################################################################## +# Hardening +# ############################################################################## + +set(USE_HARDENING_FLAGS + -D_GLIBCXX_ASSERTIONS # Enable assertions + -U_FORTIFY_SOURCE # Disable stack protector + -D_FORTIFY_SOURCE=3 # Enable stack protector + -fstack-protector-strong # Enable stack protector + -fcf-protection # Control Flow Guard + -fstack-clash-protection # Control Flow Guard + -Wimplicit-fallthrough # Enabled in compiler flags by default + -fstrict-flex-arrays=3 # Enable strict array bounds + -Wformat # Enabled in compiler flags by default + -Wformat=2 # Enabled in compiler flags by default + # -Wl,-z,nodlopen # Restrict dlopen(3) calls to shared objects + -Wl,-z,noexecstack # Enable data execution prevention by marking stack + # memory as non-executable + -Wl,-z,relro # Mark relocation table entries resolved at load-time as + # read-only + -Wl,-z,now # Mark relocation table entries resolved at load-time as + # read-only. It impacts startup performance + "-fsanitize=undefined -fsanitize-minimal-runtime" # Enable minimal runtime + # undefined behavior sanitizer + -fno-delete-null-pointer-checks + -fno-strict-overflow + -fno-strict-aliasing + -ftrivial-auto-var-init=zero + -Wtrampolines # Enable trampolines(gcc only) + -mbranch-protection=standard # Enable indirect branches(aarch64 only) + CACHE STRING "Additional hardening compilation flags for GCC/Clang") + +set(USE_HARDENING_LINKS + -fstack-protector-strong # Enable stack protector + "-fsanitize=undefined -fsanitize-minimal-runtime" # Enable minimal runtime + # undefined behavior sanitizer -Wl,-z,nodlopen # Restrict dlopen(3) calls to + # shared objects + -Wl,-z,noexecstack # Enable data execution prevention by marking stack + # memory as non-executable + -Wl,-z,relro # Mark relocation table entries resolved at load-time as + # read-only + -Wl,-z,now # Mark relocation table entries resolved at load-time as + # read-only. It impacts startup performance + CACHE STRING "Additional hardening linking flags for GCC/Clang") + +include(cmake-modules/build/Hardening) diff --git a/cmake/presets/arch/x64.json b/cmake/presets/arch/x64.json new file mode 100644 index 0000000..e7ea25b --- /dev/null +++ b/cmake/presets/arch/x64.json @@ -0,0 +1,20 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "x64", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "toolset": { + "value": "host=x64", + "strategy": "external" + }, + "hidden": true, + "cacheVariables": { + "VCPKG_TARGET_ARCHITECTURE": "x64" + } + } + ] +} diff --git a/cmake/presets/base.json b/cmake/presets/base.json new file mode 100644 index 0000000..e929d27 --- /dev/null +++ b/cmake/presets/base.json @@ -0,0 +1,48 @@ +{ + "version": 6, + "include": [ + "generators/ninja.json", + "toolchains/vcpkg.json" + ], + "configurePresets": [ + { + "name": "base", + "hidden": true, + "inherits": [ + "ninja", + "vcpkg" + ], + "binaryDir": "${sourceDir}/out/build/${presetName}", + "installDir": "${sourceDir}/out/install/${presetName}", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": true, + "CMAKE_COMPILE_WARNING_AS_ERROR": false, + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_VERBOSE_MAKEFILE": "FALSE" + } + } + ], + "buildPresets": [ + { + "name": "base", + "hidden": true, + "inherits": "ninja", + "configurePreset": "base" + } + ], + "testPresets": [ + { + "name": "base", + "hidden": true, + "inherits": "ninja", + "configurePreset": "base", + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": true + } + } + ] +} diff --git a/cmake/presets/compilers/gcc.json b/cmake/presets/compilers/gcc.json new file mode 100644 index 0000000..d920fb4 --- /dev/null +++ b/cmake/presets/compilers/gcc.json @@ -0,0 +1,13 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "gcc", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++" + } + } + ] +} diff --git a/cmake/presets/compilers/llvm.json b/cmake/presets/compilers/llvm.json new file mode 100644 index 0000000..5172325 --- /dev/null +++ b/cmake/presets/compilers/llvm.json @@ -0,0 +1,21 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "llvm", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++" + } + }, + { + "name": "llvm-cl", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "clang-cl.exe", + "CMAKE_CXX_COMPILER": "clang-cl.exe" + } + } + ] +} diff --git a/cmake/presets/compilers/mingw.json b/cmake/presets/compilers/mingw.json new file mode 100644 index 0000000..302a898 --- /dev/null +++ b/cmake/presets/compilers/mingw.json @@ -0,0 +1,9 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "mingw", + "hidden": true + } + ] +} diff --git a/cmake/presets/compilers/msvc.json b/cmake/presets/compilers/msvc.json new file mode 100644 index 0000000..712dce1 --- /dev/null +++ b/cmake/presets/compilers/msvc.json @@ -0,0 +1,18 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "msvc", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "cl", + "CMAKE_CXX_COMPILER": "cl" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + } + ] +} diff --git a/cmake/presets/default.json b/cmake/presets/default.json new file mode 100644 index 0000000..6905bcb --- /dev/null +++ b/cmake/presets/default.json @@ -0,0 +1,47 @@ +{ + "version": 6, + "include": [ + "base.json" + ], + "configurePresets": [ + { + "name": "default", + "inherits": [ + "base" + ] + } + ], + "buildPresets": [ + { + "name": "default", + "inherits": "base", + "configurePreset": "default" + } + ], + "testPresets": [ + { + "name": "default", + "inherits": "base", + "configurePreset": "default" + } + ], + "workflowPresets": [ + { + "name": "default", + "steps": [ + { + "type": "configure", + "name": "default" + }, + { + "type": "build", + "name": "default" + }, + { + "type": "test", + "name": "default" + } + ] + } + ] +} diff --git a/cmake/presets/generators/ninja.json b/cmake/presets/generators/ninja.json new file mode 100644 index 0000000..3f639a9 --- /dev/null +++ b/cmake/presets/generators/ninja.json @@ -0,0 +1,41 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "ninja", + "hidden": true, + "generator": "Ninja" + }, + { + "name": "ninja-multi-config", + "hidden": true, + "generator": "Ninja Multi-Config" + } + ], + "buildPresets": [ + { + "name": "ninja", + "hidden": true, + "configurePreset": "ninja" + }, + { + "name": "ninja-multi-config", + "hidden": true, + "configurePreset": "ninja-multi-config", + "configuration": "RelWithDebInfo" + } + ], + "testPresets": [ + { + "name": "ninja", + "hidden": true, + "configurePreset": "ninja" + }, + { + "name": "ninja-multi-config", + "hidden": true, + "configurePreset": "ninja-multi-config", + "configuration": "RelWithDebInfo" + } + ] +} diff --git a/cmake/presets/os/darwin.json b/cmake/presets/os/darwin.json new file mode 100644 index 0000000..e3f3fbe --- /dev/null +++ b/cmake/presets/os/darwin.json @@ -0,0 +1,28 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "darwin", + "hidden": true, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + } + ], + "buildPresets": [ + { + "name": "darwin", + "hidden": true, + "configurePreset": "darwin" + } + ], + "testPresets": [ + { + "name": "darwin", + "hidden": true, + "configurePreset": "darwin" + } + ] +} diff --git a/cmake/presets/os/linux.json b/cmake/presets/os/linux.json new file mode 100644 index 0000000..684e078 --- /dev/null +++ b/cmake/presets/os/linux.json @@ -0,0 +1,28 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "linux", + "hidden": true, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + } + ], + "buildPresets": [ + { + "name": "linux", + "hidden": true, + "configurePreset": "linux" + } + ], + "testPresets": [ + { + "name": "linux", + "hidden": true, + "configurePreset": "linux" + } + ] +} diff --git a/cmake/presets/os/windows.json b/cmake/presets/os/windows.json new file mode 100644 index 0000000..9f78bad --- /dev/null +++ b/cmake/presets/os/windows.json @@ -0,0 +1,28 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "windows", + "hidden": true, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + } + ], + "buildPresets": [ + { + "name": "windows", + "hidden": true, + "configurePreset": "windows" + } + ], + "testPresets": [ + { + "name": "windows", + "hidden": true, + "configurePreset": "windows" + } + ] +} diff --git a/cmake/presets/toolchains/vcpkg.json b/cmake/presets/toolchains/vcpkg.json new file mode 100644 index 0000000..3e8ec67 --- /dev/null +++ b/cmake/presets/toolchains/vcpkg.json @@ -0,0 +1,16 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "vcpkg", + "hidden": true, + "toolchainFile": "${sourceDir}/cmake/vcpkg/vcpkg.toolchain.cmake", + "cacheVariables": { + "VCPKG_INSTALL_OPTIONS": "--no-print-usage", + "VCPKG_MANIFEST_FEATURES": "test", + "VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/cmake/vcpkg/triplets", + "VCPKG_OVERLAY_PORTS": "${sourceDir}/cmake/vcpkg/ports" + } + } + ] +} diff --git a/cmake/presets/triplets/x64-linux.json b/cmake/presets/triplets/x64-linux.json new file mode 100644 index 0000000..dcbccbd --- /dev/null +++ b/cmake/presets/triplets/x64-linux.json @@ -0,0 +1,18 @@ +{ + "version": 6, + "include": [ + "../arch/x64.json" + ], + "configurePresets": [ + { + "name": "x64-linux", + "hidden": true, + "inherits": [ + "x64" + ], + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-linux" + } + } + ] +} diff --git a/cmake/presets/triplets/x64-mingw-dynamic.json b/cmake/presets/triplets/x64-mingw-dynamic.json new file mode 100644 index 0000000..672dde6 --- /dev/null +++ b/cmake/presets/triplets/x64-mingw-dynamic.json @@ -0,0 +1,18 @@ +{ + "version": 6, + "include": [ + "../arch/x64.json" + ], + "configurePresets": [ + { + "name": "x64-mingw-dynamic", + "hidden": true, + "inherits": [ + "x64" + ], + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-mingw-dynamic" + } + } + ] +} diff --git a/cmake/presets/triplets/x64-mingw-static.json b/cmake/presets/triplets/x64-mingw-static.json new file mode 100644 index 0000000..49fb429 --- /dev/null +++ b/cmake/presets/triplets/x64-mingw-static.json @@ -0,0 +1,18 @@ +{ + "version": 6, + "include": [ + "../arch/x64.json" + ], + "configurePresets": [ + { + "name": "x64-mingw-static", + "hidden": true, + "inherits": [ + "x64" + ], + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-mingw-static" + } + } + ] +} diff --git a/cmake/presets/triplets/x64-osx.json b/cmake/presets/triplets/x64-osx.json new file mode 100644 index 0000000..bc0c0d3 --- /dev/null +++ b/cmake/presets/triplets/x64-osx.json @@ -0,0 +1,18 @@ +{ + "version": 6, + "include": [ + "../arch/x64.json" + ], + "configurePresets": [ + { + "name": "x64-osx", + "hidden": true, + "inherits": [ + "x64" + ], + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-osx" + } + } + ] +} diff --git a/cmake/presets/triplets/x64-windows.json b/cmake/presets/triplets/x64-windows.json new file mode 100644 index 0000000..929700c --- /dev/null +++ b/cmake/presets/triplets/x64-windows.json @@ -0,0 +1,18 @@ +{ + "version": 6, + "include": [ + "../arch/x64.json" + ], + "configurePresets": [ + { + "name": "x64-windows", + "hidden": true, + "inherits": [ + "x64" + ], + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-windows" + } + } + ] +} diff --git a/cmake/presets/x64-linux-gcc.json b/cmake/presets/x64-linux-gcc.json new file mode 100644 index 0000000..fdbc879 --- /dev/null +++ b/cmake/presets/x64-linux-gcc.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/linux.json", + "compilers/gcc.json", + "triplets/x64-linux.json" + ], + "configurePresets": [ + { + "name": "x64-linux-gcc", + "inherits": [ + "base", + "linux", + "gcc", + "x64-linux" + ] + } + ], + "buildPresets": [ + { + "name": "x64-linux-gcc", + "inherits": "base", + "configurePreset": "x64-linux-gcc" + } + ], + "testPresets": [ + { + "name": "x64-linux-gcc", + "inherits": "base", + "configurePreset": "x64-linux-gcc" + } + ], + "workflowPresets": [ + { + "name": "x64-linux-gcc", + "steps": [ + { + "type": "configure", + "name": "x64-linux-gcc" + }, + { + "type": "build", + "name": "x64-linux-gcc" + }, + { + "type": "test", + "name": "x64-linux-gcc" + } + ] + } + ] +} diff --git a/cmake/presets/x64-linux-llvm.json b/cmake/presets/x64-linux-llvm.json new file mode 100644 index 0000000..cc9b605 --- /dev/null +++ b/cmake/presets/x64-linux-llvm.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/linux.json", + "compilers/llvm.json", + "triplets/x64-linux.json" + ], + "configurePresets": [ + { + "name": "x64-linux-llvm", + "inherits": [ + "base", + "linux", + "llvm", + "x64-linux" + ] + } + ], + "buildPresets": [ + { + "name": "x64-linux-llvm", + "inherits": "base", + "configurePreset": "x64-linux-llvm" + } + ], + "testPresets": [ + { + "name": "x64-linux-llvm", + "inherits": "base", + "configurePreset": "x64-linux-llvm" + } + ], + "workflowPresets": [ + { + "name": "x64-linux-llvm", + "steps": [ + { + "type": "configure", + "name": "x64-linux-llvm" + }, + { + "type": "build", + "name": "x64-linux-llvm" + }, + { + "type": "test", + "name": "x64-linux-llvm" + } + ] + } + ] +} diff --git a/cmake/presets/x64-mingw-dynamic-windows-mingw.json b/cmake/presets/x64-mingw-dynamic-windows-mingw.json new file mode 100644 index 0000000..bae53dc --- /dev/null +++ b/cmake/presets/x64-mingw-dynamic-windows-mingw.json @@ -0,0 +1,54 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/windows.json", + "compilers/mingw.json", + "triplets/x64-mingw-dynamic.json" + ], + "configurePresets": [ + { + "name": "x64-mingw-dynamic-windows-mingw", + "inherits": [ + "base", + "windows", + "mingw", + "x64-mingw-dynamic" + ] + + } + ], + "buildPresets": [ + { + "name": "x64-mingw-dynamic-windows-mingw", + "inherits": "base", + "configurePreset": "x64-mingw-dynamic-windows-mingw" + } + ], + "testPresets": [ + { + "name": "x64-mingw-dynamic-windows-mingw", + "inherits": "base", + "configurePreset": "x64-mingw-dynamic-windows-mingw" + } + ], + "workflowPresets": [ + { + "name": "x64-mingw-dynamic-windows-mingw", + "steps": [ + { + "type": "configure", + "name": "x64-mingw-dynamic-windows-mingw" + }, + { + "type": "build", + "name": "x64-mingw-dynamic-windows-mingw" + }, + { + "type": "test", + "name": "x64-mingw-dynamic-windows-mingw" + } + ] + } + ] +} diff --git a/cmake/presets/x64-mingw-static-windows-mingw.json b/cmake/presets/x64-mingw-static-windows-mingw.json new file mode 100644 index 0000000..31a6f44 --- /dev/null +++ b/cmake/presets/x64-mingw-static-windows-mingw.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/windows.json", + "compilers/mingw.json", + "triplets/x64-mingw-static.json" + ], + "configurePresets": [ + { + "name": "x64-mingw-static-windows-mingw", + "inherits": [ + "base", + "windows", + "mingw", + "x64-mingw-static" + ] + } + ], + "buildPresets": [ + { + "name": "x64-mingw-static-windows-mingw", + "inherits": "base", + "configurePreset": "x64-mingw-static-windows-mingw" + } + ], + "testPresets": [ + { + "name": "x64-mingw-static-windows-mingw", + "inherits": "base", + "configurePreset": "x64-mingw-static-windows-mingw" + } + ], + "workflowPresets": [ + { + "name": "x64-mingw-static-windows-mingw", + "steps": [ + { + "type": "configure", + "name": "x64-mingw-static-windows-mingw" + }, + { + "type": "build", + "name": "x64-mingw-static-windows-mingw" + }, + { + "type": "test", + "name": "x64-mingw-static-windows-mingw" + } + ] + } + ] +} diff --git a/cmake/presets/x64-osx-gcc.json b/cmake/presets/x64-osx-gcc.json new file mode 100644 index 0000000..405af6c --- /dev/null +++ b/cmake/presets/x64-osx-gcc.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/darwin.json", + "compilers/gcc.json", + "triplets/x64-osx.json" + ], + "configurePresets": [ + { + "name": "x64-osx-gcc", + "inherits": [ + "base", + "darwin", + "gcc", + "x64-osx" + ] + } + ], + "buildPresets": [ + { + "name": "x64-osx-gcc", + "inherits": "base", + "configurePreset": "x64-osx-gcc" + } + ], + "testPresets": [ + { + "name": "x64-osx-gcc", + "inherits": "base", + "configurePreset": "x64-osx-gcc" + } + ], + "workflowPresets": [ + { + "name": "x64-osx-gcc", + "steps": [ + { + "type": "configure", + "name": "x64-osx-gcc" + }, + { + "type": "build", + "name": "x64-osx-gcc" + }, + { + "type": "test", + "name": "x64-osx-gcc" + } + ] + } + ] +} diff --git a/cmake/presets/x64-osx-llvm.json b/cmake/presets/x64-osx-llvm.json new file mode 100644 index 0000000..fc43d06 --- /dev/null +++ b/cmake/presets/x64-osx-llvm.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/darwin.json", + "compilers/llvm.json", + "triplets/x64-osx.json" + ], + "configurePresets": [ + { + "name": "x64-osx-llvm", + "inherits": [ + "base", + "darwin", + "llvm", + "x64-osx" + ] + } + ], + "buildPresets": [ + { + "name": "x64-osx-llvm", + "inherits": "base", + "configurePreset": "x64-osx-llvm" + } + ], + "testPresets": [ + { + "name": "x64-osx-llvm", + "inherits": "base", + "configurePreset": "x64-osx-llvm" + } + ], + "workflowPresets": [ + { + "name": "x64-osx-llvm", + "steps": [ + { + "type": "configure", + "name": "x64-osx-llvm" + }, + { + "type": "build", + "name": "x64-osx-llvm" + }, + { + "type": "test", + "name": "x64-osx-llvm" + } + ] + } + ] +} diff --git a/cmake/presets/x64-windows-llvm.json b/cmake/presets/x64-windows-llvm.json new file mode 100644 index 0000000..04acc62 --- /dev/null +++ b/cmake/presets/x64-windows-llvm.json @@ -0,0 +1,56 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/windows.json", + "compilers/llvm.json", + "triplets/x64-windows.json" + ], + "configurePresets": [ + { + "name": "x64-windows-llvm", + "inherits": [ + "base", + "windows", + "llvm-cl", + "x64-windows" + ], + "cacheVariables": { + "USE_SANITIZER": "OFF" + } + } + ], + "buildPresets": [ + { + "name": "x64-windows-llvm", + "inherits": "base", + "configurePreset": "x64-windows-llvm" + } + ], + "testPresets": [ + { + "name": "x64-windows-llvm", + "inherits": "base", + "configurePreset": "x64-windows-llvm" + } + ], + "workflowPresets": [ + { + "name": "x64-windows-llvm", + "steps": [ + { + "type": "configure", + "name": "x64-windows-llvm" + }, + { + "type": "build", + "name": "x64-windows-llvm" + }, + { + "type": "test", + "name": "x64-windows-llvm" + } + ] + } + ] +} diff --git a/cmake/presets/x64-windows-msvc.json b/cmake/presets/x64-windows-msvc.json new file mode 100644 index 0000000..f63a964 --- /dev/null +++ b/cmake/presets/x64-windows-msvc.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/windows.json", + "compilers/msvc.json", + "triplets/x64-windows.json" + ], + "configurePresets": [ + { + "name": "x64-windows-msvc", + "inherits": [ + "base", + "windows", + "msvc", + "x64-windows" + ] + } + ], + "buildPresets": [ + { + "name": "x64-windows-msvc", + "inherits": "base", + "configurePreset": "x64-windows-msvc" + } + ], + "testPresets": [ + { + "name": "x64-windows-msvc", + "inherits": "base", + "configurePreset": "x64-windows-msvc" + } + ], + "workflowPresets": [ + { + "name": "x64-windows-msvc", + "steps": [ + { + "type": "configure", + "name": "x64-windows-msvc" + }, + { + "type": "build", + "name": "x64-windows-msvc" + }, + { + "type": "test", + "name": "x64-windows-msvc" + } + ] + } + ] +} diff --git a/cmake/vcpkg/bootstrap/vcpkg-config.cmake b/cmake/vcpkg/bootstrap/vcpkg-config.cmake new file mode 100644 index 0000000..869092b --- /dev/null +++ b/cmake/vcpkg/bootstrap/vcpkg-config.cmake @@ -0,0 +1,20 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +include_guard(GLOBAL) + +# CMAKE_HOST_* variables are not available during first configure on windows. +cmake_host_system_information(RESULT __vcpkg_bootstrap_host QUERY OS_NAME) +cmake_host_system_information(RESULT __vcpkg_bootstrap_arch QUERY OS_PLATFORM) + +set(__vcpkg_bootstrap_list_dir "${CMAKE_CURRENT_LIST_DIR}") + +include(${__vcpkg_bootstrap_list_dir}/vcpkg_skip_install_on_reconfigure.cmake) +include(${__vcpkg_bootstrap_list_dir}/vcpkg_bootstrap.cmake) +include(${__vcpkg_bootstrap_list_dir}/vcpkg_chainload_toolchain.cmake) +include(${__vcpkg_bootstrap_list_dir}/vcpkg_load_triplet.cmake) +include(${__vcpkg_bootstrap_list_dir}/vcpkg_export_mode.cmake) +include(${__vcpkg_bootstrap_list_dir}/vcpkg_configure.cmake) diff --git a/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake b/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake new file mode 100644 index 0000000..ba599f4 --- /dev/null +++ b/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake @@ -0,0 +1,205 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +# stash all local changes +function(_vcpkg_stash vcpkg_root) + message(STATUS "vcpkg stash all local changes") + + execute_process( + COMMAND ${GIT_EXECUTABLE} stash + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message(FATAL_ERROR "${GIT_EXECUTABLE} stash failed with ${result}") + endif() +endfunction() + +# checkout to a specific baseline +function(_vcpkg_checkout vcpkg_root vcpkg_ref) + message(STATUS "vcpkg checkout to ${vcpkg_ref}") + + execute_process( + COMMAND ${GIT_EXECUTABLE} fetch origin ${vcpkg_ref} + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message( + FATAL_ERROR "${GIT_EXECUTABLE} fetch ${vcpkg_ref} failed with ${result}") + endif() + + execute_process( + COMMAND ${GIT_EXECUTABLE} checkout ${vcpkg_ref} + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message( + FATAL_ERROR + "${GIT_EXECUTABLE} checkout ${vcpkg_ref} failed with ${result}") + endif() +endfunction() + +# clone +function(_vcpkg_clone vcpkg_root vcpkg_repo vcpkg_ref) + execute_process( + COMMAND ${GIT_EXECUTABLE} clone ${vcpkg_repo} ${vcpkg_root} --depth=1 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message(FATAL_ERROR "failed to clone ${vcpkg_repo} to ${vcpkg_root}") + endif() + + file(LOCK "${vcpkg_root}" DIRECTORY) + _vcpkg_checkout(${vcpkg_root} ${vcpkg_ref}) +endfunction() + +# bootstrap +function(_vcpkg_tool_bootstrap vcpkg_root) + message(STATUS "Bootstrap vckpg tool") + + if("${__vcpkg_bootstrap_host}" STREQUAL "Windows") + set(bootstrap_cmd "${vcpkg_root}/bootstrap-vcpkg.bat") + else() + set(bootstrap_cmd "${vcpkg_root}/bootstrap-vcpkg.sh") + endif() + + execute_process( + COMMAND ${bootstrap_cmd} -disableMetrics + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + if(CMAKE_HOST_UNIX) + message(STATUS "Retry to build vcpkg from source...") + set(bootstrap_impl "${vcpkg_root}/scripts/bootstrap.sh") + file(READ "${bootstrap_impl}" file_contents) + string(REPLACE [[elif [ "$ARCH" = "x86_64" ]; then]] + [[elif [ "$ARCH" = "" ]; then]] file_contents + "${file_contents}") + file(WRITE "${bootstrap_impl}" "${file_contents}") + + execute_process( + COMMAND ${bootstrap_cmd} -disableMetrics + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + endif() + + if(NOT result EQUAL "0") + message(FATAL_ERROR "${bootstrap_cmd} failed with ${result}") + endif() + endif() +endfunction() + +# upgrade +function(_vcpkg_upgrade vcpkg_root vcpkg_repo vcpkg_ref) + file(LOCK "${vcpkg_root}" DIRECTORY) + + if(NOT EXISTS "${vcpkg_root}/.git") + message(WARNING "vcpkg not found in git work tree, skipping upgrade") + return() + endif() + + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse HEAD + WORKING_DIRECTORY ${vcpkg_root} + OUTPUT_VARIABLE current_git_hash + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message( + FATAL_ERROR "${GIT_EXECUTABLE} rev-parse HEAD failed with ${result}") + endif() + + if("${current_git_hash}" STREQUAL "${vcpkg_ref}") + return() + endif() + + message(STATUS "Upgrade vcpkg") + message(STATUS "vcpkg current commit: ${current_git_hash}") + message(STATUS "vcpkg release: ${vcpkg_ref}") + + execute_process( + COMMAND ${GIT_EXECUTABLE} remote set-url origin ${vcpkg_repo} + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message(FATAL_ERROR "failed to change origin to ${vcpkg_repo}") + endif() + + execute_process( + COMMAND ${GIT_EXECUTABLE} fetch + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message(FATAL_ERROR "${GIT_EXECUTABLE} fetch failed with ${result}") + endif() + + _vcpkg_stash(${vcpkg_root}) + _vcpkg_checkout(${vcpkg_root} ${vcpkg_ref}) + _vcpkg_tool_bootstrap(${vcpkg_root}) +endfunction() + +# find root +function(_vcpkg_find_root cache_dir_name out_vcpkg_root) + if(DEFINED ENV{VCPKG_ROOT} AND NOT "$ENV{VCPKG_ROOT}" STREQUAL "") + set(root "$ENV{VCPKG_ROOT}") + elseif("${__vcpkg_bootstrap_host}" STREQUAL "Windows") + set(root "$ENV{LOCALAPPDATA}/vcpkg/projects/${cache_dir_name}/cache") + else() + set(root "$ENV{HOME}/.cache/vcpkg/projects/${cache_dir_name}") + endif() + + set(${out_vcpkg_root} + ${root} + PARENT_SCOPE) +endfunction() + +# set vcpkg_root/toolchain_file cache variables +function(_vcpkg_set_cache_variables vcpkg_root) + set(_VCPKG_ROOT + "${vcpkg_root}" + CACHE INTERNAL "vcpkg root") + + set(_VCPKG_TOOLCHAIN_FILE + "${vcpkg_root}/scripts/buildsystems/vcpkg.cmake" + CACHE INTERNAL "vcpkg toolchain file") +endfunction() + +# bootstrap +function(_vcpkg_bootstrap) + cmake_parse_arguments(PARSE_ARGV 0 "arg" "" "CACHE_DIR_NAME;REPO;REF" "") + + if(DEFINED arg_UNPARSED_ARGUMENTS) + message( + FATAL_ERROR "internal error: ${CMAKE_CURRENT_FUNCTION} passed extra args:" + "${arg_UNPARSED_ARGUMENTS}") + endif() + + find_package(Git QUIET REQUIRED) + + if(DEFINED CACHE{_VCPKG_ROOT}) + set(vcpkg_root $CACHE{_VCPKG_ROOT}) + else() + _vcpkg_find_root("${arg_CACHE_DIR_NAME}" vcpkg_root) + endif() + + if(NOT EXISTS ${vcpkg_root}) + message(STATUS "Setup vcpkg") + _vcpkg_clone(${vcpkg_root} ${arg_REPO} ${arg_REF}) + _vcpkg_tool_bootstrap(${vcpkg_root}) + else() + message(STATUS "Found vcpkg in: ${vcpkg_root}") + _vcpkg_upgrade(${vcpkg_root} ${arg_REPO} ${arg_REF}) + endif() + + _vcpkg_set_cache_variables("${vcpkg_root}") +endfunction() diff --git a/cmake/vcpkg/bootstrap/vcpkg_chainload_toolchain.cmake b/cmake/vcpkg/bootstrap/vcpkg_chainload_toolchain.cmake new file mode 100644 index 0000000..2cff74e --- /dev/null +++ b/cmake/vcpkg/bootstrap/vcpkg_chainload_toolchain.cmake @@ -0,0 +1,45 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +# configure VCPKG_CHAINLOAD_TOOLCHAIN_FILE based on VCPKG_TARGET_TRIPLET and +# VCPKG_TARGET_ARCHITECTURE +function(_vcpkg_chainload_toolchain) + if(DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE) + return() + endif() + + if(NOT DEFINED VCPKG_TARGET_TRIPLET OR NOT DEFINED VCPKG_TARGET_ARCHITECTURE) + message( + FATAL_ERROR + "VCPKG_TARGET_TRIPLET and VCPKG_TARGET_ARCHITECTURE must be set before calling _vcpkg_chainload_toolchain()" + ) + endif() + + # Load toolchain variables from triplet and architecture + + string(LENGTH "${VCPKG_TARGET_ARCHITECTURE}-" _prefix_len) + string(SUBSTRING ${VCPKG_TARGET_TRIPLET} ${_prefix_len} -1 _stripped_string) + string(REPLACE "-" ";" _triplet_parts "${_stripped_string}") + list(GET _triplet_parts 0 _chainload_toolchain_name) + + set(_toolchain "scripts/toolchains/${_chainload_toolchain_name}.cmake") + + if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${_toolchain}") + set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE + "${CMAKE_CURRENT_LIST_DIR}/${_toolchain}" + CACHE INTERNAL "vcpkg chainload") + elseif(EXISTS "${_VCPKG_ROOT}/${_toolchain}") + set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE + "${_VCPKG_ROOT}/${_toolchain}" + CACHE INTERNAL "vcpkg chainload") + else() + message( + WARNING + "Could not find toolchain file for ${_chainload_toolchain_name}, skipping chainload" + ) + endif() + message( + STATUS "vcpkg_chainload_toolchain_file: ${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}") +endfunction() diff --git a/cmake/vcpkg/bootstrap/vcpkg_configure.cmake b/cmake/vcpkg/bootstrap/vcpkg_configure.cmake new file mode 100644 index 0000000..2f63cc3 --- /dev/null +++ b/cmake/vcpkg/bootstrap/vcpkg_configure.cmake @@ -0,0 +1,55 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +function(_vcpkg_export_mode) + if(_VCPKG_ROOT) + _vcpkg_bootstrap(${ARGN}) + _vcpkg_skip_install_on_reconfigure() + endif() + + set(_export_export_dir "${CMAKE_SOURCE_DIR}/cmake/vcpkg/export") + set(_export_vcpkg_root "${_export_export_dir}/${VCPKG_TARGET_TRIPLET}") + _vcpkg_setup_export("${_export_export_dir}" "${_export_vcpkg_root}") + + # Set vcpkg root and toolchian file variables to target the exported artifacts + if(NOT EXISTS "${_export_vcpkg_root}") + message( + FATAL_ERROR + "vcpkg export not found for triplet ${VCPKG_TARGET_TRIPLET}, check vcpkg logs for details" + ) + endif() + + message( + STATUS "Using vcpkg exported artifacts as vcpkg root: ${_export_vcpkg_root}" + ) + + _vcpkg_set_cache_variables("${_export_vcpkg_root}") + + # Disable vcpkg.cmake to read the cache variable to check if it should install + # packages + set(VCPKG_MANIFEST_DIR + "" + CACHE PATH "vcpkg manifest dir" FORCE) + message(STATUS "Disable manifest mode for using vcpkg exported artifacts") +endfunction() + +# bootstrap and configure vcpkg +macro(vcpkg_configure) + if(NOT VCPKG_EXPORT_MODE) + _vcpkg_bootstrap(${ARGN}) + _vcpkg_skip_install_on_reconfigure() + endif() + + _vcpkg_load_triplet() + + if(VCPKG_EXPORT_MODE) + _vcpkg_export_mode(${ARGN}) + endif() + + _vcpkg_chainload_toolchain() + message(STATUS "vcpkg_toolchain_file:$CACHE{_VCPKG_TOOLCHAIN_FILE}") + include("$CACHE{_VCPKG_TOOLCHAIN_FILE}") +endmacro() diff --git a/cmake/vcpkg/bootstrap/vcpkg_export_mode.cmake b/cmake/vcpkg/bootstrap/vcpkg_export_mode.cmake new file mode 100644 index 0000000..2b6e0b9 --- /dev/null +++ b/cmake/vcpkg/bootstrap/vcpkg_export_mode.cmake @@ -0,0 +1,97 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +# This function using vcpkg install and export to export vcpkg artifacts to +# ${CMAKE_SOURCE_DIR}/cmake/vcpkg/export +function(_vcpkg_setup_export export_export_dir export_vcpkg_root) + set(_export_install_dir + "${CMAKE_SOURCE_DIR}/out/vcpkg_installed/${VCPKG_TARGET_TRIPLET}") + + # Update exported artifacts when _VCPKG_ROOT is found + if(DEFINED _VCPKG_ROOT AND NOT ${export_vcpkg_root} STREQUAL _VCPKG_ROOT) + message( + STATUS + "Exporting vcpkg to ${export_vcpkg_root} when VCPKG_EXPORT_MODE is enabled" + ) + + if("${__vcpkg_bootstrap_host}" STREQUAL "Windows") + set(vcpkg_cmd "$CACHE{_VCPKG_ROOT}/vcpkg.exe") + else() + set(vcpkg_cmd "$CACHE{_VCPKG_ROOT}/vcpkg") + endif() + + if(NOT EXISTS ${vcpkg_cmd}) + message( + FATAL_ERROR + "vcpkg executable not found when export_with_manifest enabled: ${vcpkg_cmd}" + ) + endif() + + if(DEFINED VCPKG_FEATURE_FLAGS OR DEFINED CACHE{VCPKG_FEATURE_FLAGS}) + list(JOIN VCPKG_FEATURE_FLAGS "," vcpkg_feature_flags) + set(vcpkg_feature_flags "--feature-flags=${vcpkg_feature_flags}") + endif() + + foreach(_vcpkg_feature IN LISTS VCPKG_MANIFEST_FEATURES) + list(APPEND vcpkg_additional_manifest_params + "--x-feature=${_vcpkg_feature}") + endforeach() + + if(VCPKG_MANIFEST_NO_DEFAULT_FEATURES) + list(APPEND vcpkg_additional_manifest_params "--x-no-default-features") + endif() + + if(DEFINED VCPKG_HOST_TRIPLET AND NOT VCPKG_HOST_TRIPLET STREQUAL "") + list(APPEND vcpkg_additional_manifest_params + "--host-triplet=${VCPKG_HOST_TRIPLET}") + endif() + + set(_additional_args + --vcpkg-root + ${_VCPKG_ROOT} + --overlay-ports + "${VCPKG_OVERLAY_PORTS}" + --overlay-triplets + "${VCPKG_OVERLAY_TRIPLETS}" + --triplet + ${VCPKG_TARGET_TRIPLET} + --x-install-root + "${_export_install_dir}") + + execute_process( + COMMAND + ${vcpkg_cmd} install "--x-wait-for-lock" + "--x-manifest-root=${CMAKE_SOURCE_DIR}" ${_additional_args} + ${vcpkg_feature_flags} ${vcpkg_additional_manifest_params} + ${VCPKG_INSTALL_OPTIONS} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + RESULT_VARIABLE install_packages_result) + + if(NOT install_packages_result EQUAL 0) + message( + FATAL_ERROR + "vcpkg install failed with ${install_packages_result}, check vcpkg logs for details" + ) + endif() + + execute_process( + COMMAND ${vcpkg_cmd} export --raw --output ${VCPKG_TARGET_TRIPLET} + --output-dir ${export_export_dir} ${_additional_args} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + RESULT_VARIABLE export_packages_result) + + if(NOT export_packages_result EQUAL 0) + message( + FATAL_ERROR + "vcpkg export failed with ${export_packages_result}, check vcpkg logs for details" + ) + endif() + + file(COPY "${_VCPKG_ROOT}/triplets" DESTINATION "${export_vcpkg_root}") + + file(COPY "${_VCPKG_ROOT}/scripts/toolchains" + DESTINATION "${export_vcpkg_root}/scripts") + endif() +endfunction() diff --git a/cmake/vcpkg/bootstrap/vcpkg_load_triplet.cmake b/cmake/vcpkg/bootstrap/vcpkg_load_triplet.cmake new file mode 100644 index 0000000..6ceb2f0 --- /dev/null +++ b/cmake/vcpkg/bootstrap/vcpkg_load_triplet.cmake @@ -0,0 +1,225 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +# copied from vcpkg vcpkg.cmake +function(_vcpkg_detect_host_triplet) + if(DEFINED VCPKG_TARGET_TRIPLET) + return() + endif() + + if(CMAKE_GENERATOR_PLATFORM MATCHES "^[Ww][Ii][Nn]32$") + set(_detect_target_triplet_arch x86) + elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Xx]64$") + set(_detect_target_triplet_arch x64) + elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Aa][Rr][Mm]$") + set(_detect_target_triplet_arch arm) + elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Aa][Rr][Mm]64$") + set(_detect_target_triplet_arch arm64) + else() + if(CMAKE_GENERATOR STREQUAL "Visual Studio 14 2015 Win64") + set(_detect_target_triplet_arch x64) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 14 2015 ARM") + set(_detect_target_triplet_arch arm) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 14 2015") + set(_detect_target_triplet_arch x86) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 15 2017 Win64") + set(_detect_target_triplet_arch x64) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 15 2017 ARM") + set(_detect_target_triplet_arch arm) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 15 2017") + set(_detect_target_triplet_arch x86) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 16 2019" + AND CMAKE_VS_PLATFORM_NAME_DEFAULT STREQUAL "ARM64") + set(_detect_target_triplet_arch arm64) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 16 2019") + set(_detect_target_triplet_arch x64) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 17 2022" + AND CMAKE_VS_PLATFORM_NAME_DEFAULT STREQUAL "ARM64") + set(_detect_target_triplet_arch arm64) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 17 2022") + set(_detect_target_triplet_arch x64) + elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND DEFINED + CMAKE_OSX_ARCHITECTURES) + list(LENGTH CMAKE_OSX_ARCHITECTURES _detect_osx_arch_count) + if(_detect_osx_arch_count EQUAL "0") + message( + WARNING + "Unable to determine target architecture from ${CMAKE_OSX_ARCHITECTURES}. " + "Consider providing a value for the CMAKE_OSX_ARCHITECTURES cache variable. " + "Continuing without vcpkg.") + set(VCPKG_TOOLCHAIN ON) + cmake_policy(POP) + return() + endif() + + if(_detect_osx_arch_count GREATER "1") + message( + WARNING + "Detected more than one target architecture from ${CMAKE_OSX_ARCHITECTURES}. Using the first one." + ) + endif() + list(GET CMAKE_OSX_ARCHITECTURES "0" _detect_osx_target_arch) + if(_detect_osx_target_arch STREQUAL "arm64") + set(_detect_target_triplet_arch arm64) + elseif(_detect_osx_target_arch STREQUAL "arm64s") + set(_detect_target_triplet_arch arm64s) + elseif(_detect_osx_target_arch STREQUAL "armv7s") + set(_detect_target_triplet_arch armv7s) + elseif(_detect_osx_target_arch STREQUAL "armv7") + set(_detect_target_triplet_arch arm) + elseif(_detect_osx_target_arch STREQUAL "x86_64") + set(_detect_target_triplet_arch x64) + elseif(_detect_osx_target_arch STREQUAL "i386") + set(_detect_target_triplet_arch x86) + else() + message( + WARNING + "Unable to determine target architecture from ${CMAKE_OSX_ARCHITECTURES}, continuing without vcpkg." + ) + set(VCPKG_TOOLCHAIN ON) + cmake_policy(POP) + return() + endif() + else() + find_program(_vcpkg_cl cl) + if(_vcpkg_cl MATCHES "amd64/cl.exe$" OR _vcpkg_cl MATCHES "x64/cl.exe$") + set(_detect_target_triplet_arch x64) + elseif(_vcpkg_cl MATCHES "arm/cl.exe$") + set(_detect_target_triplet_arch arm) + elseif(_vcpkg_cl MATCHES "arm64/cl.exe$") + set(_detect_target_triplet_arch arm64) + elseif(_vcpkg_cl MATCHES "bin/cl.exe$" OR _vcpkg_cl MATCHES "x86/cl.exe$") + set(_detect_target_triplet_arch x86) + elseif( + CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64" + OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64" + OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "amd64") + set(_detect_target_triplet_arch x64) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^i.86$") + set(_detect_target_triplet_arch x86) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "s390x") + set(_detect_target_triplet_arch s390x) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "ppc64le") + set(_detect_target_triplet_arch ppc64le) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "armv7l") + set(_detect_target_triplet_arch arm) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|ARM64)$") + set(_detect_target_triplet_arch arm64) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "riscv32") + set(_detect_target_triplet_arch riscv32) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "riscv64") + set(_detect_target_triplet_arch riscv64) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "loongarch32") + set(_detect_target_triplet_arch loongarch32) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "loongarch64") + set(_detect_target_triplet_arch loongarch64) + else() + message( + WARNING + "Unable to determine target architecture from ${CMAKE_HOST_SYSTEM_PROCESSOR}, continuing without vcpkg." + ) + set(VCPKG_TOOLCHAIN ON) + cmake_policy(POP) + return() + endif() + endif() + endif() + + # detect the target platform + if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" OR CMAKE_SYSTEM_NAME STREQUAL + "WindowsPhone") + set(_detect_target_triplet_plat uwp) + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" + OR (NOT CMAKE_SYSTEM_NAME AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")) + set(_detect_target_triplet_plat linux) + elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" + OR (NOT CMAKE_SYSTEM_NAME AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" + )) + set(_detect_target_triplet_plat osx) + elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS") + set(_detect_target_triplet_plat ios) + elseif(MINGW) + set(_detect_target_triplet_plat mingw-dynamic) + elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows" + OR (NOT CMAKE_SYSTEM_NAME AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" + )) + if(XBOX_CONSOLE_TARGET STREQUAL "scarlett") + set(_detect_target_triplet_plat xbox-scarlett) + elseif(XBOX_CONSOLE_TARGET STREQUAL "xboxone") + set(_detect_target_triplet_plat xbox-xboxone) + else() + set(_detect_target_triplet_plat windows) + endif() + elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" + OR (NOT CMAKE_SYSTEM_NAME AND CMAKE_HOST_SYSTEM_NAME STREQUAL "FreeBSD" + )) + set(_detect_target_triplet_plat freebsd) + elseif(CMAKE_SYSTEM_NAME STREQUAL "Android" + OR (NOT CMAKE_SYSTEM_NAME AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Android" + )) + set(_detect_target_triplet_plat android) + endif() + + if(EMSCRIPTEN) + set(_detect_target_triplet_arch wasm32) + set(_detect_target_triplet_plat emscripten) + endif() + + if(NOT _detect_target_triplet_arch STREQUAL "" + AND NOT _detect_target_triplet_plat STREQUAL "") + set(VCPKG_DETECT_TRIPLET_ARCH + ${_detect_target_triplet_arch} + PARENT_SCOPE) + set(VCPKG_DETECT_TRIPLET_PLAT + ${_detect_target_triplet_plat} + PARENT_SCOPE) + set(VCPKG_HOST_TRIPLET + "${_detect_target_triplet_arch}-${_detect_target_triplet_plat}" + PARENT_SCOPE) + endif() +endfunction() + +# load the triplet by VCPKG_TARGET_TRIPLET +macro(_vcpkg_load_triplet) + if(NOT DEFINED VCPKG_TARGET_TRIPLET) + message( + STATUS + "VCPKG_TARGET_TRIPLET is not defined, detecting triplet from the system" + ) + + _vcpkg_detect_host_triplet() + + if(DEFINED VCPKG_HOST_TRIPLET) + set(VCPKG_TARGET_TRIPLET "${VCPKG_HOST_TRIPLET}") + message(STATUS "Detected triplet: ${VCPKG_TARGET_TRIPLET}") + else() + message( + FATAL_ERROR + "Unable to determine target triplet, please set it manually.") + endif() + endif() + + # Load triplet variables from VCPKG_TARGET_TRIPLET triplet file + + set(_triplet "triplets/${VCPKG_TARGET_TRIPLET}.cmake") + set(_community_triplet "triplets/community/${VCPKG_TARGET_TRIPLET}.cmake") + + if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${_triplet}") + include("${CMAKE_CURRENT_LIST_DIR}/${_triplet}") + elseif(EXISTS "${_VCPKG_ROOT}/${_triplet}") + include("${_VCPKG_ROOT}/${_triplet}") + elseif(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${_community_triplet}") + include("${CMAKE_CURRENT_LIST_DIR}/${_community_triplet}") + elseif(EXISTS "${_VCPKG_ROOT}/${_community_triplet}") + include("${_VCPKG_ROOT}/${_community_triplet}") + else() + message( + FATAL_ERROR + "Triplet ${VCPKG_TARGET_TRIPLET} not found at ${CMAKE_CURRENT_LIST_DIR}/${_triplet} or ${_VCPKG_ROOT}/${_triplet}" + ) + endif() + unset(_triplet) + unset(_community_triplet) +endmacro(_vcpkg_load_triplet) diff --git a/cmake/vcpkg/bootstrap/vcpkg_skip_install_on_reconfigure.cmake b/cmake/vcpkg/bootstrap/vcpkg_skip_install_on_reconfigure.cmake new file mode 100644 index 0000000..a6c51a5 --- /dev/null +++ b/cmake/vcpkg/bootstrap/vcpkg_skip_install_on_reconfigure.cmake @@ -0,0 +1,47 @@ +# SPDX-FileCopyrightText: Copyright 2024 Mikhail Svetkin +# SPDX-License-Identifier: MIT + +function(_vcpkg_update_manifest_hash) + set(_VCPKG_MANIFEST_HASH + "$CACHE{__VCPKG_MANIFEST_HASH}" + CACHE INTERNAL "Hash of vcpkg manifest file") +endfunction() + +# disable vcpkg manifest install step on cmake reconfigure if vcpkg.json has not +# changed. +function(_vcpkg_skip_install_on_reconfigure) + if(DEFINED CACHE{VCPKG_MANIFEST_DIR} AND NOT $CACHE{VCPKG_MANIFEST_DIR} + STREQUAL "") + set(vcpkg_manifest_file "$CACHE{VCPKG_MANIFEST_DIR}/vcpkg.json") + else() + set(vcpkg_manifest_file "${CMAKE_SOURCE_DIR}/vcpkg.json") + endif() + + file(SHA512 "${vcpkg_manifest_file}" vcpkg_manifest_hash) + + if(DEFINED CACHE{_VCPKG_MANIFEST_HASH} AND _VCPKG_MANIFEST_HASH STREQUAL + vcpkg_manifest_hash) + set(VCPKG_MANIFEST_INSTALL + OFF + CACHE INTERNAL "") + set_property( + DIRECTORY + APPEND + PROPERTY CMAKE_CONFIGURE_DEPENDS "${vcpkg_manifest_file}") + else() + set(VCPKG_MANIFEST_INSTALL + ON + CACHE INTERNAL "") + endif() + + # I was not able to propagate vcpkg_manifest_hash via defer call, so + # workaround it with another cache variable. + set(__VCPKG_MANIFEST_HASH + "${vcpkg_manifest_hash}" + CACHE INTERNAL "") + + # set actual hash only when vcpkg install command succeed. The only way you to + # detect to assume that configuration step succeed. + cmake_language(DEFER DIRECTORY ${CMAKE_SOURCE_DIR} CALL + _vcpkg_update_manifest_hash) +endfunction() diff --git a/cmake/vcpkg/ports/README.md b/cmake/vcpkg/ports/README.md new file mode 100644 index 0000000..a129778 --- /dev/null +++ b/cmake/vcpkg/ports/README.md @@ -0,0 +1,3 @@ +# Customize vcpkg ports + +This folder applies to the custom vcpkg ports. These ports are loaded automatically which can be patched from the `ports` folder of the vcpkg repository or created from scratch. diff --git a/cmake/vcpkg/ports/python3/portfile.cmake b/cmake/vcpkg/ports/python3/portfile.cmake new file mode 100644 index 0000000..bd750d8 --- /dev/null +++ b/cmake/vcpkg/ports/python3/portfile.cmake @@ -0,0 +1,3 @@ +message(WARNING "Using fake python3 to force system libraries.") + +set(VCPKG_POLICY_EMPTY_PACKAGE enabled) diff --git a/cmake/vcpkg/ports/python3/vcpkg.json b/cmake/vcpkg/ports/python3/vcpkg.json new file mode 100644 index 0000000..e7749c5 --- /dev/null +++ b/cmake/vcpkg/ports/python3/vcpkg.json @@ -0,0 +1,7 @@ +{ + "name": "python3", + "version": "3.11.8", + "description": "The Python programming language", + "homepage": "https://github.com/python/cpython", + "license": "Python-2.0" +} diff --git a/cmake/vcpkg/scripts/build_type.cmake b/cmake/vcpkg/scripts/build_type.cmake new file mode 100644 index 0000000..a49dad6 --- /dev/null +++ b/cmake/vcpkg/scripts/build_type.cmake @@ -0,0 +1,26 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2024 msclock + +This module initializes the build type. +]] + +if(NOT CMAKE_BUILD_TYPE) + message(STATUS "Setting CMAKE_BUILD_TYPE to 'Debug' as none was specified.") +endif() +set(CMAKE_BUILD_TYPE + Debug + CACHE STRING "Choose the type of build.") + +# Set the possible values of build type for cmake-gui, ccmake +get_property(_builtin_build_types GLOBAL PROPERTY CMAKE_BUILD_TYPE) + +foreach(_type "Debug" "Release" "MinSizeRel" "RelWithDebInfo") + if(NOT _type IN_LIST _builtin_build_types) + list(APPEND _builtin_build_types ${_type}) + endif() +endforeach() + +set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${_builtin_build_types}) + +unset(_builtin_build_types) diff --git a/cmake/vcpkg/scripts/toolchains/README.md b/cmake/vcpkg/scripts/toolchains/README.md new file mode 100644 index 0000000..2b60435 --- /dev/null +++ b/cmake/vcpkg/scripts/toolchains/README.md @@ -0,0 +1,3 @@ +# Customize vcpkg toolchains + +This folder applies to the custom vcpkg toolchains. These toolchains can be loaded automatically which can be copied from the `scripts/toolchains` folder of the vcpkg repository or created from scratch. diff --git a/cmake/vcpkg/triplets/README.md b/cmake/vcpkg/triplets/README.md new file mode 100644 index 0000000..74db63a --- /dev/null +++ b/cmake/vcpkg/triplets/README.md @@ -0,0 +1,22 @@ +# Customize vcpkg triplets + +This folder applies to the custom vcpkg triplets. These triplets are loaded automatically which can be copied from the `triplets` folder of the vcpkg repository or created from scratch. + +For example, to create a custom triplet for Linux x64 with dynamic library linkage: + +```bash +# Copy the triplet from the vcpkg repository +cp /path/to/vcpkg/repository/triplets/x64-linux.cmake ./x64-linux.cmake +# Edit the triplet to change the library linkage to dynamic +sed -i ./x64-linux.cmake -e's/set(VCPKG_LIBRARY_LINKAGE static)/set(VCPKG_LIBRARY_LINKAGE dynamic)/g' +# Show the contents of the triplet +cat ./x64-linux.cmake +# set(VCPKG_TARGET_ARCHITECTURE x64) +# set(VCPKG_CRT_LINKAGE dynamic) +# set(VCPKG_LIBRARY_LINKAGE dynamic) + +# set(VCPKG_CMAKE_SYSTEM_NAME Linux) + +# Use it when configure the project +cmake --preset=default -DVCPKG_TARGET_TRIPLET=x64-linux +``` diff --git a/cmake/vcpkg/vcpkg.toolchain.cmake b/cmake/vcpkg/vcpkg.toolchain.cmake new file mode 100644 index 0000000..aae0787 --- /dev/null +++ b/cmake/vcpkg/vcpkg.toolchain.cmake @@ -0,0 +1,47 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +include_guard(GLOBAL) + +cmake_minimum_required(VERSION 3.25) + +get_property(IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE) + +if(IN_TRY_COMPILE) + return() +endif() + +unset(IN_TRY_COMPILE) + +# Load the common settings +include(${CMAKE_CURRENT_LIST_DIR}/scripts/build_type.cmake) + +# Vcpkg build environment +file(READ ${CMAKE_SOURCE_DIR}/vcpkg.json _vcpkg_json) +string(JSON _builtin_baseline GET ${_vcpkg_json} builtin-baseline) + +# Respect environment variable VCPKG_ROOT and VCPKG_INSTALLATION_ROOT if set +if(DEFINED ENV{VCPKG_ROOT} AND NOT "$ENV{VCPKG_ROOT}" STREQUAL "") + set(_VCPKG_ROOT + "$ENV{VCPKG_ROOT}" + CACHE PATH "Vcpkg root directory" FORCE) +elseif(DEFINED ENV{VCPKG_INSTALLATION_ROOT} + AND NOT "$ENV{VCPKG_INSTALLATION_ROOT}" STREQUAL "") + set(_VCPKG_ROOT + "$ENV{VCPKG_INSTALLATION_ROOT}" + CACHE PATH "Vcpkg root directory" FORCE) +else() + unset(_VCPKG_ROOT CACHE) +endif() + +include(${CMAKE_CURRENT_LIST_DIR}/bootstrap/vcpkg-config.cmake) + +set(VCPKG_VERBOSE + ON + CACHE BOOL "Vcpkg VCPKG_VERBOSE") + +vcpkg_configure(CACHE_DIR_NAME ss-pybind11 REPO + https://github.com/microsoft/vcpkg.git REF ${_builtin_baseline}) diff --git a/copier.yml b/copier.yml new file mode 100644 index 0000000..cb9fe01 --- /dev/null +++ b/copier.yml @@ -0,0 +1,226 @@ +_envops: + block_end_string: '%]' + block_start_string: '[%' +_subdirectory: template +_message_before_copy: | + Thanks for generating a project using our template. + + You'll be asked a series of questions whose answers will be used to + generate a tailored project for you. +_message_after_copy: | + Your project "{{ project_name }}" has been created successfully! +_message_before_update: | + Thanks for updating your project using our template. + + You'll be asked a series of questions whose answers are pre-populated + with previously entered values. Feel free to change them as needed. +_message_after_update: | + Your project "{{ project_name }}" has been updated successfully! + In case there are any conflicts, please resolve them. Then, + you're done. + +project_name: + default: Serious Scaffold Pybind11 + help: 'Enter the name of the project in CamelCase format:' + type: str + +project_description: + default: | + [%- if project_name == 'Serious Scaffold Pybind11' -%] + A continuously evolving basic template for cpp development. + [%- endif -%] + help: 'Provide a brief description for the project:' + type: str + +copyright_license: + default: MIT License + choices: + - Apache Software License + - Boost Software License 1.0 (BSL-1.0) + - GNU Affero General Public License v3 + - GNU General Public License v3 (GPLv3) + - GNU Lesser General Public License v3 (LGPLv3) + - MIT License + - Mozilla Public License 2.0 (MPL 2.0) + - The Unlicense (Unlicense) + help: Choose the project's license (e.g. "MIT", "GPL-3.0"). + type: str + +copyright_year: + default: 2022-{{ "%Y" | strftime }} + help: Enter the copyright year or range (e.g. "2022-2023"). + type: str + +author_name: + default: Your Name + help: 'Specify the name of the author:' + type: str + +organization_name: + default: | + [%- if project_name == 'Serious Scaffold Pybind11' -%] + Serious Scaffold + [%- endif -%] + help: 'Provide the name of the organization associated with the project:' + type: str + +copyright_holder: + default: '{{ organization_name }}' + help: Name(s) or organization(s) holding the copyright. + type: str + +author_email: + default: '{{ author_name|lower|replace(" ", ".") }}@{{ organization_name|lower|replace(" ", "-") }}.com' + help: 'Specify the email address of the author:' + type: str + +repo_platform: + default: github + choices: + GitHub: github + GitLab: gitlab + GitLab (self-managed): gitlab-self-managed + help: 'Choose the platform for the repository:' + type: str + +repo_host: + default: |- + [% if repo_platform == 'github' -%] + github.com + [%- elif repo_platform == 'gitlab' -%] + gitlab.com + [%- endif %] + help: 'Specify the host of the self-managed GitLab:' + type: str + when: '{{ repo_platform == "gitlab-self-managed" }}' + +page_host: + default: |- + [% if repo_platform == 'github' -%] + github.io + [%- elif repo_platform == 'gitlab' -%] + gitlab.io + [%- endif %] + help: 'Specify the host of the self-managed GitLab Pages:' + type: str + when: '{{ repo_platform == "gitlab-self-managed" }}' + +repo_namespace: + default: '{{ organization_name|lower|replace(" ", "-") }}' + help: 'Indicate the GitHub Repository Owner or GitLab Namespace. This is typically the account name of the author or the organization:' + type: str + +repo_name: + default: '{{ project_name|lower|replace(" ", "-") }}' + help: 'Provide a name for the repository:' + type: str + +module_name: + default: '{{ repo_name|lower|replace("-", "_") }}' + help: 'Specify the name of the primary module within the package (often used in "import "):' + type: str + +create_devcontainer: + default: true + help: 'Whether to create a devcontainer configuration:' + type: bool + +docs_type: + default: sphinx + choices: + Sphinx: sphinx + MkDocs: mkdocs + help: 'Choose the type of documentation to generate:' + type: str + +use_cpm: + default: false + help: Whether to use CPM to manage C++ dependencies that will break up vcpkg dependency management. + type: bool + +use_conan: + default: false + help: Whether to use conan to manage C++ dependencies that will break up vcpkg dependency management. + type: bool + +use_codecov: + default: true + help: 'Whether to add codecov integration:' + type: bool + +codecov_notify_builds: + default: 1 + help: 'Specify the number of builds to notify status for codecov:' + type: int + when: '{{ use_codecov == true }}' + +codecov_threshold: + default: 5% + help: 'Specify the minimum coverage threshold for codecov:' + type: str + when: '{{ use_codecov == true }}' + +use_codeql: + default: true + help: 'Whether to add codeql integration:' + type: bool + when: '{{ repo_platform == "github" }}' + +min_py: + default: '3.12' + choices: + - '3.8' + - '3.9' + - '3.10' + - '3.11' + - '3.12' + - '3.13' + help: 'Choose the minimal Python version the project should support:' + type: str + +max_py: + default: '3.12' + choices: + '3.8': + validator: '[% from pathjoin("includes", "version_compare.jinja") import version_higher_than_validator %]{{ version_higher_than_validator("3.8", min_py) }}' + value: '3.8' + '3.9': + validator: '[% from pathjoin("includes", "version_compare.jinja") import version_higher_than_validator %]{{ version_higher_than_validator("3.9", min_py) }}' + value: '3.9' + '3.10': + validator: '[% from pathjoin("includes", "version_compare.jinja") import version_higher_than_validator %]{{ version_higher_than_validator("3.10", min_py) }}' + value: '3.10' + '3.11': + validator: '[% from pathjoin("includes", "version_compare.jinja") import version_higher_than_validator %]{{ version_higher_than_validator("3.11", min_py) }}' + value: '3.11' + '3.12': + validator: '[% from pathjoin("includes", "version_compare.jinja") import version_higher_than_validator %]{{ version_higher_than_validator("3.12", min_py) }}' + value: '3.12' + '3.13': + value: '3.13' + help: 'Choose the maximal Python version the project should support:' + type: str + +default_py: + default: '{{ max_py }}' + choices: + '3.8': + validator: '[% from pathjoin("includes", "version_compare.jinja") import version_between_validator %]{{ version_between_validator("3.8", min_py, max_py) }}' + value: '3.8' + '3.9': + validator: '[% from pathjoin("includes", "version_compare.jinja") import version_between_validator %]{{ version_between_validator("3.9", min_py, max_py) }}' + value: '3.9' + '3.10': + validator: '[% from pathjoin("includes", "version_compare.jinja") import version_between_validator %]{{ version_between_validator("3.10", min_py, max_py) }}' + value: '3.10' + '3.11': + validator: '[% from pathjoin("includes", "version_compare.jinja") import version_between_validator %]{{ version_between_validator("3.11", min_py, max_py) }}' + value: '3.11' + '3.12': + validator: '[% from pathjoin("includes", "version_compare.jinja") import version_between_validator %]{{ version_between_validator("3.12", min_py, max_py) }}' + value: '3.12' + '3.13': + validator: '[% from pathjoin("includes", "version_compare.jinja") import version_between_validator %]{{ version_between_validator("3.13", min_py, max_py) }}' + value: '3.13' + help: 'Choose the default Python version for development, documentation generation, and package build:' + type: str diff --git a/docs/api/index.md b/docs/api/index.md new file mode 100644 index 0000000..23dedfc --- /dev/null +++ b/docs/api/index.md @@ -0,0 +1,17 @@ +# ss_pybind11 package + +```{eval-rst} +.. automodule:: ss_pybind11 + :members: + :undoc-members: + :show-inheritance: +``` + +## Submodules + +```{eval-rst} +.. automodule:: ss_pybind11._core + :members: + :undoc-members: + :show-inheritance: +``` diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..e414b18 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,120 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) +from __future__ import annotations + +from pathlib import Path + +ROOT = Path(__file__).parent.parent.resolve() + +# -- Project information ----------------------------------------------------- + +project = "Serious Scaffold Pybind11" +copyright = "2024 Serious Scaffold" +author = "msclock" + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "myst_parser", + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.viewcode", + "sphinx.ext.mathjax", + "sphinx.ext.napoleon", + "sphinx_autodoc_typehints", + "sphinx_copybutton", +] +source_suffix = { + ".rst": "restructuredtext", + ".md": "markdown", +} +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = [ + "_build", + "Thumbs.db", + ".DS_Store", + ".env", + ".venv", +] + +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-the-linkcheck-builder +linkcheck_ignore = [ + "https://github.com/serious-scaffold/ss-pybind11", +] + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of buhltin themes. +# +# default theme +# html_theme = 'alabaster' +# +# use furo +html_theme = "furo" + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +# html_static_path = ["_static"] + +html_favicon = "https://img.shields.io/badge/SSP-blue" + +html_css_files = [ + "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/fontawesome.min.css", + "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/solid.min.css", + "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/brands.min.css", +] + +html_theme_options = { + "footer_icons": [ + { + "name": "GitHub", + "url": "https://github.com/serious-scaffold/ss-pybind11", + "html": "", + "class": "fa-brands fa-solid fa-github fa-lg", + }, + ], +} + +# -- Extension configuration ------------------------------------------------- +myst_enable_extensions = [ + "colon_fence", + "substitution", + "deflist", +] + +# https://myst-parser.readthedocs.io/en/latest/syntax/optional.html#auto-generated-header-anchors +myst_heading_anchors = 3 + +intersphinx_mapping = { + "python": ("https://docs.python.org/3", None), +} + +nitpick_ignore = [ + ("py:class", "_io.StringIO"), + ("py:class", "_io.BytesIO"), +] + +always_document_param_types = True diff --git a/docs/contributing.md b/docs/contributing.md new file mode 100644 index 0000000..78caf34 --- /dev/null +++ b/docs/contributing.md @@ -0,0 +1,2 @@ +```{include} ../CONTRIBUTING.md +``` diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..5e5294f --- /dev/null +++ b/docs/index.md @@ -0,0 +1,35 @@ +# Welcome to Serious Scaffold Pybind11's documentation + + + +```{include} ../README.md +:start-after: +``` + +## Content + +```{toctree} +:maxdepth: 2 +:titlesonly: +:caption: Guide +:glob: + +Overview +``` + + + +## Content +```{toctree} +:maxdepth: 1 +:titlesonly: +:caption: API docs + +api/index +``` + +## Indices and tables + +- {ref}`genindex` +- {ref}`modindex` +- {ref}`search` diff --git a/includes/codecov.yml.jinja b/includes/codecov.yml.jinja new file mode 100644 index 0000000..a2d8336 --- /dev/null +++ b/includes/codecov.yml.jinja @@ -0,0 +1,12 @@ +codecov: + notify: + after_n_builds: {{ codecov_notify_builds}} +coverage: + status: + project: + default: + target: auto + threshold: {{ codecov_threshold }} + patch: + default: + informational: true diff --git a/includes/copier-answers-sample.yml b/includes/copier-answers-sample.yml new file mode 100644 index 0000000..fff4c02 --- /dev/null +++ b/includes/copier-answers-sample.yml @@ -0,0 +1,25 @@ +# Default values for verifying the current project structure +author_email: msclock@126.com +author_name: msclock +codecov_notify_builds: 1 +codecov_threshold: 5% +copyright_holder: Serious Scaffold +copyright_license: MIT License +copyright_year: 2024 +create_devcontainer: true +docs_type: sphinx +organization_name: Serious Scaffold +project_description: A template of serious scaffold family based on pybind11. +project_name: Serious Scaffold Pybind11 +repo_name: ss-pybind11 +module_name: ss_pybind11 +repo_namespace: serious-scaffold +repo_platform: github +use_cdash: false +use_codecov: true +use_codeql: true +use_conan: false +use_cpm: false +min_py: '3.8' +max_py: '3.13' +default_py: '3.10' diff --git a/includes/licenses/Apache Software License.jinja b/includes/licenses/Apache Software License.jinja new file mode 100644 index 0000000..b74bfd9 --- /dev/null +++ b/includes/licenses/Apache Software License.jinja @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {{ copyright_year }} {{ copyright_holder }} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/includes/licenses/Boost Software License 1.0 (BSL-1.0).jinja b/includes/licenses/Boost Software License 1.0 (BSL-1.0).jinja new file mode 100644 index 0000000..36b7cd9 --- /dev/null +++ b/includes/licenses/Boost Software License 1.0 (BSL-1.0).jinja @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +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, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/includes/licenses/GNU Affero General Public License v3.jinja b/includes/licenses/GNU Affero General Public License v3.jinja new file mode 100644 index 0000000..d4cde68 --- /dev/null +++ b/includes/licenses/GNU Affero General Public License v3.jinja @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {{ project_name }}: {{ project_description }} + Copyright (C) {{ copyright_year }} {{ copyright_holder }} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/includes/licenses/GNU General Public License v3 (GPLv3).jinja b/includes/licenses/GNU General Public License v3 (GPLv3).jinja new file mode 100644 index 0000000..3b7cfd1 --- /dev/null +++ b/includes/licenses/GNU General Public License v3 (GPLv3).jinja @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {{ project_name }}: {{ project_description }} + Copyright (C) {{ copyright_year }} {{ copyright_holder }} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {{ project_name }} Copyright (C) {{ copyright_year }} {{ copyright_holder }} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/includes/licenses/GNU Lesser General Public License v3 (LGPLv3).jinja b/includes/licenses/GNU Lesser General Public License v3 (LGPLv3).jinja new file mode 100644 index 0000000..0a04128 --- /dev/null +++ b/includes/licenses/GNU Lesser General Public License v3 (LGPLv3).jinja @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/includes/licenses/MIT License.jinja b/includes/licenses/MIT License.jinja new file mode 100644 index 0000000..26a3778 --- /dev/null +++ b/includes/licenses/MIT License.jinja @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) {{ copyright_year }} {{ copyright_holder }} + +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. diff --git a/includes/licenses/Mozilla Public License 2.0 (MPL 2.0).jinja b/includes/licenses/Mozilla Public License 2.0 (MPL 2.0).jinja new file mode 100644 index 0000000..a612ad9 --- /dev/null +++ b/includes/licenses/Mozilla Public License 2.0 (MPL 2.0).jinja @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/includes/licenses/The Unlicense (Unlicense).jinja b/includes/licenses/The Unlicense (Unlicense).jinja new file mode 100644 index 0000000..fdddb29 --- /dev/null +++ b/includes/licenses/The Unlicense (Unlicense).jinja @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +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 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. + +For more information, please refer to diff --git a/includes/utilities.jinja b/includes/utilities.jinja new file mode 100644 index 0000000..2955a85 --- /dev/null +++ b/includes/utilities.jinja @@ -0,0 +1,5 @@ +[% macro first_letters(string) -%] + [%- set words = string.replace("-", " ").replace(".", " ").split(' ') -%] + [%- set initials = words|map('first')|join() -%] + {{ initials|upper }} +[%- endmacro %] diff --git a/includes/variable.jinja b/includes/variable.jinja new file mode 100644 index 0000000..a0ae769 --- /dev/null +++ b/includes/variable.jinja @@ -0,0 +1,69 @@ +[% macro repo_url() -%] + {{ repo_host }}/{{ repo_namespace }}/{{ repo_name }} +[%- endmacro %] + +[% macro page_url() -%] + [% if repo_platform == 'github' -%] + {{ repo_namespace }}.github.io/{{ repo_name }} + [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' -%] + [%- set repo_namespace_root = repo_namespace.split("/")[0] -%] + {{ repo_namespace_root }}.{{ page_host }}{{ repo_namespace | replace(repo_namespace_root, "", 1) }}/{{ repo_name }} + [%- endif %] +[%- endmacro %] + +[% macro license_url() -%] + [% if repo_platform == 'github' -%] + https://{{ repo_url() }}/blob/master/LICENSE + [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' -%] + https://{{ repo_url() }}/-/blob/master/LICENSE + [%- endif -%] +[%- endmacro %] + +[% macro documentation_badge() -%] + [% if docs_type == 'sphinx' -%] +[![Documentation](https://img.shields.io/badge/Documentation-sphinx-blue)](https://{{ page_url() }}) + [%- elif docs_type == 'mkdocs' -%] +[![Documentation](https://img.shields.io/badge/Documentation-mkdocs-blue)](https://{{ page_url() }}) + [%- endif -%] +[%- endmacro %] + +[% macro license_badge() -%] + [% if repo_platform == 'github' -%] +[![License](https://img.shields.io/github/license/{{ repo_namespace }}/{{ repo_name }})]({{ license_url() }}) + [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' -%] +[![License](https://img.shields.io/gitlab/license/{{ repo_namespace }}/{{ repo_name }}?gitlab_url=https%3A%2F%2F{{ repo_host }})]({{ license_url() }}) + [%- endif -%] +[%- endmacro %] + +[% macro ss_badge() -%] +[![SS Badge](https://img.shields.io/badge/Serious%20Scaffold-pybind11-blue)](https://github.com/serious-scaffold/ss-pybind11) +[%- endmacro %] + +[% macro pipeline_badge() -%] + [% if repo_platform == 'github' -%] +[![CI](https://{{ repo_url() }}/actions/workflows/ci.yml/badge.svg)](https://{{ repo_url() }}/actions/workflows/ci.yml) +[![CD](https://{{ repo_url() }}/actions/workflows/cd.yml/badge.svg)](https://{{ repo_url() }}/actions/workflows/cd.yml) +[![Renovate](https://{{ repo_url() }}/actions/workflows/renovate.yml/badge.svg)](https://{{ repo_url() }}/actions/workflows/renovate.yml) +[![Semantic Release](https://{{ repo_url() }}/actions/workflows/semantic-release.yml/badge.svg)](https://{{ repo_url() }}/actions/workflows/semantic-release.yml) + [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' -%] +[![CI](https://{{ repo_url() }}/badges/master/pipeline.svg)](https://{{ repo_url() }}/-/commits/master) + [%- endif %] +[%- endmacro %] + +[% macro codecov_badge() -%] + [% if use_codecov == true -%] + [%- if repo_platform == 'github' -%] +[![codecov](https://codecov.io/gh/{{ repo_namespace }}/{{ repo_name }}/branch/master/graph/badge.svg?token=123456789)](https://codecov.io/gh/{{ repo_namespace }}/{{ repo_name }}) + [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' -%] +[![codecov](https://codecov.io/gh/{{ repo_namespace }}/{{ repo_name }}/branch/master/graph/badge.svg?token=123456789)](https://codecov.io/gh/{{ repo_namespace }}/{{ repo_name }}) + [%- endif -%] + [%- endif -%] +[%- endmacro %] + +[% macro release_badge() -%] + [% if repo_platform == 'github' -%] +[![Release](https://img.shields.io/github/v/release/{{ repo_namespace }}/{{ repo_name }})](https://github.com/{{ repo_namespace }}/{{ repo_name }}/releases) + [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' -%] +[![Release](https://{{ repo_url() }}/-/badges/release.svg)](https://{{ repo_url() }}/-/releases) + [%- endif -%] +[%- endmacro %] diff --git a/includes/version_compare.jinja b/includes/version_compare.jinja new file mode 100644 index 0000000..0fc94c3 --- /dev/null +++ b/includes/version_compare.jinja @@ -0,0 +1,23 @@ +[% macro version_higher_than(version1, version2) -%] + {{ "1" if version1.split(".") | map("int") | list >= version2.split(".") | map("int") | list }} +[%- endmacro %] + +[% macro version_higher_than_validator(version1, version2) -%] + {{ + "Invalid version. The version '%s' is not higher than '%s'." % (version1, version2) + if not version_higher_than(version1, version2) + }} +[%- endmacro %] + +[% macro version_between(version, version_min, version_max) -%] + {{ + "1" if version_min.split(".") | map("int") | list <= version.split(".") | map("int") | list <= version_max.split(".") | map("int") | list + }} +[%- endmacro %] + +[% macro version_between_validator(version, version_min, version_max) -%] + {{ + "Invalid version. The version '%s' is not between '%s' and '%s'." % (version, version_min, version_max) + if not version_between(version, version_min, version_max) + }} +[%- endmacro %] diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000..534454a --- /dev/null +++ b/noxfile.py @@ -0,0 +1,131 @@ +from __future__ import annotations + +import argparse +import shutil +from pathlib import Path + +import nox + +DIR = Path(__file__).parent.resolve() + +nox.options.sessions = ["lint", "pylint", "tests"] + + +@nox.session +def lint(session: nox.Session) -> None: + """ + Run the linter. + """ + session.install("pre-commit") + session.run( + "pre-commit", "run", "--all-files", "--show-diff-on-failure", *session.posargs + ) + + +@nox.session +def pylint(session: nox.Session) -> None: + """ + Run PyLint. + """ + # This needs to be installed into the package environment, and is slower + # than a pre-commit check + session.install(".", "pylint") + session.run("pylint", "ss-pybind11", *session.posargs) + + +@nox.session +def tests(session: nox.Session) -> None: + """ + Run the unit and regular tests. + """ + session.install(".[test]") + session.run("pytest", *session.posargs) + + +@nox.session(reuse_venv=True) +def docs(session: nox.Session) -> None: + """ + Build the docs. Pass "--serve" to serve. Pass "-b linkcheck" to check links. + """ + + parser = argparse.ArgumentParser() + parser.add_argument("--serve", action="store_true", help="Serve after building") + parser.add_argument( + "-b", dest="builder", default="html", help="Build target (default: html)" + ) + args, posargs = parser.parse_known_args(session.posargs) + + if args.builder != "html" and args.serve: + session.error("Must not specify non-HTML builder with --serve") + + extra_installs = ["sphinx-autobuild"] if args.serve else [] + + session.install("-e.[docs]", *extra_installs) + session.chdir("docs") + + if args.builder == "linkcheck": + session.run( + "sphinx-build", "-b", "linkcheck", ".", "_build/linkcheck", *posargs + ) + return + + shared_args = ( + "-n", # nitpicky mode + "-T", # full tracebacks + f"-b={args.builder}", + ".", + f"_build/{args.builder}", + *posargs, + ) + + if args.serve: + session.run("sphinx-autobuild", *shared_args) + else: + session.run("sphinx-build", "--keep-going", *shared_args) + + +@nox.session +def build(session: nox.Session) -> None: + """ + Build an SDist and wheel. + """ + + build_path = DIR.joinpath("build") + if build_path.exists(): + shutil.rmtree(build_path) + + session.install("build") + session.run("python", "-m", "build") + + +@nox.session(reuse_venv=True) +def template_build(session: nox.Session) -> None: + """ + Build template for the current repo only. + """ + import os + + excludes = [".", ".git", "template", "includes", ".nox", "copier.yml"] + for dir_item in os.listdir("."): + if dir_item in excludes: + continue + if Path(dir_item).is_dir(): + shutil.rmtree(dir_item) + else: + Path(dir_item).unlink() + + session.run( + "pipx", + "run", + "copier==9.3.1", + "copy", + "-r", + "HEAD", + "--data-file", + "includes/copier-answers-sample.yml", + *session.posargs, + "-f", + ".", + ".", + ) + Path(".copier-answers.yml").unlink() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..13f0d18 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,158 @@ +[build-system] +requires = ["scikit-build-core"] +build-backend = "scikit_build_core.build" + +[project] +name = "ss_pybind11" +description = "A template of serious scaffold family based on pybind11." +readme = "README.md" +license = { text = "MIT" } +authors = [ + { email = "msclock@126.com", name = "msclock" }, +] +requires-python = ">=3.8" +classifiers = [ + "Intended Audience :: Science/Research", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Topic :: Scientific/Engineering", + "Typing :: Typed", +] +dynamic = ["version"] +dependencies = ["typing-extensions >=3.10.0; python_version<'3.9'"] + +[project.optional-dependencies] +test = ["pytest >=6", "pytest-cov >=3"] +dev = ["pytest >=6", "pytest-cov >=3"] +docs = [ + "sphinx>=7.0", + "myst_parser>=0.13", + "sphinx_copybutton", + "sphinx_autodoc_typehints", + "furo>=2023.08.17", +] + +[project.urls] +Homepage = "https://github.com/serious-scaffold/ss-pybind11" +"Bug Tracker" = "https://github.com/serious-scaffold/ss-pybind11/issues" +Discussions = "https://github.com/serious-scaffold/ss-pybind11/discussions" +Changelog = "https://github.com/serious-scaffold/ss-pybind11/releases" + +[tool.scikit-build] +minimum-version = "0.4" +build-dir = "build/{wheel_tag}" +metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" +sdist.include = ["src/ss_pybind11/_version.py"] +cmake.args = [ + "-DBUILD_TESTING=OFF", + "-DCMAKE_TOOLCHAIN_FILE=cmake/vcpkg/vcpkg.toolchain.cmake", + "-DVCPKG_OVERLAY_TRIPLETS=cmake/vcpkg/triplets", + "-DVCPKG_OVERLAY_PORTS=cmake/vcpkg/ports" +] + +[tool.setuptools_scm] +write_to = "src/ss_pybind11/_version.py" + +[tool.cibuildwheel] +test-command = "pytest {project}/tests" +test-extras = ["test"] +test-skip = ["*universal2:arm64"] + +[tool.cibuildwheel.linux] +before-build =[ + 'yum install zip -y || apk add zip || true', + 'apt update && apt install zip -y || true', + 'pip install cmake ninja', + 'cmake --version', 'git --version', 'ninja --version', +] + +[tool.pytest.ini_options] +minversion = "6.0" +addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"] +xfail_strict = true +filterwarnings = ["error"] +log_cli_level = "INFO" +testpaths = ["tests"] + +[tool.coverage] +run.source = ["ss_pybind11"] +report.exclude_also = ['\.\.\.', 'if typing.TYPE_CHECKING:'] + +[tool.mypy] +files = ["src", "tests"] +python_version = "3.8" +warn_unused_configs = true +strict = true +enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] +warn_unreachable = true +disallow_untyped_defs = false +disallow_incomplete_defs = false + +[[tool.mypy.overrides]] +module = "ss_pybind11.*" +disallow_untyped_defs = true +disallow_incomplete_defs = true + +[tool.ruff] +src = ["src"] + +[tool.ruff.lint] +extend-select = [ + "B", # flake8-bugbear + "I", # isort + "ARG", # flake8-unused-arguments + "C4", # flake8-comprehensions + "EM", # flake8-errmsg + "ICN", # flake8-import-conventions + "G", # flake8-logging-format + "PGH", # pygrep-hooks + "PIE", # flake8-pie + "PL", # pylint + "PT", # flake8-pytest-style + "PTH", # flake8-use-pathlib + "RET", # flake8-return + "RUF", # Ruff-specific + "SIM", # flake8-simplify + "T20", # flake8-print + "UP", # pyupgrade + "YTT", # flake8-2020 + "EXE", # flake8-executable + "NPY", # NumPy specific rules + "PD", # pandas-vet +] +ignore = [ + "PLR09", # Too many <...> + "PLR2004", # Magic value used in comparison + "ISC001", # Conflicts with formatter +] +isort.required-imports = ["from __future__ import annotations"] +# Uncomment if using a _compat.typing backport +# typing-modules = ["ss_pybind11._compat.typing"] + +[tool.ruff.lint.per-file-ignores] +"tests/**" = ["T20"] +"noxfile.py" = ["T20"] + +[tool.pylint] +py-version = "3.8" +ignore-paths = [".*/_version.py"] +extension-pkg-allow-list = ["ss_pybind11._core"] +reports.output-format = "colorized" +similarities.ignore-imports = "yes" +messages_control.disable = [ + "design", + "fixme", + "line-too-long", + "missing-module-docstring", + "wrong-import-position", +] diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..3b11226 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,12 @@ +file( + GLOB _sub_dirs + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/*) + +foreach(_sub_dir ${_sub_dirs}) + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_sub_dir}/CMakeLists.txt") + add_subdirectory(${_sub_dir}) + endif() +endforeach() + +unset(_sub_dirs) diff --git a/src/_core/CMakeLists.txt b/src/_core/CMakeLists.txt new file mode 100644 index 0000000..00222fa --- /dev/null +++ b/src/_core/CMakeLists.txt @@ -0,0 +1,26 @@ +set(PYBIND11_FINDPYTHON ON) + +find_package(pybind11 CONFIG REQUIRED) + +set(target_name _core) + +file(GLOB_RECURSE internal_srcs "src/*.cpp") +file(GLOB_RECURSE internal_hdrs "include/*.hpp") + +generate_git_header(VERSION_NAMESPACE_PREFIX _core) + +pybind11_add_module(${target_name} MODULE ${internal_srcs} ${internal_hdrs}) +warn_target(${target_name}) +harden_target(${target_name}) +sanitize_target(${target_name}) + +target_include_interface_directories( + ${target_name} ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_BINARY_DIR}/git_version) + +target_link_libraries(${target_name} PRIVATE ${target_name_internal}) + +install(TARGETS ${target_name} DESTINATION ${SKBUILD_PROJECT_NAME}) + +install_dependency(TARGETS ${target_name} INSTALL_SYSTEM_LIBS + DEPENDS_DESTINATION ${SKBUILD_PROJECT_NAME}) diff --git a/src/_core/include/_core.hpp b/src/_core/include/_core.hpp new file mode 100644 index 0000000..bf3b3e3 --- /dev/null +++ b/src/_core/include/_core.hpp @@ -0,0 +1,3 @@ +#pragma once + +#include "_version.hpp" diff --git a/src/_core/src/pybind.cpp b/src/_core/src/pybind.cpp new file mode 100644 index 0000000..4caf98c --- /dev/null +++ b/src/_core/src/pybind.cpp @@ -0,0 +1,14 @@ +#include +#include "_core.hpp" + +namespace py = pybind11; + +PYBIND11_MODULE(_core, m) { + m.doc() = R"pbdoc( + Pybind11 _core plugin + ----------------------- + .. currentmodule:: _core + )pbdoc"; + + m.attr("__version__") = _core::ProjectVersion(); +} diff --git a/src/ss_pybind11/__init__.py b/src/ss_pybind11/__init__.py new file mode 100644 index 0000000..20d23db --- /dev/null +++ b/src/ss_pybind11/__init__.py @@ -0,0 +1,12 @@ +""" +Copyright (c) 2024 Serious Scaffold. All rights reserved. + +ss-pybind11: A template of serious scaffold family based on pybind11. +""" + + +from __future__ import annotations + +from ._version import version as __version__ + +__all__ = ["__version__"] diff --git a/src/ss_pybind11/_core.pyi b/src/ss_pybind11/_core.pyi new file mode 100644 index 0000000..2ae8fa0 --- /dev/null +++ b/src/ss_pybind11/_core.pyi @@ -0,0 +1,3 @@ +"""Pybind11 _core plugin interfaces""" + +__version__: str = ... diff --git a/src/ss_pybind11/_version.pyi b/src/ss_pybind11/_version.pyi new file mode 100644 index 0000000..91744f9 --- /dev/null +++ b/src/ss_pybind11/_version.pyi @@ -0,0 +1,4 @@ +from __future__ import annotations + +version: str +version_tuple: tuple[int, int, int] | tuple[int, int, int, str, str] diff --git a/src/ss_pybind11/py.typed b/src/ss_pybind11/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/template/.clang-format b/template/.clang-format new file mode 100644 index 0000000..a36591a --- /dev/null +++ b/template/.clang-format @@ -0,0 +1,228 @@ +--- +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html +--- +Language: Cpp +# Do not offset access specifiers (public, protected, private) +AccessModifierOffset: -4 +# Align parameters after opening brackets (round, angle, square) +AlignAfterOpenBracket: Align +# Do not align consecutive assignments +AlignConsecutiveAssignments: false +# Do not align consecutive declarations +AlignConsecutiveDeclarations: false +# Align consecutive macros +AlignConsecutiveMacros: true +# Align escaped newlines to the left +AlignEscapedNewlines: Left +# Align operands of binary and ternary expressions horizontally +AlignOperands: true +# Align trailing comments +AlignTrailingComments: true +# Allow all function arguments on the next line +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +# Do not allow short blocks (e.g., while blocks) on a single line +AllowShortBlocksOnASingleLine: false +# Do not allow short case labels on a single line +AllowShortCaseLabelsOnASingleLine: false +# Do not allow non-empty functions defined outside of a class on a single line +AllowShortFunctionsOnASingleLine: Inline +# Do not allow short if statements on a single line +AllowShortIfStatementsOnASingleLine: false +# Do not allow short loop blocks on a single line +AllowShortLoopsOnASingleLine: false +# Do not break after the return type in function definitions, unless it exceeds the column limit +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +# Do not break before multiline strings +AlwaysBreakBeforeMultilineStrings: false +# Always break after template declarations +AlwaysBreakTemplateDeclarations: Yes +# Do not require each function argument to be on a separate line +BinPackArguments: false +# Do not require each function parameter to be on a separate line +BinPackParameters: false +# Configure brace wrapping style +BraceWrapping: + # Do not break after case labels + AfterCaseLabel: false + # Do not break after class definitions + AfterClass: false + # Do not break after control statements + AfterControlStatement: false + # Do not break after enum definitions + AfterEnum: false + # Do not break after function definitions + AfterFunction: false + # Do not break after namespace definitions + AfterNamespace: false + # Do not break after struct definitions + AfterStruct: false + # Do not break after union definitions + AfterUnion: false + # Do not break after extern blocks + AfterExternBlock: false + # Break before catch statements + BeforeCatch: true + # Break before else statements + BeforeElse: true + # Do not break before lambda bodies + BeforeLambdaBody: false + # Break before while statements + BeforeWhile: true + # Do not indent braces + IndentBraces: false + # Allow empty function bodies on a single line + SplitEmptyFunction: false + # Allow empty statements on a single line + SplitEmptyRecord: false + # Allow empty namespaces on a single line + SplitEmptyNamespace: false +# Break before binary operators, except for assignment operators +BreakBeforeBinaryOperators: NonAssignment +# Customize break before braces in BraceWrapping +BreakBeforeBraces: Custom +# Do not break after commas in inheritance lists +BreakBeforeInheritanceComma: false +# Break before colons in inheritance lists, but not before commas +BreakInheritanceList: BeforeColon +# Break before ternary operators +BreakBeforeTernaryOperators: true +# Do not break after commas in constructor initializer lists +BreakConstructorInitializersBeforeComma: false +# Break before colons in constructor initializer lists, but not before commas +BreakConstructorInitializers: BeforeColon +# Allow breaking string literals +BreakStringLiterals: true +# Column limit for each line +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +# Do not allow different namespaces to be defined on the same line +CompactNamespaces: false +# Constructor initializer lists should either be all on one line or one per line +ConstructorInitializerAllOnOneLineOrOnePerLine: true +# Indent constructor initializer lists by 4 spaces +ConstructorInitializerIndentWidth: 4 +# Indent continuation lines by 4 spaces +ContinuationIndentWidth: 4 +# No spaces around variable initialization lists +Cpp11BracedListStyle: true +DerivePointerAlignment: true +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +# Automatically add comments at the end of namespaces +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: ^ + Priority: 2 + - Regex: StdAfx.h + Priority: -1 + - Regex: ^<.*\.h> + Priority: 1 + - Regex: ^<.* + Priority: 2 + - Regex: .* + Priority: 3 +IncludeIsMainRegex: ([-_](test|unittest))?$ +# Indent case labels inside switch statements +IndentCaseLabels: true +# Indent code blocks inside extern blocks +IndentExternBlock: Indent +# Do not indent preprocessor directives +IndentPPDirectives: None +# Use 4 spaces for indentation +IndentWidth: 4 +# Do not indent wrapped function names after the return type +IndentWrappedFunctionNames: false +# Do not keep empty lines at the start of code blocks +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +# Do not allow consecutive empty lines +MaxEmptyLinesToKeep: 1 +# Do not indent contents inside namespaces +NamespaceIndentation: None +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +# * and & should be placed next to the type name +PointerAlignment: Left +RawStringFormats: + - Language: Cpp + Delimiters: + - cc + - CC + - cpp + - Cpp + - CPP + - c++ + - C++ + CanonicalDelimiter: '' + BasedOnStyle: google + - Language: TextProto + Delimiters: + - pb + - PB + - proto + - PROTO + EnclosingFunctions: + - EqualsProto + - EquivToProto + - PARSE_PARTIAL_TEXT_PROTO + - PARSE_TEST_PROTO + - PARSE_TEXT_PROTO + - ParseTextOrDie + - ParseTextProtoOrDie + CanonicalDelimiter: '' + BasedOnStyle: google +# Allow reflowing of comments +ReflowComments: true +# Allow sorting of #include statements +SortIncludes: true +# Allow sorting of using declarations +SortUsingDeclarations: true +# Do not include spaces after C-style casts +SpaceAfterCStyleCast: false +# Require a space after the template keyword +SpaceAfterTemplateKeyword: true +# Require spaces around assignment operators +SpaceBeforeAssignmentOperators: true +# Do not include spaces before C++11 braced initializer lists +SpaceBeforeCpp11BracedList: false +# Require a space before the colon in constructor initializers +SpaceBeforeCtorInitializerColon: true +# Require a space before the colon in inheritance statements +SpaceBeforeInheritanceColon: true +# Require a space after control statement keywords (if, for, while, etc.) +SpaceBeforeParens: ControlStatements +# Require a space before the colon in range-based for loops +SpaceBeforeRangeBasedForLoopColon: true +# Do not include spaces inside empty parentheses +SpaceInEmptyParentheses: false +# Require a space before // in trailing comments +SpacesBeforeTrailingComments: 1 +# Do not include spaces around angle brackets +SpacesInAngles: false +# Do not include spaces around C-style cast parentheses +SpacesInCStyleCastParentheses: false +# Do not include spaces around parentheses +SpacesInParentheses: false +# Do not include spaces around square brackets +SpacesInSquareBrackets: false +Standard: Auto +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseTab: Never diff --git a/template/.clang-tidy b/template/.clang-tidy new file mode 100644 index 0000000..820d51d --- /dev/null +++ b/template/.clang-tidy @@ -0,0 +1,78 @@ +Checks: > + *, + -abseil-*, + -altera-*, + -android-*, + -boost-*, + -cert-*, + -cppcoreguidelines-*, + -darwin-*, + -fuchsia-*, + -google-*, + -hicpp-*, + -linuxkernel-*, + -llvm-*, + -llvmlibc-*, + -mpi-*, + -objc-*, + -openmp-*, + -zircon-*, + cert-err34-c, + google-explicit-constructor, + cppcoreguidelines-rvalue-reference-param-not-moved, + -bugprone-assignment-in-if-condition, + -bugprone-branch-clone, + -bugprone-easily-swappable-parameters, + -bugprone-empty-catch, + -bugprone-macro-parentheses, + -bugprone-narrowing-conversions, + -bugprone-signed-char-misuse, + -bugprone-switch-missing-default-case, + -bugprone-unchecked-optional-access, + -clang-analyzer-*, + -concurrency-mt-unsafe, + -misc-const-correctness, + -misc-no-recursion, + -misc-non-private-member-variables-in-classes, + -misc-throw-by-value-catch-by-reference, + -misc-use-anonymous-namespace, + -misc-include-cleaner, + -misc-unused-using-decls, + -modernize-avoid-c-arrays, + -modernize-deprecated-ios-base-aliases, + -modernize-loop-convert, + -modernize-macro-to-enum, + -modernize-raw-string-literal, + -modernize-replace-auto-ptr, + -modernize-return-braced-init-list, + -modernize-type-traits, + -modernize-use-auto, + -modernize-use-nodiscard, + -modernize-use-trailing-return-type, + -modernize-concat-nested-namespaces, + -performance-avoid-endl, + -performance-enum-size, + -performance-inefficient-string-concatenation, + -performance-no-automatic-move, + -performance-noexcept-swap, + -portability-simd-intrinsics, + -portability-std-allocator-const, + -readability-avoid-const-params-in-decls, + -readability-avoid-nested-conditional-operator, + -readability-braces-around-statements, + -readability-container-data-pointer, + -readability-function-cognitive-complexity, + -readability-function-size, + -readability-identifier-length, + -readability-identifier-naming, + -readability-implicit-bool-conversion, + -readability-isolate-declaration, + -readability-magic-numbers, + -readability-suspicious-call-argument, + -readability-uppercase-literal-suffix +HeaderFilterRegex: (src)\/[a-z]+\.hpp +CheckOptions: + - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic + value: '1' + - key: readability-simplify-boolean-expr.SimplifyDeMorgan + value: '0' diff --git a/template/.cppcheck-suppressions.txt b/template/.cppcheck-suppressions.txt new file mode 100644 index 0000000..3384b4a --- /dev/null +++ b/template/.cppcheck-suppressions.txt @@ -0,0 +1,2 @@ +// Limit analysis of branches. Use --check-level=exhaustive to analyze all branches. +normalCheckLevelMaxBranches diff --git a/template/.editorconfig b/template/.editorconfig new file mode 100644 index 0000000..4f6c70c --- /dev/null +++ b/template/.editorconfig @@ -0,0 +1,20 @@ +# EditorConfig is awesome: https://EditorConfig.org + +root = true + +[*] +end_of_line = lf +charset = utf-8 +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{yml,yaml,json,toml,jinja,css,js,cmake}] +indent_size = 2 + +[CMakeLists.txt] +indent_size = 2 + +[Makefile] +indent_style = tab diff --git a/template/.gitattributes b/template/.gitattributes new file mode 100644 index 0000000..a7fe8ee --- /dev/null +++ b/template/.gitattributes @@ -0,0 +1,7 @@ +# Keep compatilibity between windows and unix-like OS +* text=auto eol=lf +*.{cmd,[cC][mM][dD]} text eol=crlf +*.{bat,[bB][aA][tT]} text eol=crlf + +# Archive Format +*.tar.gz filter=lfs diff=lfs merge=lfs -text diff --git a/template/.gitignore.jinja b/template/.gitignore.jinja new file mode 100644 index 0000000..49981c0 --- /dev/null +++ b/template/.gitignore.jinja @@ -0,0 +1,370 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +build +.build + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# OS specific stuff +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Common editor files +*~ +*.swp + +# Build output for this sample +*.out +/out + +# Python lint or env cache +.nox +.mypy_cache + +[% if repo_name == 'ss-pybind11' -%] +# Ignore things from copier +.copier-answers.yml +[%- endif %] + +# Documenation files +docs/_build + +# Vcpkg integration files +!cmake/vcpkg/**/* + +# setuptools_scm +src/*/_version.py + +# ruff +.ruff_cache/ diff --git a/template/.markdownlint.yaml b/template/.markdownlint.yaml new file mode 100644 index 0000000..a435c58 --- /dev/null +++ b/template/.markdownlint.yaml @@ -0,0 +1,10 @@ +default: true + +# Multiple headings with the same content +MD024: false +# First line in a file should be a top-level heading +MD041: false +line_length: false +no-hard-tabs: false +whitespace: false +html: false diff --git a/template/.pre-commit-config.yaml.jinja b/template/.pre-commit-config.yaml.jinja new file mode 100644 index 0000000..4a21d04 --- /dev/null +++ b/template/.pre-commit-config.yaml.jinja @@ -0,0 +1,151 @@ +# To use: +# +# pre-commit run -a +# +# Or: +# +# pre-commit install # (runs every time you commit in git) +# +# To update this file: +# +# pre-commit autoupdate +# +# See https://github.com/pre-commit/pre-commit + +fail_fast: false +exclude: | + (?x)( + ^(.vscode/.*) + ) +files: '' # set '' as default + +repos: + # Standard hooks + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-added-large-files + args: [--maxkb=4096] + - id: check-case-conflict + - id: check-merge-conflict + - id: check-symlinks + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + - id: name-tests-test + args: [--pytest-test-first] + - id: requirements-txt-fixer + - id: trailing-whitespace + + # Check RST + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.10.0 + hooks: + - id: rst-backticks + - id: rst-directive-colons + - id: rst-inline-touching-normal + + # Strong lint from ruff + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.14 + hooks: + - id: ruff + args: [--fix, --show-fixes] + - id: ruff-format + + # Mypy Check + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.8.0 + hooks: + - id: mypy + files: src|tests + args: [] + additional_dependencies: + - pytest + + # Check yaml + - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v2.14.0 + hooks: + - id: pretty-format-yaml + args: + - --autofix + - --offset=2 + exclude: | + (?x)( + .copier-answers.yml + ) + + # Changes tabs to spaces + - repo: https://github.com/Lucas-C/pre-commit-hooks + rev: v1.5.5 + hooks: + - id: remove-tabs + + # CMake formatting + - repo: https://github.com/cheshirekow/cmake-format-precommit + rev: v0.6.13 + hooks: + - id: cmake-format + additional_dependencies: [pyyaml] + types: [file] + files: (\.cmake|CMakeLists.txt)(.in)?$ + exclude: | + (?x)( + ^(cmake/vcpkg/ports/.*) | + ^(cmake/vcpkg/triplets/.*) | + ^(cmake/vcpkg/scripts/toolchains/.*) + ) + + # Check pyproject + - repo: https://github.com/abravalheri/validate-pyproject + rev: v0.16 + hooks: + - id: validate-pyproject + additional_dependencies: ['validate-pyproject-schema-store[all]'] + + # Check jsonschema + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.27.3 + hooks: + - id: check-dependabot + - id: check-github-workflows + - id: check-readthedocs + + # Check for spelling + - repo: https://github.com/codespell-project/codespell + rev: v2.3.0 + hooks: + - id: codespell + args: + - -L=lang + - --check-filenames + - --write-changes + + # Check for common shell mistakes + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.9.0.6 + hooks: + - id: shellcheck + + # Clang format the codebase automatically + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v18.1.8 + hooks: + - id: clang-format + types_or: [c++, c, cuda] + + # Check for renovate config + - repo: https://github.com/renovatebot/pre-commit-hooks + rev: 38.110.2 + hooks: + - id: renovate-config-validator + stages: [manual] + + - repo: local + hooks: + - id: disallow-caps + name: Disallow improper capitalization + language: pygrep + entry: PyBind|Numpy|Cmake|CCache|Github|PyTest + exclude: .pre-commit-config.yaml diff --git a/template/.releaserc.js b/template/.releaserc.js new file mode 100644 index 0000000..f7a2872 --- /dev/null +++ b/template/.releaserc.js @@ -0,0 +1,67 @@ +module.exports = { + branches: [ + '+([0-9])?(.{+([0-9]),x}).x', + { + name: 'beta', + prerelease: true + }, + { + name: 'alpha', + prerelease: true + }, + 'master', + ], + dryRun: false, + plugins: [ + [ + "@semantic-release/commit-analyzer", + { + preset: "angular", + releaseRules: [ + { breaking: true, release: "major" }, + { type: "feat", release: "minor" }, + { type: "fix", release: "patch" }, + { type: "style", release: false }, + { type: "refactor", release: false }, + { type: "perf", release: "patch" }, + { type: "revert", release: "patch" }, + { type: "chore", release: false }, + { type: "build", release: false }, + { type: "ci", release: false }, + { type: "docs", release: false }, + { type: "test", release: false }, + { scope: '*no-release*', release: false }, + ], + parseOpts: { + noteKeywords: ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"] + }, + }, + ], + [ + "@semantic-release/release-notes-generator", + { + preset: "conventionalcommits", + presetConfig: { + types: [ + { type: "feat", section: "Features" }, + { type: "fix", section: "Bug Fixes" }, + { type: "style", section: "Style" }, + { type: "refactor", section: "Refactor" }, + { type: "perf", section: "Performance" }, + { type: "revert", section: "Reverts" }, + { type: "chore", section: "Chores" }, + { type: "build", section: "Build" }, + { type: "ci", section: "CI" }, + { type: "docs", section: "Docs" }, + { type: "test", section: "Tests" }, + ], + }, + parserOpts: { + headerPattern: "^(\\w*)(?:\\((?:no-release,?)?([\\w\\$\\.\\-\\* ]*)(?:,?no-release)?\\))?\\: (.*)$", + noteKeywords: ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"] + }, + }, + ], + "@semantic-release/github", + ], +}; diff --git a/template/.renovaterc.json.jinja b/template/.renovaterc.json.jinja new file mode 100644 index 0000000..54eb359 --- /dev/null +++ b/template/.renovaterc.json.jinja @@ -0,0 +1,190 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:recommended", +[%- if repo_name == 'ss-pybind11' or repo_platform == 'github' %] + "helpers:pinGitHubActionDigests", +[%- endif %] + ":enablePreCommit", + ], + "automergeType": "pr", + "automergeStrategy": "merge-commit", + "platformAutomerge": true, + "packageRules": [ +[%- if repo_name == 'ss-pybind11' %] + { + "matchDepTypes": [ + "action" + ], + "postUpgradeTasks": { + "commands": [ + "find template -type f -exec sed -i -E {{ '\'s/{{{replace \\"/\\" \\"\\\\/\\" depName}}}(.*)@{{{currentDigest}}} # {{{currentValue}}}/{{{replace \\"/\\" \\"\\\\/\\" depName}}}\\\\1@{{{newDigest}}} # {{{newValue}}}/g\' {} +' }}" + ] + } + }, + { + "matchDepTypes": [ + "github-runner" + ], + "postUpgradeTasks": { + "commands": [ + "find template -type f -exec sed -i {{ '\'s|{{{depName}}}-{{{currentValue}}}|{{{depName}}}-{{{newValue}}}|g\'' }} {} +" + ] + } + }, + { + "matchManagers": [ + "pre-commit" + ], + "postUpgradeTasks": { + "commands": [ + "find template -type f -name '.pre-commit-config.yaml.jinja' -exec sed -i {{ '\'/{{{replace \\"/\\" \\"\\\\/\\" depName}}}/{N;s/rev: {{{currentValue}}}/rev: {{{newValue}}}/}\'' }} {} +" + ] + } + }, + { + "matchDepTypes": [ + "container", + "image", + "image-name", + "service-image" + ], + "postUpgradeTasks": { + "commands": [ + "find template -type f -exec sed -i {{ '\'s|{{{depName}}}:{{{currentValue}}}@{{{currentDigest}}}|{{{depName}}}:{{{newValue}}}@{{{newDigest}}}|g\'' }} {} +" + ] + } + }, + { + "description": "Group vcpkg.json baseline with auto-update", + "groupName": "group vcpkg-baseline", + "extends": ["schedule:automergeMonthly"], + "addLabels": [ +[%- if repo_platform == 'github' %] + "auto-approval", +[%- endif %] + "vcpkg-baseline" + ], + "matchDepTypes": [ + "vcpkg-builtin-baseline", + "registration-baseline" + ], + "matchFileNames": [ + "vcpkg.json" + ], + "automerge": true, + "postUpgradeTasks": { + "commands": [ + "find template -type f -name 'vcpkg.json.jinja' -exec sed -i {{ '\'s|{{{currentDigest}}}|{{{newDigest}}}|g\'' }} {} +" + ] + } + }, +[%- endif %] + { + "description": "Group renovate docker tag and pre-commit-hooks tag", + "groupName": "renovate group", + "extends": ["schedule:automergeMonthly"], + "addLabels": [ +[%- if repo_platform == 'github' %] + "auto-approval", +[%- endif %] + "renovate" + ], + "matchDatasources": [ + "docker", + "github-tags" + ], + "automerge": true, + "matchDepNames": [ +[%- if repo_platform == 'github' %] + "ghcr.io/renovatebot/renovate", +[%- endif %] +[%- if repo_platform == 'gitlab' or reop_host_type == 'gitlab-self-managed' or repo_name == 'ss-pybind11' %] + "renovate/renovate", +[%- endif %] + "renovatebot/pre-commit-hooks" + ] + }, + { + "commitMessageTopic": "serious-scaffold-cpp", + "matchDepTypes": [ + "copier-template" + ], + "postUpgradeTasks": { + "commands": [ + "git stash", + "pip install copier==9.3.1", + "copier update --defaults --vcs-ref {{ '{{{newVersion}}}' }}" + ] + }, + "semanticCommitScope": "copier-template" + }, + { + "description": "Group apt packages to avoid failure when multiple packages are outdated.", + "groupName": "apt packages", + "matchDepTypes": [ + "apt" + ] + } + ], + "customManagers": [ + { + "description": "Update python packages installed with pip or pipx", + "customType": "regex", + "datasourceTemplate": "pypi", + "fileMatch": [ + "^\\.github/workflows/.+\\.yml$", + "^\\.renovaterc\\.json$", + "^Makefile$" +[%- if repo_name == 'ss-pybind11' %], + "^template/.*?/workflows/.+\\.yml(\\.jinja)?$", + "^template/\\.renovaterc\\.json\\.jinja$", + "^template/Makefile\\.jinja$" +[%- endif %] + ], + "matchStrings": [ + "pipx? install.* (?.*?)==(?.*?)[\\s\";]" + ] + }, + { + "description": " Update vcpkg.json builtin-baseline with git hash", + "customType": "regex", + "currentValueTemplate": "master", + "datasourceTemplate": "git-refs", + "depNameTemplate": "https://github.com/microsoft/vcpkg", + "depTypeTemplate": "vcpkg-builtin-baseline", + "fileMatch": [ + "^vcpkg\\.json$" + ], + "matchStrings": [ + "\"builtin-baseline\": \"(?.*?)\"" + ] + }, + { + "description": "Update registration baseline with git hash", + "customType": "regex", + "currentValueTemplate": "master", + "datasourceTemplate": "git-refs", + "depTypeTemplate": "registration-baseline", + "fileMatch": [ + "^vcpkg\\.json$" + ], + "matchStrings": [ + "\"baseline\": \"(?.*?)\"[^}]+?\"repository\": \"(?.*?)\"" + ] + }, + { + "customType": "regex", + "datasourceTemplate": "git-tags", + "depNameTemplate": "https://github.com/serious-scaffold/ss-pybind11.git", + "depTypeTemplate": "copier-template", + "fileMatch": [ + "^\\.copier-answers\\.yml$" + ], + "matchStrings": [ + "_commit: (?.*?)\n" + ], + "versioningTemplate": "semver" + } + ] +} diff --git a/template/.vscode/launch.json.jinja b/template/.vscode/launch.json.jinja new file mode 100644 index 0000000..bad5311 --- /dev/null +++ b/template/.vscode/launch.json.jinja @@ -0,0 +1,32 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${command:cmake.launchTargetPath}", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ] + } + ] +} diff --git a/template/.vscode/settings.json b/template/.vscode/settings.json new file mode 100644 index 0000000..6f41f5f --- /dev/null +++ b/template/.vscode/settings.json @@ -0,0 +1,107 @@ +{ + "python.testing.pytestArgs": ["tests"], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true, + "cmake.useCMakePresets": "always", + "cmake.options.statusBarVisibility": "compact", + "files.exclude": { + "**/.clangd/**": true + }, + "files.watcherExclude": { + "**/.clangd/**": true + }, + "files.associations": { + "iosfwd": "cpp", + "type_traits": "cpp", + "algorithm": "cpp", + "any": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "cinttypes": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "deque": "cpp", + "exception": "cpp", + "filesystem": "cpp", + "format": "cpp", + "forward_list": "cpp", + "fstream": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iostream": "cpp", + "istream": "cpp", + "iterator": "cpp", + "limits": "cpp", + "list": "cpp", + "locale": "cpp", + "map": "cpp", + "memory": "cpp", + "mutex": "cpp", + "new": "cpp", + "numeric": "cpp", + "optional": "cpp", + "ostream": "cpp", + "queue": "cpp", + "random": "cpp", + "ranges": "cpp", + "ratio": "cpp", + "set": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "string": "cpp", + "system_error": "cpp", + "thread": "cpp", + "tuple": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "utility": "cpp", + "variant": "cpp", + "vector": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xstddef": "cpp", + "xstring": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp", + "string_view": "cpp", + "*.tcc": "cpp", + "cwctype": "cpp", + "memory_resource": "cpp", + "numbers": "cpp", + "semaphore": "cpp", + "codecvt": "cpp", + "source_location": "cpp" + } +} diff --git a/template/CMakeLists.txt.jinja b/template/CMakeLists.txt.jinja new file mode 100644 index 0000000..26659ce --- /dev/null +++ b/template/CMakeLists.txt.jinja @@ -0,0 +1,41 @@ +[%- from pathjoin("includes", "variable.jinja") import repo_url with context -%] + +cmake_minimum_required(VERSION 3.25) +message(STATUS "CMAKE VERSION:${CMAKE_VERSION}") + +if(NOT DEFINED SKBUILD_PROJECT_NAME) + set(SKBUILD_PROJECT_NAME _core) + set(SKBUILD_PROJECT_VERSION 0.0.0) +endif() + +project( + ${SKBUILD_PROJECT_NAME} + VERSION ${SKBUILD_PROJECT_VERSION} + LANGUAGES C CXX) + +set(CMAKE_CXX_STANDARD + 20 + CACHE STRING "C++ standard") +set(CMAKE_CXX_STANDARD_REQUIRED + ON + CACHE BOOL "C++ standard required") +set(CMAKE_CXX_EXTENSIONS + OFF + CACHE BOOL "C++ extensions") + +# Project default module +find_package(cmake-modules REQUIRED) +include(cmake-modules/ProjectDefault) + +# Project custom modules +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +include(ConfigureWarningsAndHardening) +include(ConfigureVersion) +[%- if use_cpm == true %] +include(ConfigureCPMDependencies) +[%- endif %] +[%- if use_cpm == true %] +include(ConfigureConanDependencies) +[%- endif %] + +add_subdirectory(src) diff --git a/template/CMakePresets.json b/template/CMakePresets.json new file mode 100644 index 0000000..19edd87 --- /dev/null +++ b/template/CMakePresets.json @@ -0,0 +1,19 @@ +{ + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 25, + "patch": 0 + }, + "include": [ + "cmake/presets/default.json", + "cmake/presets/x64-linux-llvm.json", + "cmake/presets/x64-linux-gcc.json", + "cmake/presets/x64-mingw-dynamic-windows-mingw.json", + "cmake/presets/x64-mingw-static-windows-mingw.json", + "cmake/presets/x64-osx-gcc.json", + "cmake/presets/x64-osx-llvm.json", + "cmake/presets/x64-windows-llvm.json", + "cmake/presets/x64-windows-msvc.json" + ] +} diff --git a/template/LICENSE.jinja b/template/LICENSE.jinja new file mode 100644 index 0000000..a635cc0 --- /dev/null +++ b/template/LICENSE.jinja @@ -0,0 +1,2 @@ +[%- set license_template = 'includes/licenses/' + copyright_license + '.jinja' -%] +[%- include license_template -%] diff --git a/template/README.md.jinja b/template/README.md.jinja new file mode 100644 index 0000000..ea49883 --- /dev/null +++ b/template/README.md.jinja @@ -0,0 +1,48 @@ +[% from pathjoin("includes", "variable.jinja") import license_url with context -%] +[% from pathjoin("includes", "variable.jinja") import documentation_badge with context -%] +[% from pathjoin("includes", "variable.jinja") import license_badge with context -%] +[% from pathjoin("includes", "variable.jinja") import ss_badge with context -%] +[% from pathjoin("includes", "variable.jinja") import pipeline_badge with context -%] +[% from pathjoin("includes", "variable.jinja") import codecov_badge with context -%] +[% from pathjoin("includes", "variable.jinja") import release_badge with context -%] +# {{ project_name }} + + + +{{ project_description }} + +{{ documentation_badge() }} +{{ license_badge() }} +{{ ss_badge() }} + +{{ pipeline_badge() }} +{{ codecov_badge() }} +{{ release_badge() }} + +[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit) +[![clang-format](https://img.shields.io/badge/clang--format-enabled-blue)](https://github.com/pre-commit/mirrors-clang-format) +[![cmake-format](https://img.shields.io/badge/cmake--format-enabled-blue)](https://github.com/cheshirekow/cmake-format-precommit) +[![codespell](https://img.shields.io/badge/codespell-enabled-blue)](https://github.com/codespell-project/codespell) +[![markdownlint](https://img.shields.io/badge/markdownlint-enabled-blue)](https://github.com/igorshubovych/markdownlint-cli) +[![shellcheck](https://img.shields.io/badge/shellcheck-enabled-blue)](https://github.com/shellcheck-py/shellcheck-py) + +[% if repo_name == 'ss-pybind11' -%] +## Features + +- Project setup and template update with [copier](https://github.com/copier-org/copier/). +- Containerization for development and deployment with [dev container](https://containers.dev/). +- Continuous Integration with [GitHub Actions](https://docs.github.com/actions). +- Automate dependency updates with [Renovate](https://github.com/renovatebot/renovate). +- Use [cmake-registry](https://github.com/msclock/cmake-registry) to provide various cmake modules and scripts. +- Lint tool `pre-commit` integration with various linters, including [clang-format](https://github.com/pre-commit/mirrors-clang-format), [codespell](https://github.com/codespell-project/codespell), [markdownlint](https://github.com/igorshubovych/markdownlint-cli), and more. +- Handy Makefile for local development. +- Documentation generation with [sphinx](https://www.sphinx-doc.org/en/master/)[[furo](https://github.com/pradyunsg/furo)] or [mkdocs](https://www.mkdocs.org/)[[material](https://squidfunk.github.io/mkdocs-material/)]. +- Automatic release workflow with [semantic-release](https://github.com/semantic-release/semantic-release). +- Maintainable [documentation](https://serious-scaffold.github.io/ss-pybind11/) guides for configuration, development, security and contribution based on ss-pybind11. +[%- else -%] + +[%- endif %] + +## License + +{{ copyright_license }}, for more details, see the [LICENSE]({{ license_url() }}) file. diff --git a/template/[% if create_devcontainer == true %].devcontainer[% endif %]/devcontainer.json.jinja b/template/[% if create_devcontainer == true %].devcontainer[% endif %]/devcontainer.json.jinja new file mode 100644 index 0000000..73a2fd7 --- /dev/null +++ b/template/[% if create_devcontainer == true %].devcontainer[% endif %]/devcontainer.json.jinja @@ -0,0 +1,38 @@ +// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at: +// https://github.com/devcontainers/images/tree/main/src/base-ubuntu +{ + "name": "{{ repo_name }}", + "image": "mcr.microsoft.com/devcontainers/base:ubuntu-22.04", + "capAdd": [ + // Enable ptrace-based debugging for C++ + "SYS_PTRACE" + ], + "securityOpt": [ + "seccomp=unconfined" + ], + // https://github.com/devcontainers/features + // Using features in vscode requires access github with uncomment the below + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "username": "vscode" + }, + "ghcr.io/devcontainers/features/docker-in-docker:2": {}, + "ghcr.io/devcontainers/features/python:1": {}, + "ghcr.io/msclock/features/vcpkg:2": {} + }, + "customizations": { + "vscode": { + "extensions": [ + "EditorConfig.EditorConfig", + "mhutchie.git-graph", + "ms-vscode.cmake-tools" + ] + } + }, + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": { + "git-completions": "echo 'source /usr/share/bash-completion/completions/git' >> ~/.bashrc" + }, + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + "remoteUser": "vscode" +} diff --git a/template/[% if docs_type == 'mkdocs' %]docs[% endif %]/css/mkdocstrings.css b/template/[% if docs_type == 'mkdocs' %]docs[% endif %]/css/mkdocstrings.css new file mode 100644 index 0000000..ca40731 --- /dev/null +++ b/template/[% if docs_type == 'mkdocs' %]docs[% endif %]/css/mkdocstrings.css @@ -0,0 +1,32 @@ +/* Indentation. */ +div.doc-contents:not(.first) { + padding-left: 25px; + border-left: .05rem solid var(--md-typeset-table-color); +} + +/* Mark external links as such. */ +a.external::after, +a.autorefs-external::after { + /* https://primer.style/octicons/arrow-up-right-24 */ + mask-image: url('data:image/svg+xml,'); + -webkit-mask-image: url('data:image/svg+xml,'); + content: ' '; + + display: inline-block; + vertical-align: middle; + position: relative; + + height: 1em; + width: 1em; + background-color: var(--md-typeset-a-color); +} + +a.external:hover::after, +a.autorefs-external:hover::after { + background-color: var(--md-accent-fg-color); +} + +/* Avoid breaking parameters name, etc. in table cells. */ +td code { + word-break: normal !important; +} diff --git a/template/[% if docs_type == 'mkdocs' %]docs[% endif %]/includes/abbreviations.md b/template/[% if docs_type == 'mkdocs' %]docs[% endif %]/includes/abbreviations.md new file mode 100644 index 0000000..ab69e0e --- /dev/null +++ b/template/[% if docs_type == 'mkdocs' %]docs[% endif %]/includes/abbreviations.md @@ -0,0 +1 @@ + diff --git a/template/[% if docs_type == 'mkdocs' %]docs[% endif %]/index.md.jinja b/template/[% if docs_type == 'mkdocs' %]docs[% endif %]/index.md.jinja new file mode 100644 index 0000000..bfbd502 --- /dev/null +++ b/template/[% if docs_type == 'mkdocs' %]docs[% endif %]/index.md.jinja @@ -0,0 +1 @@ +--8<-- "README.md:1:" diff --git a/template/[% if docs_type == 'mkdocs' %]mkdocs.yml[% endif %].jinja b/template/[% if docs_type == 'mkdocs' %]mkdocs.yml[% endif %].jinja new file mode 100644 index 0000000..0748305 --- /dev/null +++ b/template/[% if docs_type == 'mkdocs' %]mkdocs.yml[% endif %].jinja @@ -0,0 +1,126 @@ +[% from pathjoin("includes", "variable.jinja") import repo_url with context -%] +[% from pathjoin("includes", "variable.jinja") import page_url with context -%] + +site_name: {{ project_name }} +site_description: {{ project_description }} +site_url: https://{{ page_url() }} +repo_url: https://{{ repo_url() }} +repo_name: {{ repo_namespace }}/{{ repo_name }} +copyright: Copyright © {{ copyright_year }} {{ copyright_holder }} +edit_uri: edit/master +docs_dir: . + +exclude_docs: | + out + docs/includes +[%- if repo_name == 'ss-pybind11' %] + template +[%- endif %] + +theme: + name: material + + features: + - content.action.edit + - content.action.view + - content.code.copy + - content.code.select + - content.tooltips + - navigation.footer + - navigation.instant + - navigation.path + - navigation.sections + # - navigation.tabs + # - navigation.tabs.sticky + - navigation.top + - navigation.indexes + - toc.follow + # - toc.integrate + + palette: + # Palette toggle for automatic mode + - media: (prefers-color-scheme) + toggle: + icon: material/brightness-auto + name: Switch to light mode + + # Palette toggle for light mode + - media: '(prefers-color-scheme: light)' + scheme: default + toggle: + icon: material/brightness-7 + name: Switch to dark mode + + # Palette toggle for dark mode + - media: '(prefers-color-scheme: dark)' + scheme: slate + toggle: + icon: material/brightness-4 + name: Switch to light mode + + languages: en + + icon: + logo: material/book-open-page-variant +[%- if repo_platform == 'github' %] + repo: fontawesome/brands/github +[%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %] + repo: fontawesome/brands/gitlab +[%- endif %] + +extra: + generator: false + +extra_css: + - docs/css/mkdocstrings.css + +markdown_extensions: + - abbr + - admonition + - attr_list + - md_in_html + - pymdownx.details + - pymdownx.emoji + - pymdownx.tasklist + - pymdownx.magiclink + - pymdownx.superfences + - pymdownx.inlinehilite + - pymdownx.highlight: + anchor_linenums: true + line_spans: __span + pygments_lang_class: true + - pymdownx.snippets: + check_paths: true + auto_append: + - docs/includes/abbreviations.md + - toc: + permalink: ¤ + +plugins: + - search + - same-dir + - git-revision-date-localized: + enable_creation_date: true + fallback_to_build_date: true + type: datetime + exclude: + - out/* + - minify: + minify_html: true + minify_js: true + minify_css: true + htmlmin_opts: + remove_comments: true + cache_safe: true + +watch: + - docs +[%- if repo_name == 'ss-pybind11' %] + - CONTRIBUTING.md +[%- endif %] + - LICENSE + - README.md + - mkdocs.yml + +nav: + - Home: docs/index.md diff --git a/template/[% if docs_type == 'sphinx' %]docs[% endif %]/[% if repo_name == 'ss-pybind11' %]contributing.md[% endif %].jinja b/template/[% if docs_type == 'sphinx' %]docs[% endif %]/[% if repo_name == 'ss-pybind11' %]contributing.md[% endif %].jinja new file mode 100644 index 0000000..78caf34 --- /dev/null +++ b/template/[% if docs_type == 'sphinx' %]docs[% endif %]/[% if repo_name == 'ss-pybind11' %]contributing.md[% endif %].jinja @@ -0,0 +1,2 @@ +```{include} ../CONTRIBUTING.md +``` diff --git a/template/[% if docs_type == 'sphinx' %]docs[% endif %]/api/index.md b/template/[% if docs_type == 'sphinx' %]docs[% endif %]/api/index.md new file mode 100644 index 0000000..23dedfc --- /dev/null +++ b/template/[% if docs_type == 'sphinx' %]docs[% endif %]/api/index.md @@ -0,0 +1,17 @@ +# ss_pybind11 package + +```{eval-rst} +.. automodule:: ss_pybind11 + :members: + :undoc-members: + :show-inheritance: +``` + +## Submodules + +```{eval-rst} +.. automodule:: ss_pybind11._core + :members: + :undoc-members: + :show-inheritance: +``` diff --git a/template/[% if docs_type == 'sphinx' %]docs[% endif %]/conf.py.jinja b/template/[% if docs_type == 'sphinx' %]docs[% endif %]/conf.py.jinja new file mode 100644 index 0000000..c21699b --- /dev/null +++ b/template/[% if docs_type == 'sphinx' %]docs[% endif %]/conf.py.jinja @@ -0,0 +1,130 @@ +[%- from pathjoin("includes", "variable.jinja") import repo_url with context -%] +[%- from pathjoin("includes", "utilities.jinja") import first_letters with context -%] +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) +from __future__ import annotations + +from pathlib import Path + +ROOT = Path(__file__).parent.parent.resolve() + +# -- Project information ----------------------------------------------------- + +project = "{{ project_name }}" +copyright = "{{ copyright_year }} {{ copyright_holder }}" +author = "{{ author_name }}" + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "myst_parser", + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.viewcode", + "sphinx.ext.mathjax", + "sphinx.ext.napoleon", + "sphinx_autodoc_typehints", + "sphinx_copybutton", +] +source_suffix = { + ".rst": "restructuredtext", + ".md": "markdown", +} +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = [ + "_build", + "Thumbs.db", + ".DS_Store", + ".env", + ".venv", +] + +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-the-linkcheck-builder +linkcheck_ignore = [ + "https://{{ repo_url() }}", +] + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of buhltin themes. +# +# default theme +# html_theme = 'alabaster' +# +# use furo +html_theme = "furo" + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +# html_static_path = ["_static"] + +html_favicon = "https://img.shields.io/badge/{{ first_letters(project_name) }}-blue" + +html_css_files = [ + "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/fontawesome.min.css", + "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/solid.min.css", + "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/brands.min.css", +] + +html_theme_options = { + "footer_icons": [ + { +[%- if repo_platform == 'github' %] + "name": "GitHub", +[%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %] + "name": "GitLab", +[%- endif %] + "url": "https://{{ repo_url() }}", + "html": "", +[%- if repo_platform == 'github' %] + "class": "fa-brands fa-solid fa-github fa-lg", +[%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %] + "class": "fa-brands fa-solid fa-gitlab fa-lg", +[%- endif %] + }, + ], +} + +# -- Extension configuration ------------------------------------------------- +myst_enable_extensions = [ + "colon_fence", + "substitution", + "deflist", +] + +# https://myst-parser.readthedocs.io/en/latest/syntax/optional.html#auto-generated-header-anchors +myst_heading_anchors = 3 + +intersphinx_mapping = { + "python": ("https://docs.python.org/3", None), +} + +nitpick_ignore = [ + ("py:class", "_io.StringIO"), + ("py:class", "_io.BytesIO"), +] + +always_document_param_types = True diff --git a/template/[% if docs_type == 'sphinx' %]docs[% endif %]/index.md.jinja b/template/[% if docs_type == 'sphinx' %]docs[% endif %]/index.md.jinja new file mode 100644 index 0000000..7e1a85a --- /dev/null +++ b/template/[% if docs_type == 'sphinx' %]docs[% endif %]/index.md.jinja @@ -0,0 +1,35 @@ +# Welcome to {{ project_name }}'s documentation + + + +```{include} ../README.md +:start-after: +``` + +## Content + +```{toctree} +:maxdepth: 2 +:titlesonly: +:caption: Guide +:glob: + +Overview +``` + + + +## Content +```{toctree} +:maxdepth: 1 +:titlesonly: +:caption: API docs + +api/index +``` + +## Indices and tables + +- {ref}`genindex` +- {ref}`modindex` +- {ref}`search` diff --git a/template/[% if repo_name == 'ss-cpp' %]CONTRIBUTING.md[% endif %].jinja b/template/[% if repo_name == 'ss-cpp' %]CONTRIBUTING.md[% endif %].jinja new file mode 100644 index 0000000..033b021 --- /dev/null +++ b/template/[% if repo_name == 'ss-cpp' %]CONTRIBUTING.md[% endif %].jinja @@ -0,0 +1,63 @@ +# Contributing + +Our scaffolds are community-driven and open-source, anddesigned to save time and effort, allowing developers to focus on writing code that matters most. Your contributions are invaluable! + +## Environment setup + +Fork and clone the repository. + +### Light Environment + +If you don't want to run the full test suite, you can just create a virtual environment based on python and install copier and pre-commit: + +```bash +Optional virtualenv, depends on your develop environment +pipx install virtualenv pre-commit +virtualenv .venv +source .venv/bin/activate + +pip install copier +``` + +### Devcontainer Environment + +If you want to run the full testable environment, you can use the devcontainer provided in the folder `.devcontainer`. + +To use the devcontainer, refer to [Dev Containers tutorial](https://code.visualstudio.com/docs/devcontainers/tutorial). + +## Development + +As usual: + +- create a new branch: `git switch -c feature-or-bugfix-name`. +- edit the code and/or the documentation. +- run `copier copy --vcs-ref=HEAD -l . .` to generate the current repository. +- run `pre-commit run -a` to check if any errors can be fixed. +- if everything is fine, your changes are ready to commit and follow our convention based on the Commit Convention. +- push your branch to your fork and create a pull request. + +## Pull Requests Guidelines + +Link to any related issue in the Pull Request message. + +During the review, we recommend using fixups: + +```bash +# SHA is the SHA of the commit you want to fix +git commit --fixup=SHA +``` + +Once all the changes are approved, you can squash your commits: + +```bash +git rebase -i --autosquash master +``` + +And force-push: + +```bash +git push -f +``` + +If this seems all too complicated, you can push or force-push each new commit, +and we will squash them ourselves if needed, before merging. diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/[% if use_codecov == true %]codecov.yml[% endif %].jinja b/template/[% if repo_platform == 'github' %].github[% endif %]/[% if use_codecov == true %]codecov.yml[% endif %].jinja new file mode 100644 index 0000000..db04e00 --- /dev/null +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/[% if use_codecov == true %]codecov.yml[% endif %].jinja @@ -0,0 +1 @@ +[%- include pathjoin('includes', 'codecov.yml.jinja') -%] diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/[% if use_codeql == true %]codeql-config.yml[% endif %] b/template/[% if repo_platform == 'github' %].github[% endif %]/[% if use_codeql == true %]codeql-config.yml[% endif %] new file mode 100644 index 0000000..8de2daf --- /dev/null +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/[% if use_codeql == true %]codeql-config.yml[% endif %] @@ -0,0 +1,6 @@ +name: CodeQL config + +# https://codeql.github.com/codeql-query-help/ +query-filters: + - exclude: + id: py/commented-out-code diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/matchers/pylint.json b/template/[% if repo_platform == 'github' %].github[% endif %]/matchers/pylint.json new file mode 100644 index 0000000..e3a6bd1 --- /dev/null +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/matchers/pylint.json @@ -0,0 +1,32 @@ +{ + "problemMatcher": [ + { + "severity": "warning", + "pattern": [ + { + "regexp": "^([^:]+):(\\d+):(\\d+): ([A-DF-Z]\\d+): \\033\\[[\\d;]+m([^\\033]+).*$", + "file": 1, + "line": 2, + "column": 3, + "code": 4, + "message": 5 + } + ], + "owner": "pylint-warning" + }, + { + "severity": "error", + "pattern": [ + { + "regexp": "^([^:]+):(\\d+):(\\d+): (E\\d+): \\033\\[[\\d;]+m([^\\033]+).*$", + "file": 1, + "line": 2, + "column": 3, + "code": 4, + "message": 5 + } + ], + "owner": "pylint-error" + } + ] +} diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/[% if use_codeql == true %]codeql.yml[% endif %].jinja b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/[% if use_codeql == true %]codeql.yml[% endif %].jinja new file mode 100644 index 0000000..00ebb33 --- /dev/null +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/[% if use_codeql == true %]codeql.yml[% endif %].jinja @@ -0,0 +1,75 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: CodeQL + +on: + push: + branches: [master] + pull_request: + # The branches below must be a subset of the branches above + branches: [master] + schedule: + - cron: 15 4 * * 3 + +concurrency: + group: {{ '${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}' }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-22.04 + timeout-minutes: 15 + permissions: + actions: read + contents: read + security-events: write + strategy: + fail-fast: false + matrix: + language: [cpp, python] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://git.io/codeql-language-support + + steps: + - name: Checkout repository + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + with: + fetch-depth: 0 + + - name: Initialize CodeQL + uses: github/codeql-action/init@8214744c546c1e5c8f03dde8fab3a7353211988d # v3.26.7 + with: + languages: {{ '${{ matrix.language }}' }} + config-file: ./.github/codeql-config.yml + + - name: Cache + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4 + with: + path: | + ~/vcpkg + ~/.cache/vcpkg + key: codeql-{{ '${{ hashFiles(\'vcpkg.json\') }}' }} + restore-keys: codeql-{{ '${{ hashFiles(\'vcpkg.json\') }}' }} + + - uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5 + with: + python-version: 3.x + + - name: Build + run: python -m pip install .[test] + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@8214744c546c1e5c8f03dde8fab3a7353211988d # v3.26.7 diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/cd.yml.jinja b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/cd.yml.jinja new file mode 100644 index 0000000..f25b52e --- /dev/null +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/cd.yml.jinja @@ -0,0 +1,111 @@ +name: CD + +on: + workflow_dispatch: + release: + types: + - published + +concurrency: + group: {{ '${{ github.workflow }}-${{ github.ref }}' }} + cancel-in-progress: true + +env: + FORCE_COLOR: 3 + +jobs: + make_sdist: + name: Make SDist + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Build SDist + run: pipx run build --sdist + + - uses: actions/upload-artifact@v4 + with: + name: cibw-sdist + path: dist/*.tar.gz + + build_wheels: + name: Wheel on {{ '${{ matrix.os }}' }} + runs-on: {{ '${{ matrix.os }}' }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-22.04, windows-2202, macos-12] + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: pypa/cibuildwheel@v2.22.0 + + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: {{ 'cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}' }} + path: wheelhouse/*.whl + + upload_all: + needs: [build_wheels, make_sdist] + environment: pypi + permissions: + id-token: write + runs-on: ubuntu-latest + if: github.event_name == 'release' && github.event.action == 'published' + + steps: + - uses: actions/download-artifact@v4 + with: + pattern: cibw-* + path: dist + merge-multiple: true + + - uses: pypa/gh-action-pypi-publish@release/v1 + env: + PYPI_API_TOKEN: {{ '${{ secrets.PYPI_API_TOKEN }}' }} + with: + password: {{ '${{ secrets.PYPI_API_TOKEN }}' }} + + pages: + name: Deploy to GitHub Pages + runs-on: ubuntu-22.04 + if: {{ '${{ github.ref_name == github.event.repository.default_branch || (github.event_name == \'release\' && github.event.action == \'published\') }}' }} + permissions: + contents: write + id-token: write + timeout-minutes: 15 + + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + with: + token: {{ '${{ secrets.GITHUB_TOKEN }}' }} + ref: {{ '${{ github.head_ref }}' }} + + - name: Cache + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4 + with: + path: | + ~/vcpkg + ~/.cache/pip + ~/.cache/vcpkg + key: cd-pages-{{ '${{ hashFiles(\'vcpkg.json\') }}' }} + restore-keys: cd-pages-{{ '${{ hashFiles(\'vcpkg.json\') }}' }} + + - uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5 + with: + python-version: 3.x + + - name: Build Docs + run: pipx run nox -s docs + + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4 + with: + github_token: {{ '${{ secrets.GITHUB_TOKEN }}' }} + publish_dir: ./docs/_build/html diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja new file mode 100644 index 0000000..c878c62 --- /dev/null +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja @@ -0,0 +1,208 @@ +name: CI + +on: + workflow_dispatch: + + push: + branches: + - master + - beta + - alpha + - '*.x' + + pull_request: + +concurrency: + group: {{ '${{ github.workflow }}-${{ github.ref }}' }} + cancel-in-progress: true + +env: + FORCE_COLOR: 3 + +jobs: + pre-commit: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + with: + fetch-depth: 0 + + - uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5 + with: + python-version: 3.x + + - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 + with: + extra_args: --hook-stage manual --all-files + + - name: Run PyLint + run: | + echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json" + pipx run nox -s pylint + +[% if repo_name == 'ss-pybind11' %] + consistency: + if: {{ '${{ !cancelled() && ! failure() }}' }} + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + with: + fetch-depth: 0 + + - name: Set up Git + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + + - uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5 + with: + python-version: 3.x + + - name: Install copier + run: pipx install copier==9.3.1 + + - name: Verify template + run: pipx run nox -s template_build + + - name: Test for consistency + run: | + echo "List inconsistent files:" + git status --porcelain + git diff --exit-code || ( \ + echo "# :warning: Inconsistent files found" >> $GITHUB_STEP_SUMMARY && \ + echo "The following files are inconsistent with the template:" >> $GITHUB_STEP_SUMMARY && \ + git status --porcelain | while read file; do echo "- $file"; done >> $GITHUB_STEP_SUMMARY && \ + echo "" >> $GITHUB_STEP_SUMMARY && \ + echo "Please run 'copier copy -r HEAD -f . .' to fix them." >>$GITHUB_STEP_SUMMARY && \ + exit 1 \ + ) +[% endif %] + + checks: + runs-on: {{ '${{ matrix.runs-on }}' }} + needs: [pre-commit] + strategy: + fail-fast: false + matrix: + python-version: ['3.8', '3.12'] + runs-on: [ubuntu-22.04, macos-12, windows-2022] + + include: + - python-version: pypy-3.10 + runs-on: ubuntu-22.04 + + name: Check Python {{ '${{ matrix.python-version }} on ${{ matrix.runs-on }}' }} + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Cache + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4 + with: + path: | + ~/vcpkg + ~/.cache/pip + ~/.cache/vcpkg + key: {{ '${{ matrix.python-version }}-${{ matrix.runs-on }}-${{ hashFiles(\'vcpkg.json\') }}' }} + restore-keys: {{ '${{ matrix.python-version }}-${{ matrix.runs-on }}-${{ hashFiles(\'vcpkg.json\') }}' }} + + - uses: actions/setup-python@v5 + with: + python-version: {{ '${{ matrix.python-version }}' }} + + - name: Install package + run: python -m pip install .[test] + + - name: Test package + run: >- + python -m pytest -ra --cov --cov-report=xml --cov-report=term + --durations=20 +[% if use_codecov == true %] + - name: Upload coverage report + uses: codecov/codecov-action@v3.1.4 +[% endif %] + check-docs: + runs-on: ubuntu-22.04 + needs: [pre-commit +[%- if repo_name == 'ss-pybind11' -%] + , consistency +[%- endif -%] + ] + timeout-minutes: 15 + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Cache + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4 + with: + path: | + ~/vcpkg + ~/.cache/pip + ~/.cache/vcpkg + key: docs-{{ '${{ hashFiles(\'vcpkg.json\') }}' }} + restore-keys: docs-{{ '${{ hashFiles(\'vcpkg.json\') }}' }} + + - uses: actions/setup-python@v5 + with: + python-version: 3.x + + - name: Checks the docs with warnings as errors + run: pipx run nox -s docs -- --check + +[% if docs_type == 'sphinx' %] + - name: Checks the docs for broken links + run: pipx run nox -s docs -- --linkcheck +[%- endif %] + +[% if repo_name == 'ss-pybind11'%] + check-mkdocs-docs: + runs-on: ubuntu-22.04 + needs: [pre-commit, consistency] + timeout-minutes: 15 + + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + with: + fetch-depth: 0 + + - uses: actions/setup-python@v5 + with: + python-version: 3.x + + - name: Install copier + run: pipx install copier==9.3.1 + + - name: Apply mkdocs + run: pipx run nox -s template-build -- -d docs_type=mkdocs + + - name: Checks the docs with warnings as errors + run: pipx run nox -s docs -- --check +[% endif %] + + pass: + if: always() + needs: + - checks + - check-docs +[%- if repo_name == 'ss-pybind11' %] + - check-mkdocs-docs +[%- endif %] + runs-on: ubuntu-22.04 + timeout-minutes: 2 + permissions: + pull-requests: write + + steps: + - name: Decide whether the needed jobs succeeded or failed + uses: re-actors/alls-green@release/v1 + with: + jobs: {{ '${{ toJSON(needs) }}' }} + + - name: Approve pr if all jobs succeeded + if: contains(github.event.pull_request.labels.*.name, 'auto-approval') + uses: hmarr/auto-approve-action@v4 diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/renovate.yml.jinja b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/renovate.yml.jinja new file mode 100644 index 0000000..aa24168 --- /dev/null +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/renovate.yml.jinja @@ -0,0 +1,52 @@ +name: Renovate + +on: + schedule: + # * is a special character in YAML so you have to quote this string + - cron: '*/15 0-3 * * 1' + workflow_dispatch: + +jobs: + renovate: + container: + env: + LOG_LEVEL: debug + RENOVATE_ALLOWED_POST_UPGRADE_COMMANDS: '["^git", "^pip", "^copier", "^find"]' + RENOVATE_BRANCH_PREFIX: renovate-github/ + RENOVATE_ENABLED: {{ '${{ vars.RENOVATE_ENABLED || true }}' }} + RENOVATE_ENABLED_MANAGERS: '["pep621", "github-actions", "regex", "pre-commit"]' + RENOVATE_OPTIMIZE_FOR_DISABLED: 'true' + RENOVATE_PLATFORM: github + RENOVATE_REPOSITORIES: '["{{ '${{ github.repository }}' }}"]' + RENOVATE_REPOSITORY_CACHE: enabled + image: ghcr.io/renovatebot/renovate:38.110.2@sha256:06665449c11c61011319ef8f1cd6e00a265d2692e84586f964ba368d4f67591d + options: --user root + runs-on: ubuntu-22.04 + steps: + - run: env | sort + + - name: Generate a token with GitHub App if App ID exists + id: generate-token + if: vars.BOT_APP_ID + uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1 + with: + app-id: {{ '${{ vars.BOT_APP_ID }}' }} + private-key: {{ '${{ secrets.BOT_PRIVATE_KEY }}' }} + + - name: Warn if RENOVATE_GIT_AUTHOR is set while using GitHub App token + if: steps.generate-token.outputs.token && vars.RENOVATE_GIT_AUTHOR + run: | + echo "# :warning: `RENOVATE_GIT_AUTHOR` is set explicitly while using GitHub App token" >> $GITHUB_STEP_SUMMARY + echo "Generally, Renovate automatically detects the git author and email using the token. However, explicitly setting the `RENOVATE_GIT_AUTHOR` will override this behavior." >> $GITHUB_STEP_SUMMARY + + - name: Run Renovate + env: + RENOVATE_PLATFORM_COMMIT: {{ '${{ steps.generate-token.outputs.token && true || false }}' }} + RENOVATE_TOKEN: {{ '${{ secrets.RENOVATE_TOKEN || steps.generate-token.outputs.token }}' }} + RENOVATE_GIT_AUTHOR: {{ '${{ vars.RENOVATE_GIT_AUTHOR }}' }} + run: | + if [ -z "$RENOVATE_TOKEN" ]; then + echo "RENOVATE_TOKEN is not properly configured, skipping ..." + else + renovate $RENOVATE_EXTRA_FLAG + fi diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/semantic-release.yml.jinja b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/semantic-release.yml.jinja new file mode 100644 index 0000000..d6d0e55 --- /dev/null +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/semantic-release.yml.jinja @@ -0,0 +1,61 @@ +name: Semantic Release + +on: + workflow_run: + workflows: [CI] + types: [completed] + branches: + - master + - beta + - alpha + - '*.x' + +jobs: + semantic-release: + name: Semantic Release + runs-on: ubuntu-22.04 + if: github.event.workflow_run.conclusion == 'success' && github.repository == '{{ repo_namespace }}/{{ repo_name }}' + permissions: + contents: write + id-token: write + issues: write + pull-requests: write + steps: + - name: Generate a bot token with BOT_APP_ID + id: bot_token + if: vars.BOT_APP_ID && env.BOT_PRIVATE_KEY != null + uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1 + env: + BOT_PRIVATE_KEY: {{ '${{ secrets.BOT_PRIVATE_KEY }}' }} + with: + app-id: {{ '${{ vars.BOT_APP_ID }}' }} + private-key: {{ '${{ secrets.BOT_PRIVATE_KEY }}' }} + + - name: Warn if use GITHUB_TOKEN + if: env._GITHUB_TOKEN == env._TO_BE_VERIFIED_TOKEN + env: + _GITHUB_TOKEN: {{ '${{ secrets.GITHUB_TOKEN }}' }} + _TO_BE_VERIFIED_TOKEN: {{ '${{ steps.bot_token.outputs.token || secrets.PAT || secrets.GITHUB_TOKEN }}' }} + run: | + echo "# :warning: GITHUB_TOKEN is used" >> $GITHUB_STEP_SUMMARY + echo "The GITHUB_TOKEN is used instead of a bot token or PAT that will not emit the released publish event for triggering a released workflow." >> $GITHUB_STEP_SUMMARY + + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + with: + fetch-depth: 0 + token: {{ '${{ steps.bot_token.outputs.token || secrets.PAT || secrets.GITHUB_TOKEN }}' }} + + - uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4 + with: + node-version: 20 + + - uses: cycjimmy/semantic-release-action@v4 + id: semantic + with: + semantic_version: 22 + extra_plugins: | + @semantic-release/exec + @semantic-release/github + conventional-changelog-conventionalcommits@7 + env: + GITHUB_TOKEN: {{ '${{ steps.bot_token.outputs.token || secrets.PAT || secrets.GITHUB_TOKEN }}' }} diff --git a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab-ci.yml[% endif %].jinja b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab-ci.yml[% endif %].jinja new file mode 100644 index 0000000..8c09ab8 --- /dev/null +++ b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab-ci.yml[% endif %].jinja @@ -0,0 +1,7 @@ +include: + - remote: https://gitlab.com/msclock/gitlab-ci-templates/-/raw/v2.4.3/collections/All-Projects-General.gitlab-ci.yml + - remote: https://gitlab.com/msclock/gitlab-ci-templates/-/raw/v2.4.3/collections/Code-Quality.gitlab-ci.yml + +variables: + LINT_YAML_ENABLE: '' + LINT_MD_ENABLE: '' diff --git a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/[% if use_codecov == true %]codecov.yml[% endif %].jinja b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/[% if use_codecov == true %]codecov.yml[% endif %].jinja new file mode 100644 index 0000000..db04e00 --- /dev/null +++ b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/[% if use_codecov == true %]codecov.yml[% endif %].jinja @@ -0,0 +1 @@ +[%- include pathjoin('includes', 'codecov.yml.jinja') -%] diff --git a/template/cmake/ConfigureVersion.cmake b/template/cmake/ConfigureVersion.cmake new file mode 100644 index 0000000..569c2ea --- /dev/null +++ b/template/cmake/ConfigureVersion.cmake @@ -0,0 +1,48 @@ +#[[ +This file detects the git commit information and sets the version number accordingly. + +Detected variables: + - CMAKE_PROJECT_GIT_COMMIT_*: git commit information (see below) + - CMAKE_PROJECT_VERSION: version number (major.minor.patch.tweak) + - CMAKE_PROJECT_VERSION_: version numbers (as integers) + +]] + +include_guard(GLOBAL) +include(cmake-modules/configure/GitTools) + +find_package(robotology-cmake-ycm REQUIRED) +include(robotology-cmake-ycm/modules/GitInfo) +include(robotology-cmake-ycm/modules/ExtractVersion) + +# Retrieve the git commit information to CMAKE_PROJECT_GIT_WT_* variables +git_wt_info(SOURCE_DIR ${CMAKE_SOURCE_DIR} PREFIX CMAKE_PROJECT) + +# Rename CMAKE_PROJECT_GIT_WT_* variables to CMAKE_PROJECT_GIT_COMMIT_* +# variables +get_cmake_property(_vars VARIABLES) +foreach(_var IN LISTS _vars) + if(_var MATCHES "^CMAKE_PROJECT_GIT_WT_") + string(REGEX REPLACE "^CMAKE_PROJECT_GIT_WT_" "CMAKE_PROJECT_GIT_COMMIT_" + new_name "${_var}") + set(${new_name} "${${_var}}") + unset(new_name) + endif() +endforeach() + +# Set the CMAKE_PROJECT_VERSION variable +if(NOT CMAKE_PROJECT_GIT_COMMIT_TAG) + set(CMAKE_PROJECT_VERSION "0.0.0.0") +else() + set(CMAKE_PROJECT_VERSION "${CMAKE_PROJECT_GIT_COMMIT_TAG}") + + if(CMAKE_PROJECT_GIT_COMMIT_TAG_REVISION) + set(CMAKE_PROJECT_VERSION + "${CMAKE_PROJECT_VERSION}.${CMAKE_PROJECT_GIT_COMMIT_TAG_REVISION}") + endif() + + string(REGEX REPLACE "^v" "" CMAKE_PROJECT_VERSION "${CMAKE_PROJECT_VERSION}") +endif() + +# Set the CMAKE_PROJECT_VERSION_ variables +extract_version(CMAKE_PROJECT CMAKE_PROJECT REVERSE_NAME) diff --git a/template/cmake/ConfigureWarningsAndHardening.cmake b/template/cmake/ConfigureWarningsAndHardening.cmake new file mode 100644 index 0000000..784fd89 --- /dev/null +++ b/template/cmake/ConfigureWarningsAndHardening.cmake @@ -0,0 +1,117 @@ +#[[ +This file configures the following things: + - dynamic tools: sanitizers, valgrind. + - static tools: clang-tidy, cppcheck. + - compiler flags + - hardening options + +]] + +include_guard(GLOBAL) + +# ############################################################################## +# Sanitizer +# ############################################################################## + +set(USE_SANITIZER + OFF + CACHE BOOL "Enable sanitizer") + +include(cmake-modules/build/Sanitizer) + +# ############################################################################## +# Valgrind +# ############################################################################## + +set(USE_VALGRIND + OFF + CACHE BOOL "Enable Valgrind") +set(USE_VALGRIND_OPTIONS + --leak-check=full # Each individual leak will be shown in detail. + --show-leak-kinds=all # Show all of "definite, indirect, possible, + # reachable" leak kinds in the "full" report. + --gen-suppressions=all # gen suppress info automatically. + --track-origins=yes # Favor useful output over speed. This tracks the + # origins of uninitialized values, which could be very + # useful for memory errors. Consider turning off if + # Valgrind is unacceptably slow. + CACHE STRING "valgrind options.") + +include(cmake-modules/test/Valgrind) + +# ############################################################################## +# Clang-Tidy +# ############################################################################## + +set(USE_CLANGTIDY + OFF + CACHE BOOL "Enable Clang-Tidy") + +include(cmake-modules/build/ClangTidy) + +# ############################################################################## +# Cppcheck +# ############################################################################## + +set(USE_CPPCHECK + OFF + CACHE BOOL "Enable Cppcheck") +set(USE_CPPCHECK_SUPPRESSION_FILE + ${CMAKE_SOURCE_DIR}/.cppcheck-suppressions.txt + CACHE STRING + "Customize the path to the Cppcheck suppressions file of the project") + +include(cmake-modules/build/Cppcheck) + +# ############################################################################## +# CompilerFlags +# ############################################################################## + +include(cmake-modules/build/CompilerFlags) + +# ############################################################################## +# Hardening +# ############################################################################## + +set(USE_HARDENING_FLAGS + -D_GLIBCXX_ASSERTIONS # Enable assertions + -U_FORTIFY_SOURCE # Disable stack protector + -D_FORTIFY_SOURCE=3 # Enable stack protector + -fstack-protector-strong # Enable stack protector + -fcf-protection # Control Flow Guard + -fstack-clash-protection # Control Flow Guard + -Wimplicit-fallthrough # Enabled in compiler flags by default + -fstrict-flex-arrays=3 # Enable strict array bounds + -Wformat # Enabled in compiler flags by default + -Wformat=2 # Enabled in compiler flags by default + # -Wl,-z,nodlopen # Restrict dlopen(3) calls to shared objects + -Wl,-z,noexecstack # Enable data execution prevention by marking stack + # memory as non-executable + -Wl,-z,relro # Mark relocation table entries resolved at load-time as + # read-only + -Wl,-z,now # Mark relocation table entries resolved at load-time as + # read-only. It impacts startup performance + "-fsanitize=undefined -fsanitize-minimal-runtime" # Enable minimal runtime + # undefined behavior sanitizer + -fno-delete-null-pointer-checks + -fno-strict-overflow + -fno-strict-aliasing + -ftrivial-auto-var-init=zero + -Wtrampolines # Enable trampolines(gcc only) + -mbranch-protection=standard # Enable indirect branches(aarch64 only) + CACHE STRING "Additional hardening compilation flags for GCC/Clang") + +set(USE_HARDENING_LINKS + -fstack-protector-strong # Enable stack protector + "-fsanitize=undefined -fsanitize-minimal-runtime" # Enable minimal runtime + # undefined behavior sanitizer -Wl,-z,nodlopen # Restrict dlopen(3) calls to + # shared objects + -Wl,-z,noexecstack # Enable data execution prevention by marking stack + # memory as non-executable + -Wl,-z,relro # Mark relocation table entries resolved at load-time as + # read-only + -Wl,-z,now # Mark relocation table entries resolved at load-time as + # read-only. It impacts startup performance + CACHE STRING "Additional hardening linking flags for GCC/Clang") + +include(cmake-modules/build/Hardening) diff --git a/template/cmake/[% if use_conan == true %]ConfigureConanDependencies.cmake[% endif %] b/template/cmake/[% if use_conan == true %]ConfigureConanDependencies.cmake[% endif %] new file mode 100644 index 0000000..445bce6 --- /dev/null +++ b/template/cmake/[% if use_conan == true %]ConfigureConanDependencies.cmake[% endif %] @@ -0,0 +1,37 @@ +#[[ +Use conan to add dependencies to the project. + +conan is a CMake wrapper for conan C and C++ package manager. + +See https://github.com/conan-io/cmake-conan. + +Example: + + conan_cmake_configure(REQUIRES fmt/6.1.2 + GENERATORS cmake_find_package) + + conan_cmake_autodetect(settings) + + conan_cmake_install(PATH_OR_REFERENCE . + BUILD missing + REMOTE conancenter + SETTINGS ${settings}) + + find_package(fmt) + + add_executable(main main.cpp) + target_link_libraries(main fmt::fmt) + +Note: + Use cmake-conan/conan will break up the project dependency management of vcpkg. Best practice + to use this when the project would not be built as a shared library to be referred by + other vcpkg projects. + +]] + +find_package(cmake-conan REQUIRED) +include(cmake-conan/conan) + +message(STATUS "conan is configuring extra deps...") + +# Add extra deps here diff --git a/template/cmake/[% if use_cpm == true %]ConfigureCPMDependencies.cmake[% endif %] b/template/cmake/[% if use_cpm == true %]ConfigureCPMDependencies.cmake[% endif %] new file mode 100644 index 0000000..4cd4168 --- /dev/null +++ b/template/cmake/[% if use_cpm == true %]ConfigureCPMDependencies.cmake[% endif %] @@ -0,0 +1,34 @@ +#[[ +Use CPM to add dependencies to the project. + +CPM is CMake's missing package manager. A small CMake script for setup-free, +cross-platform, reproducible dependency management. + +See https://github.com/cpm-cmake/CPM.cmake. + +Example: + + # add executable + add_executable(main main.cpp) + + # add dependencies using cpm module + CPMAddPackage("gh:fmtlib/fmt#7.1.3") + CPMAddPackage("gh:nlohmann/json@3.10.5") + CPMAddPackage("gh:catchorg/Catch2@3.2.1") + + # link dependencies + target_link_libraries(main fmt::fmt nlohmann_json::nlohmann_json Catch2::Catch2WithMain) + +Note: + Use cmake-cpm/CPM will break up the project dependency management of vcpkg. Best practice + to use this when the project would not be built as a shared library to be referred by + other vcpkg projects. + +]] + +find_package(cmake-cpm REQUIRED) +include(cmake-cpm/CPM) + +message(STATUS "CPM is configuring extra deps...") + +# Add extra deps here diff --git a/template/cmake/presets/arch/x64.json b/template/cmake/presets/arch/x64.json new file mode 100644 index 0000000..e7ea25b --- /dev/null +++ b/template/cmake/presets/arch/x64.json @@ -0,0 +1,20 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "x64", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "toolset": { + "value": "host=x64", + "strategy": "external" + }, + "hidden": true, + "cacheVariables": { + "VCPKG_TARGET_ARCHITECTURE": "x64" + } + } + ] +} diff --git a/template/cmake/presets/base.json b/template/cmake/presets/base.json new file mode 100644 index 0000000..e929d27 --- /dev/null +++ b/template/cmake/presets/base.json @@ -0,0 +1,48 @@ +{ + "version": 6, + "include": [ + "generators/ninja.json", + "toolchains/vcpkg.json" + ], + "configurePresets": [ + { + "name": "base", + "hidden": true, + "inherits": [ + "ninja", + "vcpkg" + ], + "binaryDir": "${sourceDir}/out/build/${presetName}", + "installDir": "${sourceDir}/out/install/${presetName}", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": true, + "CMAKE_COMPILE_WARNING_AS_ERROR": false, + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_VERBOSE_MAKEFILE": "FALSE" + } + } + ], + "buildPresets": [ + { + "name": "base", + "hidden": true, + "inherits": "ninja", + "configurePreset": "base" + } + ], + "testPresets": [ + { + "name": "base", + "hidden": true, + "inherits": "ninja", + "configurePreset": "base", + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": true + } + } + ] +} diff --git a/template/cmake/presets/compilers/gcc.json b/template/cmake/presets/compilers/gcc.json new file mode 100644 index 0000000..d920fb4 --- /dev/null +++ b/template/cmake/presets/compilers/gcc.json @@ -0,0 +1,13 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "gcc", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++" + } + } + ] +} diff --git a/template/cmake/presets/compilers/llvm.json b/template/cmake/presets/compilers/llvm.json new file mode 100644 index 0000000..5172325 --- /dev/null +++ b/template/cmake/presets/compilers/llvm.json @@ -0,0 +1,21 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "llvm", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++" + } + }, + { + "name": "llvm-cl", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "clang-cl.exe", + "CMAKE_CXX_COMPILER": "clang-cl.exe" + } + } + ] +} diff --git a/template/cmake/presets/compilers/mingw.json b/template/cmake/presets/compilers/mingw.json new file mode 100644 index 0000000..302a898 --- /dev/null +++ b/template/cmake/presets/compilers/mingw.json @@ -0,0 +1,9 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "mingw", + "hidden": true + } + ] +} diff --git a/template/cmake/presets/compilers/msvc.json b/template/cmake/presets/compilers/msvc.json new file mode 100644 index 0000000..712dce1 --- /dev/null +++ b/template/cmake/presets/compilers/msvc.json @@ -0,0 +1,18 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "msvc", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "cl", + "CMAKE_CXX_COMPILER": "cl" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + } + ] +} diff --git a/template/cmake/presets/default.json b/template/cmake/presets/default.json new file mode 100644 index 0000000..6905bcb --- /dev/null +++ b/template/cmake/presets/default.json @@ -0,0 +1,47 @@ +{ + "version": 6, + "include": [ + "base.json" + ], + "configurePresets": [ + { + "name": "default", + "inherits": [ + "base" + ] + } + ], + "buildPresets": [ + { + "name": "default", + "inherits": "base", + "configurePreset": "default" + } + ], + "testPresets": [ + { + "name": "default", + "inherits": "base", + "configurePreset": "default" + } + ], + "workflowPresets": [ + { + "name": "default", + "steps": [ + { + "type": "configure", + "name": "default" + }, + { + "type": "build", + "name": "default" + }, + { + "type": "test", + "name": "default" + } + ] + } + ] +} diff --git a/template/cmake/presets/generators/ninja.json b/template/cmake/presets/generators/ninja.json new file mode 100644 index 0000000..3f639a9 --- /dev/null +++ b/template/cmake/presets/generators/ninja.json @@ -0,0 +1,41 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "ninja", + "hidden": true, + "generator": "Ninja" + }, + { + "name": "ninja-multi-config", + "hidden": true, + "generator": "Ninja Multi-Config" + } + ], + "buildPresets": [ + { + "name": "ninja", + "hidden": true, + "configurePreset": "ninja" + }, + { + "name": "ninja-multi-config", + "hidden": true, + "configurePreset": "ninja-multi-config", + "configuration": "RelWithDebInfo" + } + ], + "testPresets": [ + { + "name": "ninja", + "hidden": true, + "configurePreset": "ninja" + }, + { + "name": "ninja-multi-config", + "hidden": true, + "configurePreset": "ninja-multi-config", + "configuration": "RelWithDebInfo" + } + ] +} diff --git a/template/cmake/presets/os/darwin.json b/template/cmake/presets/os/darwin.json new file mode 100644 index 0000000..e3f3fbe --- /dev/null +++ b/template/cmake/presets/os/darwin.json @@ -0,0 +1,28 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "darwin", + "hidden": true, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + } + ], + "buildPresets": [ + { + "name": "darwin", + "hidden": true, + "configurePreset": "darwin" + } + ], + "testPresets": [ + { + "name": "darwin", + "hidden": true, + "configurePreset": "darwin" + } + ] +} diff --git a/template/cmake/presets/os/linux.json b/template/cmake/presets/os/linux.json new file mode 100644 index 0000000..684e078 --- /dev/null +++ b/template/cmake/presets/os/linux.json @@ -0,0 +1,28 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "linux", + "hidden": true, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + } + ], + "buildPresets": [ + { + "name": "linux", + "hidden": true, + "configurePreset": "linux" + } + ], + "testPresets": [ + { + "name": "linux", + "hidden": true, + "configurePreset": "linux" + } + ] +} diff --git a/template/cmake/presets/os/windows.json b/template/cmake/presets/os/windows.json new file mode 100644 index 0000000..9f78bad --- /dev/null +++ b/template/cmake/presets/os/windows.json @@ -0,0 +1,28 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "windows", + "hidden": true, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + } + ], + "buildPresets": [ + { + "name": "windows", + "hidden": true, + "configurePreset": "windows" + } + ], + "testPresets": [ + { + "name": "windows", + "hidden": true, + "configurePreset": "windows" + } + ] +} diff --git a/template/cmake/presets/toolchains/vcpkg.json b/template/cmake/presets/toolchains/vcpkg.json new file mode 100644 index 0000000..3e8ec67 --- /dev/null +++ b/template/cmake/presets/toolchains/vcpkg.json @@ -0,0 +1,16 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "vcpkg", + "hidden": true, + "toolchainFile": "${sourceDir}/cmake/vcpkg/vcpkg.toolchain.cmake", + "cacheVariables": { + "VCPKG_INSTALL_OPTIONS": "--no-print-usage", + "VCPKG_MANIFEST_FEATURES": "test", + "VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/cmake/vcpkg/triplets", + "VCPKG_OVERLAY_PORTS": "${sourceDir}/cmake/vcpkg/ports" + } + } + ] +} diff --git a/template/cmake/presets/triplets/x64-linux.json b/template/cmake/presets/triplets/x64-linux.json new file mode 100644 index 0000000..dcbccbd --- /dev/null +++ b/template/cmake/presets/triplets/x64-linux.json @@ -0,0 +1,18 @@ +{ + "version": 6, + "include": [ + "../arch/x64.json" + ], + "configurePresets": [ + { + "name": "x64-linux", + "hidden": true, + "inherits": [ + "x64" + ], + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-linux" + } + } + ] +} diff --git a/template/cmake/presets/triplets/x64-mingw-dynamic.json b/template/cmake/presets/triplets/x64-mingw-dynamic.json new file mode 100644 index 0000000..672dde6 --- /dev/null +++ b/template/cmake/presets/triplets/x64-mingw-dynamic.json @@ -0,0 +1,18 @@ +{ + "version": 6, + "include": [ + "../arch/x64.json" + ], + "configurePresets": [ + { + "name": "x64-mingw-dynamic", + "hidden": true, + "inherits": [ + "x64" + ], + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-mingw-dynamic" + } + } + ] +} diff --git a/template/cmake/presets/triplets/x64-mingw-static.json b/template/cmake/presets/triplets/x64-mingw-static.json new file mode 100644 index 0000000..49fb429 --- /dev/null +++ b/template/cmake/presets/triplets/x64-mingw-static.json @@ -0,0 +1,18 @@ +{ + "version": 6, + "include": [ + "../arch/x64.json" + ], + "configurePresets": [ + { + "name": "x64-mingw-static", + "hidden": true, + "inherits": [ + "x64" + ], + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-mingw-static" + } + } + ] +} diff --git a/template/cmake/presets/triplets/x64-osx.json b/template/cmake/presets/triplets/x64-osx.json new file mode 100644 index 0000000..bc0c0d3 --- /dev/null +++ b/template/cmake/presets/triplets/x64-osx.json @@ -0,0 +1,18 @@ +{ + "version": 6, + "include": [ + "../arch/x64.json" + ], + "configurePresets": [ + { + "name": "x64-osx", + "hidden": true, + "inherits": [ + "x64" + ], + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-osx" + } + } + ] +} diff --git a/template/cmake/presets/triplets/x64-windows.json b/template/cmake/presets/triplets/x64-windows.json new file mode 100644 index 0000000..929700c --- /dev/null +++ b/template/cmake/presets/triplets/x64-windows.json @@ -0,0 +1,18 @@ +{ + "version": 6, + "include": [ + "../arch/x64.json" + ], + "configurePresets": [ + { + "name": "x64-windows", + "hidden": true, + "inherits": [ + "x64" + ], + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-windows" + } + } + ] +} diff --git a/template/cmake/presets/x64-linux-gcc.json b/template/cmake/presets/x64-linux-gcc.json new file mode 100644 index 0000000..fdbc879 --- /dev/null +++ b/template/cmake/presets/x64-linux-gcc.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/linux.json", + "compilers/gcc.json", + "triplets/x64-linux.json" + ], + "configurePresets": [ + { + "name": "x64-linux-gcc", + "inherits": [ + "base", + "linux", + "gcc", + "x64-linux" + ] + } + ], + "buildPresets": [ + { + "name": "x64-linux-gcc", + "inherits": "base", + "configurePreset": "x64-linux-gcc" + } + ], + "testPresets": [ + { + "name": "x64-linux-gcc", + "inherits": "base", + "configurePreset": "x64-linux-gcc" + } + ], + "workflowPresets": [ + { + "name": "x64-linux-gcc", + "steps": [ + { + "type": "configure", + "name": "x64-linux-gcc" + }, + { + "type": "build", + "name": "x64-linux-gcc" + }, + { + "type": "test", + "name": "x64-linux-gcc" + } + ] + } + ] +} diff --git a/template/cmake/presets/x64-linux-llvm.json b/template/cmake/presets/x64-linux-llvm.json new file mode 100644 index 0000000..cc9b605 --- /dev/null +++ b/template/cmake/presets/x64-linux-llvm.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/linux.json", + "compilers/llvm.json", + "triplets/x64-linux.json" + ], + "configurePresets": [ + { + "name": "x64-linux-llvm", + "inherits": [ + "base", + "linux", + "llvm", + "x64-linux" + ] + } + ], + "buildPresets": [ + { + "name": "x64-linux-llvm", + "inherits": "base", + "configurePreset": "x64-linux-llvm" + } + ], + "testPresets": [ + { + "name": "x64-linux-llvm", + "inherits": "base", + "configurePreset": "x64-linux-llvm" + } + ], + "workflowPresets": [ + { + "name": "x64-linux-llvm", + "steps": [ + { + "type": "configure", + "name": "x64-linux-llvm" + }, + { + "type": "build", + "name": "x64-linux-llvm" + }, + { + "type": "test", + "name": "x64-linux-llvm" + } + ] + } + ] +} diff --git a/template/cmake/presets/x64-mingw-dynamic-windows-mingw.json b/template/cmake/presets/x64-mingw-dynamic-windows-mingw.json new file mode 100644 index 0000000..bae53dc --- /dev/null +++ b/template/cmake/presets/x64-mingw-dynamic-windows-mingw.json @@ -0,0 +1,54 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/windows.json", + "compilers/mingw.json", + "triplets/x64-mingw-dynamic.json" + ], + "configurePresets": [ + { + "name": "x64-mingw-dynamic-windows-mingw", + "inherits": [ + "base", + "windows", + "mingw", + "x64-mingw-dynamic" + ] + + } + ], + "buildPresets": [ + { + "name": "x64-mingw-dynamic-windows-mingw", + "inherits": "base", + "configurePreset": "x64-mingw-dynamic-windows-mingw" + } + ], + "testPresets": [ + { + "name": "x64-mingw-dynamic-windows-mingw", + "inherits": "base", + "configurePreset": "x64-mingw-dynamic-windows-mingw" + } + ], + "workflowPresets": [ + { + "name": "x64-mingw-dynamic-windows-mingw", + "steps": [ + { + "type": "configure", + "name": "x64-mingw-dynamic-windows-mingw" + }, + { + "type": "build", + "name": "x64-mingw-dynamic-windows-mingw" + }, + { + "type": "test", + "name": "x64-mingw-dynamic-windows-mingw" + } + ] + } + ] +} diff --git a/template/cmake/presets/x64-mingw-static-windows-mingw.json b/template/cmake/presets/x64-mingw-static-windows-mingw.json new file mode 100644 index 0000000..31a6f44 --- /dev/null +++ b/template/cmake/presets/x64-mingw-static-windows-mingw.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/windows.json", + "compilers/mingw.json", + "triplets/x64-mingw-static.json" + ], + "configurePresets": [ + { + "name": "x64-mingw-static-windows-mingw", + "inherits": [ + "base", + "windows", + "mingw", + "x64-mingw-static" + ] + } + ], + "buildPresets": [ + { + "name": "x64-mingw-static-windows-mingw", + "inherits": "base", + "configurePreset": "x64-mingw-static-windows-mingw" + } + ], + "testPresets": [ + { + "name": "x64-mingw-static-windows-mingw", + "inherits": "base", + "configurePreset": "x64-mingw-static-windows-mingw" + } + ], + "workflowPresets": [ + { + "name": "x64-mingw-static-windows-mingw", + "steps": [ + { + "type": "configure", + "name": "x64-mingw-static-windows-mingw" + }, + { + "type": "build", + "name": "x64-mingw-static-windows-mingw" + }, + { + "type": "test", + "name": "x64-mingw-static-windows-mingw" + } + ] + } + ] +} diff --git a/template/cmake/presets/x64-osx-gcc.json b/template/cmake/presets/x64-osx-gcc.json new file mode 100644 index 0000000..405af6c --- /dev/null +++ b/template/cmake/presets/x64-osx-gcc.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/darwin.json", + "compilers/gcc.json", + "triplets/x64-osx.json" + ], + "configurePresets": [ + { + "name": "x64-osx-gcc", + "inherits": [ + "base", + "darwin", + "gcc", + "x64-osx" + ] + } + ], + "buildPresets": [ + { + "name": "x64-osx-gcc", + "inherits": "base", + "configurePreset": "x64-osx-gcc" + } + ], + "testPresets": [ + { + "name": "x64-osx-gcc", + "inherits": "base", + "configurePreset": "x64-osx-gcc" + } + ], + "workflowPresets": [ + { + "name": "x64-osx-gcc", + "steps": [ + { + "type": "configure", + "name": "x64-osx-gcc" + }, + { + "type": "build", + "name": "x64-osx-gcc" + }, + { + "type": "test", + "name": "x64-osx-gcc" + } + ] + } + ] +} diff --git a/template/cmake/presets/x64-osx-llvm.json b/template/cmake/presets/x64-osx-llvm.json new file mode 100644 index 0000000..fc43d06 --- /dev/null +++ b/template/cmake/presets/x64-osx-llvm.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/darwin.json", + "compilers/llvm.json", + "triplets/x64-osx.json" + ], + "configurePresets": [ + { + "name": "x64-osx-llvm", + "inherits": [ + "base", + "darwin", + "llvm", + "x64-osx" + ] + } + ], + "buildPresets": [ + { + "name": "x64-osx-llvm", + "inherits": "base", + "configurePreset": "x64-osx-llvm" + } + ], + "testPresets": [ + { + "name": "x64-osx-llvm", + "inherits": "base", + "configurePreset": "x64-osx-llvm" + } + ], + "workflowPresets": [ + { + "name": "x64-osx-llvm", + "steps": [ + { + "type": "configure", + "name": "x64-osx-llvm" + }, + { + "type": "build", + "name": "x64-osx-llvm" + }, + { + "type": "test", + "name": "x64-osx-llvm" + } + ] + } + ] +} diff --git a/template/cmake/presets/x64-windows-llvm.json b/template/cmake/presets/x64-windows-llvm.json new file mode 100644 index 0000000..04acc62 --- /dev/null +++ b/template/cmake/presets/x64-windows-llvm.json @@ -0,0 +1,56 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/windows.json", + "compilers/llvm.json", + "triplets/x64-windows.json" + ], + "configurePresets": [ + { + "name": "x64-windows-llvm", + "inherits": [ + "base", + "windows", + "llvm-cl", + "x64-windows" + ], + "cacheVariables": { + "USE_SANITIZER": "OFF" + } + } + ], + "buildPresets": [ + { + "name": "x64-windows-llvm", + "inherits": "base", + "configurePreset": "x64-windows-llvm" + } + ], + "testPresets": [ + { + "name": "x64-windows-llvm", + "inherits": "base", + "configurePreset": "x64-windows-llvm" + } + ], + "workflowPresets": [ + { + "name": "x64-windows-llvm", + "steps": [ + { + "type": "configure", + "name": "x64-windows-llvm" + }, + { + "type": "build", + "name": "x64-windows-llvm" + }, + { + "type": "test", + "name": "x64-windows-llvm" + } + ] + } + ] +} diff --git a/template/cmake/presets/x64-windows-msvc.json b/template/cmake/presets/x64-windows-msvc.json new file mode 100644 index 0000000..f63a964 --- /dev/null +++ b/template/cmake/presets/x64-windows-msvc.json @@ -0,0 +1,53 @@ +{ + "version": 6, + "include": [ + "base.json", + "os/windows.json", + "compilers/msvc.json", + "triplets/x64-windows.json" + ], + "configurePresets": [ + { + "name": "x64-windows-msvc", + "inherits": [ + "base", + "windows", + "msvc", + "x64-windows" + ] + } + ], + "buildPresets": [ + { + "name": "x64-windows-msvc", + "inherits": "base", + "configurePreset": "x64-windows-msvc" + } + ], + "testPresets": [ + { + "name": "x64-windows-msvc", + "inherits": "base", + "configurePreset": "x64-windows-msvc" + } + ], + "workflowPresets": [ + { + "name": "x64-windows-msvc", + "steps": [ + { + "type": "configure", + "name": "x64-windows-msvc" + }, + { + "type": "build", + "name": "x64-windows-msvc" + }, + { + "type": "test", + "name": "x64-windows-msvc" + } + ] + } + ] +} diff --git a/template/cmake/vcpkg/bootstrap/vcpkg-config.cmake b/template/cmake/vcpkg/bootstrap/vcpkg-config.cmake new file mode 100644 index 0000000..869092b --- /dev/null +++ b/template/cmake/vcpkg/bootstrap/vcpkg-config.cmake @@ -0,0 +1,20 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +include_guard(GLOBAL) + +# CMAKE_HOST_* variables are not available during first configure on windows. +cmake_host_system_information(RESULT __vcpkg_bootstrap_host QUERY OS_NAME) +cmake_host_system_information(RESULT __vcpkg_bootstrap_arch QUERY OS_PLATFORM) + +set(__vcpkg_bootstrap_list_dir "${CMAKE_CURRENT_LIST_DIR}") + +include(${__vcpkg_bootstrap_list_dir}/vcpkg_skip_install_on_reconfigure.cmake) +include(${__vcpkg_bootstrap_list_dir}/vcpkg_bootstrap.cmake) +include(${__vcpkg_bootstrap_list_dir}/vcpkg_chainload_toolchain.cmake) +include(${__vcpkg_bootstrap_list_dir}/vcpkg_load_triplet.cmake) +include(${__vcpkg_bootstrap_list_dir}/vcpkg_export_mode.cmake) +include(${__vcpkg_bootstrap_list_dir}/vcpkg_configure.cmake) diff --git a/template/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake b/template/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake new file mode 100644 index 0000000..ba599f4 --- /dev/null +++ b/template/cmake/vcpkg/bootstrap/vcpkg_bootstrap.cmake @@ -0,0 +1,205 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +# stash all local changes +function(_vcpkg_stash vcpkg_root) + message(STATUS "vcpkg stash all local changes") + + execute_process( + COMMAND ${GIT_EXECUTABLE} stash + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message(FATAL_ERROR "${GIT_EXECUTABLE} stash failed with ${result}") + endif() +endfunction() + +# checkout to a specific baseline +function(_vcpkg_checkout vcpkg_root vcpkg_ref) + message(STATUS "vcpkg checkout to ${vcpkg_ref}") + + execute_process( + COMMAND ${GIT_EXECUTABLE} fetch origin ${vcpkg_ref} + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message( + FATAL_ERROR "${GIT_EXECUTABLE} fetch ${vcpkg_ref} failed with ${result}") + endif() + + execute_process( + COMMAND ${GIT_EXECUTABLE} checkout ${vcpkg_ref} + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message( + FATAL_ERROR + "${GIT_EXECUTABLE} checkout ${vcpkg_ref} failed with ${result}") + endif() +endfunction() + +# clone +function(_vcpkg_clone vcpkg_root vcpkg_repo vcpkg_ref) + execute_process( + COMMAND ${GIT_EXECUTABLE} clone ${vcpkg_repo} ${vcpkg_root} --depth=1 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message(FATAL_ERROR "failed to clone ${vcpkg_repo} to ${vcpkg_root}") + endif() + + file(LOCK "${vcpkg_root}" DIRECTORY) + _vcpkg_checkout(${vcpkg_root} ${vcpkg_ref}) +endfunction() + +# bootstrap +function(_vcpkg_tool_bootstrap vcpkg_root) + message(STATUS "Bootstrap vckpg tool") + + if("${__vcpkg_bootstrap_host}" STREQUAL "Windows") + set(bootstrap_cmd "${vcpkg_root}/bootstrap-vcpkg.bat") + else() + set(bootstrap_cmd "${vcpkg_root}/bootstrap-vcpkg.sh") + endif() + + execute_process( + COMMAND ${bootstrap_cmd} -disableMetrics + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + if(CMAKE_HOST_UNIX) + message(STATUS "Retry to build vcpkg from source...") + set(bootstrap_impl "${vcpkg_root}/scripts/bootstrap.sh") + file(READ "${bootstrap_impl}" file_contents) + string(REPLACE [[elif [ "$ARCH" = "x86_64" ]; then]] + [[elif [ "$ARCH" = "" ]; then]] file_contents + "${file_contents}") + file(WRITE "${bootstrap_impl}" "${file_contents}") + + execute_process( + COMMAND ${bootstrap_cmd} -disableMetrics + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + endif() + + if(NOT result EQUAL "0") + message(FATAL_ERROR "${bootstrap_cmd} failed with ${result}") + endif() + endif() +endfunction() + +# upgrade +function(_vcpkg_upgrade vcpkg_root vcpkg_repo vcpkg_ref) + file(LOCK "${vcpkg_root}" DIRECTORY) + + if(NOT EXISTS "${vcpkg_root}/.git") + message(WARNING "vcpkg not found in git work tree, skipping upgrade") + return() + endif() + + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse HEAD + WORKING_DIRECTORY ${vcpkg_root} + OUTPUT_VARIABLE current_git_hash + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message( + FATAL_ERROR "${GIT_EXECUTABLE} rev-parse HEAD failed with ${result}") + endif() + + if("${current_git_hash}" STREQUAL "${vcpkg_ref}") + return() + endif() + + message(STATUS "Upgrade vcpkg") + message(STATUS "vcpkg current commit: ${current_git_hash}") + message(STATUS "vcpkg release: ${vcpkg_ref}") + + execute_process( + COMMAND ${GIT_EXECUTABLE} remote set-url origin ${vcpkg_repo} + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message(FATAL_ERROR "failed to change origin to ${vcpkg_repo}") + endif() + + execute_process( + COMMAND ${GIT_EXECUTABLE} fetch + WORKING_DIRECTORY ${vcpkg_root} + RESULT_VARIABLE result) + + if(NOT result EQUAL "0") + message(FATAL_ERROR "${GIT_EXECUTABLE} fetch failed with ${result}") + endif() + + _vcpkg_stash(${vcpkg_root}) + _vcpkg_checkout(${vcpkg_root} ${vcpkg_ref}) + _vcpkg_tool_bootstrap(${vcpkg_root}) +endfunction() + +# find root +function(_vcpkg_find_root cache_dir_name out_vcpkg_root) + if(DEFINED ENV{VCPKG_ROOT} AND NOT "$ENV{VCPKG_ROOT}" STREQUAL "") + set(root "$ENV{VCPKG_ROOT}") + elseif("${__vcpkg_bootstrap_host}" STREQUAL "Windows") + set(root "$ENV{LOCALAPPDATA}/vcpkg/projects/${cache_dir_name}/cache") + else() + set(root "$ENV{HOME}/.cache/vcpkg/projects/${cache_dir_name}") + endif() + + set(${out_vcpkg_root} + ${root} + PARENT_SCOPE) +endfunction() + +# set vcpkg_root/toolchain_file cache variables +function(_vcpkg_set_cache_variables vcpkg_root) + set(_VCPKG_ROOT + "${vcpkg_root}" + CACHE INTERNAL "vcpkg root") + + set(_VCPKG_TOOLCHAIN_FILE + "${vcpkg_root}/scripts/buildsystems/vcpkg.cmake" + CACHE INTERNAL "vcpkg toolchain file") +endfunction() + +# bootstrap +function(_vcpkg_bootstrap) + cmake_parse_arguments(PARSE_ARGV 0 "arg" "" "CACHE_DIR_NAME;REPO;REF" "") + + if(DEFINED arg_UNPARSED_ARGUMENTS) + message( + FATAL_ERROR "internal error: ${CMAKE_CURRENT_FUNCTION} passed extra args:" + "${arg_UNPARSED_ARGUMENTS}") + endif() + + find_package(Git QUIET REQUIRED) + + if(DEFINED CACHE{_VCPKG_ROOT}) + set(vcpkg_root $CACHE{_VCPKG_ROOT}) + else() + _vcpkg_find_root("${arg_CACHE_DIR_NAME}" vcpkg_root) + endif() + + if(NOT EXISTS ${vcpkg_root}) + message(STATUS "Setup vcpkg") + _vcpkg_clone(${vcpkg_root} ${arg_REPO} ${arg_REF}) + _vcpkg_tool_bootstrap(${vcpkg_root}) + else() + message(STATUS "Found vcpkg in: ${vcpkg_root}") + _vcpkg_upgrade(${vcpkg_root} ${arg_REPO} ${arg_REF}) + endif() + + _vcpkg_set_cache_variables("${vcpkg_root}") +endfunction() diff --git a/template/cmake/vcpkg/bootstrap/vcpkg_chainload_toolchain.cmake b/template/cmake/vcpkg/bootstrap/vcpkg_chainload_toolchain.cmake new file mode 100644 index 0000000..2cff74e --- /dev/null +++ b/template/cmake/vcpkg/bootstrap/vcpkg_chainload_toolchain.cmake @@ -0,0 +1,45 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +# configure VCPKG_CHAINLOAD_TOOLCHAIN_FILE based on VCPKG_TARGET_TRIPLET and +# VCPKG_TARGET_ARCHITECTURE +function(_vcpkg_chainload_toolchain) + if(DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE) + return() + endif() + + if(NOT DEFINED VCPKG_TARGET_TRIPLET OR NOT DEFINED VCPKG_TARGET_ARCHITECTURE) + message( + FATAL_ERROR + "VCPKG_TARGET_TRIPLET and VCPKG_TARGET_ARCHITECTURE must be set before calling _vcpkg_chainload_toolchain()" + ) + endif() + + # Load toolchain variables from triplet and architecture + + string(LENGTH "${VCPKG_TARGET_ARCHITECTURE}-" _prefix_len) + string(SUBSTRING ${VCPKG_TARGET_TRIPLET} ${_prefix_len} -1 _stripped_string) + string(REPLACE "-" ";" _triplet_parts "${_stripped_string}") + list(GET _triplet_parts 0 _chainload_toolchain_name) + + set(_toolchain "scripts/toolchains/${_chainload_toolchain_name}.cmake") + + if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${_toolchain}") + set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE + "${CMAKE_CURRENT_LIST_DIR}/${_toolchain}" + CACHE INTERNAL "vcpkg chainload") + elseif(EXISTS "${_VCPKG_ROOT}/${_toolchain}") + set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE + "${_VCPKG_ROOT}/${_toolchain}" + CACHE INTERNAL "vcpkg chainload") + else() + message( + WARNING + "Could not find toolchain file for ${_chainload_toolchain_name}, skipping chainload" + ) + endif() + message( + STATUS "vcpkg_chainload_toolchain_file: ${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}") +endfunction() diff --git a/template/cmake/vcpkg/bootstrap/vcpkg_configure.cmake b/template/cmake/vcpkg/bootstrap/vcpkg_configure.cmake new file mode 100644 index 0000000..2f63cc3 --- /dev/null +++ b/template/cmake/vcpkg/bootstrap/vcpkg_configure.cmake @@ -0,0 +1,55 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +function(_vcpkg_export_mode) + if(_VCPKG_ROOT) + _vcpkg_bootstrap(${ARGN}) + _vcpkg_skip_install_on_reconfigure() + endif() + + set(_export_export_dir "${CMAKE_SOURCE_DIR}/cmake/vcpkg/export") + set(_export_vcpkg_root "${_export_export_dir}/${VCPKG_TARGET_TRIPLET}") + _vcpkg_setup_export("${_export_export_dir}" "${_export_vcpkg_root}") + + # Set vcpkg root and toolchian file variables to target the exported artifacts + if(NOT EXISTS "${_export_vcpkg_root}") + message( + FATAL_ERROR + "vcpkg export not found for triplet ${VCPKG_TARGET_TRIPLET}, check vcpkg logs for details" + ) + endif() + + message( + STATUS "Using vcpkg exported artifacts as vcpkg root: ${_export_vcpkg_root}" + ) + + _vcpkg_set_cache_variables("${_export_vcpkg_root}") + + # Disable vcpkg.cmake to read the cache variable to check if it should install + # packages + set(VCPKG_MANIFEST_DIR + "" + CACHE PATH "vcpkg manifest dir" FORCE) + message(STATUS "Disable manifest mode for using vcpkg exported artifacts") +endfunction() + +# bootstrap and configure vcpkg +macro(vcpkg_configure) + if(NOT VCPKG_EXPORT_MODE) + _vcpkg_bootstrap(${ARGN}) + _vcpkg_skip_install_on_reconfigure() + endif() + + _vcpkg_load_triplet() + + if(VCPKG_EXPORT_MODE) + _vcpkg_export_mode(${ARGN}) + endif() + + _vcpkg_chainload_toolchain() + message(STATUS "vcpkg_toolchain_file:$CACHE{_VCPKG_TOOLCHAIN_FILE}") + include("$CACHE{_VCPKG_TOOLCHAIN_FILE}") +endmacro() diff --git a/template/cmake/vcpkg/bootstrap/vcpkg_export_mode.cmake b/template/cmake/vcpkg/bootstrap/vcpkg_export_mode.cmake new file mode 100644 index 0000000..2b6e0b9 --- /dev/null +++ b/template/cmake/vcpkg/bootstrap/vcpkg_export_mode.cmake @@ -0,0 +1,97 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +# This function using vcpkg install and export to export vcpkg artifacts to +# ${CMAKE_SOURCE_DIR}/cmake/vcpkg/export +function(_vcpkg_setup_export export_export_dir export_vcpkg_root) + set(_export_install_dir + "${CMAKE_SOURCE_DIR}/out/vcpkg_installed/${VCPKG_TARGET_TRIPLET}") + + # Update exported artifacts when _VCPKG_ROOT is found + if(DEFINED _VCPKG_ROOT AND NOT ${export_vcpkg_root} STREQUAL _VCPKG_ROOT) + message( + STATUS + "Exporting vcpkg to ${export_vcpkg_root} when VCPKG_EXPORT_MODE is enabled" + ) + + if("${__vcpkg_bootstrap_host}" STREQUAL "Windows") + set(vcpkg_cmd "$CACHE{_VCPKG_ROOT}/vcpkg.exe") + else() + set(vcpkg_cmd "$CACHE{_VCPKG_ROOT}/vcpkg") + endif() + + if(NOT EXISTS ${vcpkg_cmd}) + message( + FATAL_ERROR + "vcpkg executable not found when export_with_manifest enabled: ${vcpkg_cmd}" + ) + endif() + + if(DEFINED VCPKG_FEATURE_FLAGS OR DEFINED CACHE{VCPKG_FEATURE_FLAGS}) + list(JOIN VCPKG_FEATURE_FLAGS "," vcpkg_feature_flags) + set(vcpkg_feature_flags "--feature-flags=${vcpkg_feature_flags}") + endif() + + foreach(_vcpkg_feature IN LISTS VCPKG_MANIFEST_FEATURES) + list(APPEND vcpkg_additional_manifest_params + "--x-feature=${_vcpkg_feature}") + endforeach() + + if(VCPKG_MANIFEST_NO_DEFAULT_FEATURES) + list(APPEND vcpkg_additional_manifest_params "--x-no-default-features") + endif() + + if(DEFINED VCPKG_HOST_TRIPLET AND NOT VCPKG_HOST_TRIPLET STREQUAL "") + list(APPEND vcpkg_additional_manifest_params + "--host-triplet=${VCPKG_HOST_TRIPLET}") + endif() + + set(_additional_args + --vcpkg-root + ${_VCPKG_ROOT} + --overlay-ports + "${VCPKG_OVERLAY_PORTS}" + --overlay-triplets + "${VCPKG_OVERLAY_TRIPLETS}" + --triplet + ${VCPKG_TARGET_TRIPLET} + --x-install-root + "${_export_install_dir}") + + execute_process( + COMMAND + ${vcpkg_cmd} install "--x-wait-for-lock" + "--x-manifest-root=${CMAKE_SOURCE_DIR}" ${_additional_args} + ${vcpkg_feature_flags} ${vcpkg_additional_manifest_params} + ${VCPKG_INSTALL_OPTIONS} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + RESULT_VARIABLE install_packages_result) + + if(NOT install_packages_result EQUAL 0) + message( + FATAL_ERROR + "vcpkg install failed with ${install_packages_result}, check vcpkg logs for details" + ) + endif() + + execute_process( + COMMAND ${vcpkg_cmd} export --raw --output ${VCPKG_TARGET_TRIPLET} + --output-dir ${export_export_dir} ${_additional_args} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + RESULT_VARIABLE export_packages_result) + + if(NOT export_packages_result EQUAL 0) + message( + FATAL_ERROR + "vcpkg export failed with ${export_packages_result}, check vcpkg logs for details" + ) + endif() + + file(COPY "${_VCPKG_ROOT}/triplets" DESTINATION "${export_vcpkg_root}") + + file(COPY "${_VCPKG_ROOT}/scripts/toolchains" + DESTINATION "${export_vcpkg_root}/scripts") + endif() +endfunction() diff --git a/template/cmake/vcpkg/bootstrap/vcpkg_load_triplet.cmake b/template/cmake/vcpkg/bootstrap/vcpkg_load_triplet.cmake new file mode 100644 index 0000000..6ceb2f0 --- /dev/null +++ b/template/cmake/vcpkg/bootstrap/vcpkg_load_triplet.cmake @@ -0,0 +1,225 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +# copied from vcpkg vcpkg.cmake +function(_vcpkg_detect_host_triplet) + if(DEFINED VCPKG_TARGET_TRIPLET) + return() + endif() + + if(CMAKE_GENERATOR_PLATFORM MATCHES "^[Ww][Ii][Nn]32$") + set(_detect_target_triplet_arch x86) + elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Xx]64$") + set(_detect_target_triplet_arch x64) + elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Aa][Rr][Mm]$") + set(_detect_target_triplet_arch arm) + elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Aa][Rr][Mm]64$") + set(_detect_target_triplet_arch arm64) + else() + if(CMAKE_GENERATOR STREQUAL "Visual Studio 14 2015 Win64") + set(_detect_target_triplet_arch x64) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 14 2015 ARM") + set(_detect_target_triplet_arch arm) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 14 2015") + set(_detect_target_triplet_arch x86) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 15 2017 Win64") + set(_detect_target_triplet_arch x64) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 15 2017 ARM") + set(_detect_target_triplet_arch arm) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 15 2017") + set(_detect_target_triplet_arch x86) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 16 2019" + AND CMAKE_VS_PLATFORM_NAME_DEFAULT STREQUAL "ARM64") + set(_detect_target_triplet_arch arm64) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 16 2019") + set(_detect_target_triplet_arch x64) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 17 2022" + AND CMAKE_VS_PLATFORM_NAME_DEFAULT STREQUAL "ARM64") + set(_detect_target_triplet_arch arm64) + elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 17 2022") + set(_detect_target_triplet_arch x64) + elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND DEFINED + CMAKE_OSX_ARCHITECTURES) + list(LENGTH CMAKE_OSX_ARCHITECTURES _detect_osx_arch_count) + if(_detect_osx_arch_count EQUAL "0") + message( + WARNING + "Unable to determine target architecture from ${CMAKE_OSX_ARCHITECTURES}. " + "Consider providing a value for the CMAKE_OSX_ARCHITECTURES cache variable. " + "Continuing without vcpkg.") + set(VCPKG_TOOLCHAIN ON) + cmake_policy(POP) + return() + endif() + + if(_detect_osx_arch_count GREATER "1") + message( + WARNING + "Detected more than one target architecture from ${CMAKE_OSX_ARCHITECTURES}. Using the first one." + ) + endif() + list(GET CMAKE_OSX_ARCHITECTURES "0" _detect_osx_target_arch) + if(_detect_osx_target_arch STREQUAL "arm64") + set(_detect_target_triplet_arch arm64) + elseif(_detect_osx_target_arch STREQUAL "arm64s") + set(_detect_target_triplet_arch arm64s) + elseif(_detect_osx_target_arch STREQUAL "armv7s") + set(_detect_target_triplet_arch armv7s) + elseif(_detect_osx_target_arch STREQUAL "armv7") + set(_detect_target_triplet_arch arm) + elseif(_detect_osx_target_arch STREQUAL "x86_64") + set(_detect_target_triplet_arch x64) + elseif(_detect_osx_target_arch STREQUAL "i386") + set(_detect_target_triplet_arch x86) + else() + message( + WARNING + "Unable to determine target architecture from ${CMAKE_OSX_ARCHITECTURES}, continuing without vcpkg." + ) + set(VCPKG_TOOLCHAIN ON) + cmake_policy(POP) + return() + endif() + else() + find_program(_vcpkg_cl cl) + if(_vcpkg_cl MATCHES "amd64/cl.exe$" OR _vcpkg_cl MATCHES "x64/cl.exe$") + set(_detect_target_triplet_arch x64) + elseif(_vcpkg_cl MATCHES "arm/cl.exe$") + set(_detect_target_triplet_arch arm) + elseif(_vcpkg_cl MATCHES "arm64/cl.exe$") + set(_detect_target_triplet_arch arm64) + elseif(_vcpkg_cl MATCHES "bin/cl.exe$" OR _vcpkg_cl MATCHES "x86/cl.exe$") + set(_detect_target_triplet_arch x86) + elseif( + CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64" + OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64" + OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "amd64") + set(_detect_target_triplet_arch x64) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^i.86$") + set(_detect_target_triplet_arch x86) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "s390x") + set(_detect_target_triplet_arch s390x) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "ppc64le") + set(_detect_target_triplet_arch ppc64le) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "armv7l") + set(_detect_target_triplet_arch arm) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|ARM64)$") + set(_detect_target_triplet_arch arm64) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "riscv32") + set(_detect_target_triplet_arch riscv32) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "riscv64") + set(_detect_target_triplet_arch riscv64) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "loongarch32") + set(_detect_target_triplet_arch loongarch32) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "loongarch64") + set(_detect_target_triplet_arch loongarch64) + else() + message( + WARNING + "Unable to determine target architecture from ${CMAKE_HOST_SYSTEM_PROCESSOR}, continuing without vcpkg." + ) + set(VCPKG_TOOLCHAIN ON) + cmake_policy(POP) + return() + endif() + endif() + endif() + + # detect the target platform + if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" OR CMAKE_SYSTEM_NAME STREQUAL + "WindowsPhone") + set(_detect_target_triplet_plat uwp) + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" + OR (NOT CMAKE_SYSTEM_NAME AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")) + set(_detect_target_triplet_plat linux) + elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" + OR (NOT CMAKE_SYSTEM_NAME AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" + )) + set(_detect_target_triplet_plat osx) + elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS") + set(_detect_target_triplet_plat ios) + elseif(MINGW) + set(_detect_target_triplet_plat mingw-dynamic) + elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows" + OR (NOT CMAKE_SYSTEM_NAME AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" + )) + if(XBOX_CONSOLE_TARGET STREQUAL "scarlett") + set(_detect_target_triplet_plat xbox-scarlett) + elseif(XBOX_CONSOLE_TARGET STREQUAL "xboxone") + set(_detect_target_triplet_plat xbox-xboxone) + else() + set(_detect_target_triplet_plat windows) + endif() + elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" + OR (NOT CMAKE_SYSTEM_NAME AND CMAKE_HOST_SYSTEM_NAME STREQUAL "FreeBSD" + )) + set(_detect_target_triplet_plat freebsd) + elseif(CMAKE_SYSTEM_NAME STREQUAL "Android" + OR (NOT CMAKE_SYSTEM_NAME AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Android" + )) + set(_detect_target_triplet_plat android) + endif() + + if(EMSCRIPTEN) + set(_detect_target_triplet_arch wasm32) + set(_detect_target_triplet_plat emscripten) + endif() + + if(NOT _detect_target_triplet_arch STREQUAL "" + AND NOT _detect_target_triplet_plat STREQUAL "") + set(VCPKG_DETECT_TRIPLET_ARCH + ${_detect_target_triplet_arch} + PARENT_SCOPE) + set(VCPKG_DETECT_TRIPLET_PLAT + ${_detect_target_triplet_plat} + PARENT_SCOPE) + set(VCPKG_HOST_TRIPLET + "${_detect_target_triplet_arch}-${_detect_target_triplet_plat}" + PARENT_SCOPE) + endif() +endfunction() + +# load the triplet by VCPKG_TARGET_TRIPLET +macro(_vcpkg_load_triplet) + if(NOT DEFINED VCPKG_TARGET_TRIPLET) + message( + STATUS + "VCPKG_TARGET_TRIPLET is not defined, detecting triplet from the system" + ) + + _vcpkg_detect_host_triplet() + + if(DEFINED VCPKG_HOST_TRIPLET) + set(VCPKG_TARGET_TRIPLET "${VCPKG_HOST_TRIPLET}") + message(STATUS "Detected triplet: ${VCPKG_TARGET_TRIPLET}") + else() + message( + FATAL_ERROR + "Unable to determine target triplet, please set it manually.") + endif() + endif() + + # Load triplet variables from VCPKG_TARGET_TRIPLET triplet file + + set(_triplet "triplets/${VCPKG_TARGET_TRIPLET}.cmake") + set(_community_triplet "triplets/community/${VCPKG_TARGET_TRIPLET}.cmake") + + if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${_triplet}") + include("${CMAKE_CURRENT_LIST_DIR}/${_triplet}") + elseif(EXISTS "${_VCPKG_ROOT}/${_triplet}") + include("${_VCPKG_ROOT}/${_triplet}") + elseif(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${_community_triplet}") + include("${CMAKE_CURRENT_LIST_DIR}/${_community_triplet}") + elseif(EXISTS "${_VCPKG_ROOT}/${_community_triplet}") + include("${_VCPKG_ROOT}/${_community_triplet}") + else() + message( + FATAL_ERROR + "Triplet ${VCPKG_TARGET_TRIPLET} not found at ${CMAKE_CURRENT_LIST_DIR}/${_triplet} or ${_VCPKG_ROOT}/${_triplet}" + ) + endif() + unset(_triplet) + unset(_community_triplet) +endmacro(_vcpkg_load_triplet) diff --git a/template/cmake/vcpkg/bootstrap/vcpkg_skip_install_on_reconfigure.cmake b/template/cmake/vcpkg/bootstrap/vcpkg_skip_install_on_reconfigure.cmake new file mode 100644 index 0000000..a6c51a5 --- /dev/null +++ b/template/cmake/vcpkg/bootstrap/vcpkg_skip_install_on_reconfigure.cmake @@ -0,0 +1,47 @@ +# SPDX-FileCopyrightText: Copyright 2024 Mikhail Svetkin +# SPDX-License-Identifier: MIT + +function(_vcpkg_update_manifest_hash) + set(_VCPKG_MANIFEST_HASH + "$CACHE{__VCPKG_MANIFEST_HASH}" + CACHE INTERNAL "Hash of vcpkg manifest file") +endfunction() + +# disable vcpkg manifest install step on cmake reconfigure if vcpkg.json has not +# changed. +function(_vcpkg_skip_install_on_reconfigure) + if(DEFINED CACHE{VCPKG_MANIFEST_DIR} AND NOT $CACHE{VCPKG_MANIFEST_DIR} + STREQUAL "") + set(vcpkg_manifest_file "$CACHE{VCPKG_MANIFEST_DIR}/vcpkg.json") + else() + set(vcpkg_manifest_file "${CMAKE_SOURCE_DIR}/vcpkg.json") + endif() + + file(SHA512 "${vcpkg_manifest_file}" vcpkg_manifest_hash) + + if(DEFINED CACHE{_VCPKG_MANIFEST_HASH} AND _VCPKG_MANIFEST_HASH STREQUAL + vcpkg_manifest_hash) + set(VCPKG_MANIFEST_INSTALL + OFF + CACHE INTERNAL "") + set_property( + DIRECTORY + APPEND + PROPERTY CMAKE_CONFIGURE_DEPENDS "${vcpkg_manifest_file}") + else() + set(VCPKG_MANIFEST_INSTALL + ON + CACHE INTERNAL "") + endif() + + # I was not able to propagate vcpkg_manifest_hash via defer call, so + # workaround it with another cache variable. + set(__VCPKG_MANIFEST_HASH + "${vcpkg_manifest_hash}" + CACHE INTERNAL "") + + # set actual hash only when vcpkg install command succeed. The only way you to + # detect to assume that configuration step succeed. + cmake_language(DEFER DIRECTORY ${CMAKE_SOURCE_DIR} CALL + _vcpkg_update_manifest_hash) +endfunction() diff --git a/template/cmake/vcpkg/ports/README.md b/template/cmake/vcpkg/ports/README.md new file mode 100644 index 0000000..a129778 --- /dev/null +++ b/template/cmake/vcpkg/ports/README.md @@ -0,0 +1,3 @@ +# Customize vcpkg ports + +This folder applies to the custom vcpkg ports. These ports are loaded automatically which can be patched from the `ports` folder of the vcpkg repository or created from scratch. diff --git a/template/cmake/vcpkg/ports/python3/portfile.cmake b/template/cmake/vcpkg/ports/python3/portfile.cmake new file mode 100644 index 0000000..bd750d8 --- /dev/null +++ b/template/cmake/vcpkg/ports/python3/portfile.cmake @@ -0,0 +1,3 @@ +message(WARNING "Using fake python3 to force system libraries.") + +set(VCPKG_POLICY_EMPTY_PACKAGE enabled) diff --git a/template/cmake/vcpkg/ports/python3/vcpkg.json b/template/cmake/vcpkg/ports/python3/vcpkg.json new file mode 100644 index 0000000..e7749c5 --- /dev/null +++ b/template/cmake/vcpkg/ports/python3/vcpkg.json @@ -0,0 +1,7 @@ +{ + "name": "python3", + "version": "3.11.8", + "description": "The Python programming language", + "homepage": "https://github.com/python/cpython", + "license": "Python-2.0" +} diff --git a/template/cmake/vcpkg/scripts/build_type.cmake b/template/cmake/vcpkg/scripts/build_type.cmake new file mode 100644 index 0000000..a49dad6 --- /dev/null +++ b/template/cmake/vcpkg/scripts/build_type.cmake @@ -0,0 +1,26 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2024 msclock + +This module initializes the build type. +]] + +if(NOT CMAKE_BUILD_TYPE) + message(STATUS "Setting CMAKE_BUILD_TYPE to 'Debug' as none was specified.") +endif() +set(CMAKE_BUILD_TYPE + Debug + CACHE STRING "Choose the type of build.") + +# Set the possible values of build type for cmake-gui, ccmake +get_property(_builtin_build_types GLOBAL PROPERTY CMAKE_BUILD_TYPE) + +foreach(_type "Debug" "Release" "MinSizeRel" "RelWithDebInfo") + if(NOT _type IN_LIST _builtin_build_types) + list(APPEND _builtin_build_types ${_type}) + endif() +endforeach() + +set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${_builtin_build_types}) + +unset(_builtin_build_types) diff --git a/template/cmake/vcpkg/scripts/toolchains/README.md b/template/cmake/vcpkg/scripts/toolchains/README.md new file mode 100644 index 0000000..2b60435 --- /dev/null +++ b/template/cmake/vcpkg/scripts/toolchains/README.md @@ -0,0 +1,3 @@ +# Customize vcpkg toolchains + +This folder applies to the custom vcpkg toolchains. These toolchains can be loaded automatically which can be copied from the `scripts/toolchains` folder of the vcpkg repository or created from scratch. diff --git a/template/cmake/vcpkg/triplets/README.md b/template/cmake/vcpkg/triplets/README.md new file mode 100644 index 0000000..74db63a --- /dev/null +++ b/template/cmake/vcpkg/triplets/README.md @@ -0,0 +1,22 @@ +# Customize vcpkg triplets + +This folder applies to the custom vcpkg triplets. These triplets are loaded automatically which can be copied from the `triplets` folder of the vcpkg repository or created from scratch. + +For example, to create a custom triplet for Linux x64 with dynamic library linkage: + +```bash +# Copy the triplet from the vcpkg repository +cp /path/to/vcpkg/repository/triplets/x64-linux.cmake ./x64-linux.cmake +# Edit the triplet to change the library linkage to dynamic +sed -i ./x64-linux.cmake -e's/set(VCPKG_LIBRARY_LINKAGE static)/set(VCPKG_LIBRARY_LINKAGE dynamic)/g' +# Show the contents of the triplet +cat ./x64-linux.cmake +# set(VCPKG_TARGET_ARCHITECTURE x64) +# set(VCPKG_CRT_LINKAGE dynamic) +# set(VCPKG_LIBRARY_LINKAGE dynamic) + +# set(VCPKG_CMAKE_SYSTEM_NAME Linux) + +# Use it when configure the project +cmake --preset=default -DVCPKG_TARGET_TRIPLET=x64-linux +``` diff --git a/template/cmake/vcpkg/vcpkg.toolchain.cmake.jinja b/template/cmake/vcpkg/vcpkg.toolchain.cmake.jinja new file mode 100644 index 0000000..690c74f --- /dev/null +++ b/template/cmake/vcpkg/vcpkg.toolchain.cmake.jinja @@ -0,0 +1,47 @@ +#[[ +SPDX-License-Identifier: MIT +SPDX-FileCopyrightText: Copyright 2023 Mikhail Svetkin +SPDX-FileCopyrightText: Copyright 2024 msclock +]] + +include_guard(GLOBAL) + +cmake_minimum_required(VERSION 3.25) + +get_property(IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE) + +if(IN_TRY_COMPILE) + return() +endif() + +unset(IN_TRY_COMPILE) + +# Load the common settings +include(${CMAKE_CURRENT_LIST_DIR}/scripts/build_type.cmake) + +# Vcpkg build environment +file(READ ${CMAKE_SOURCE_DIR}/vcpkg.json _vcpkg_json) +string(JSON _builtin_baseline GET ${_vcpkg_json} builtin-baseline) + +# Respect environment variable VCPKG_ROOT and VCPKG_INSTALLATION_ROOT if set +if(DEFINED ENV{VCPKG_ROOT} AND NOT "$ENV{VCPKG_ROOT}" STREQUAL "") + set(_VCPKG_ROOT + "$ENV{VCPKG_ROOT}" + CACHE PATH "Vcpkg root directory" FORCE) +elseif(DEFINED ENV{VCPKG_INSTALLATION_ROOT} + AND NOT "$ENV{VCPKG_INSTALLATION_ROOT}" STREQUAL "") + set(_VCPKG_ROOT + "$ENV{VCPKG_INSTALLATION_ROOT}" + CACHE PATH "Vcpkg root directory" FORCE) +else() + unset(_VCPKG_ROOT CACHE) +endif() + +include(${CMAKE_CURRENT_LIST_DIR}/bootstrap/vcpkg-config.cmake) + +set(VCPKG_VERBOSE + ON + CACHE BOOL "Vcpkg VCPKG_VERBOSE") + +vcpkg_configure(CACHE_DIR_NAME {{ repo_name}} REPO + https://github.com/microsoft/vcpkg.git REF ${_builtin_baseline}) diff --git a/template/noxfile.py.jinja b/template/noxfile.py.jinja new file mode 100644 index 0000000..4b54441 --- /dev/null +++ b/template/noxfile.py.jinja @@ -0,0 +1,132 @@ +from __future__ import annotations + +import argparse +import shutil +from pathlib import Path + +import nox + +DIR = Path(__file__).parent.resolve() + +nox.options.sessions = ["lint", "pylint", "tests"] + + +@nox.session +def lint(session: nox.Session) -> None: + """ + Run the linter. + """ + session.install("pre-commit") + session.run( + "pre-commit", "run", "--all-files", "--show-diff-on-failure", *session.posargs + ) + + +@nox.session +def pylint(session: nox.Session) -> None: + """ + Run PyLint. + """ + # This needs to be installed into the package environment, and is slower + # than a pre-commit check + session.install(".", "pylint") + session.run("pylint", "{{ repo_name }}", *session.posargs) + + +@nox.session +def tests(session: nox.Session) -> None: + """ + Run the unit and regular tests. + """ + session.install(".[test]") + session.run("pytest", *session.posargs) + + +@nox.session(reuse_venv=True) +def docs(session: nox.Session) -> None: + """ + Build the docs. Pass "--serve" to serve. Pass "-b linkcheck" to check links. + """ + + parser = argparse.ArgumentParser() + parser.add_argument("--serve", action="store_true", help="Serve after building") + parser.add_argument( + "-b", dest="builder", default="html", help="Build target (default: html)" + ) + args, posargs = parser.parse_known_args(session.posargs) + + if args.builder != "html" and args.serve: + session.error("Must not specify non-HTML builder with --serve") + + extra_installs = ["sphinx-autobuild"] if args.serve else [] + + session.install("-e.[docs]", *extra_installs) + session.chdir("docs") + + if args.builder == "linkcheck": + session.run( + "sphinx-build", "-b", "linkcheck", ".", "_build/linkcheck", *posargs + ) + return + + shared_args = ( + "-n", # nitpicky mode + "-T", # full tracebacks + f"-b={args.builder}", + ".", + f"_build/{args.builder}", + *posargs, + ) + + if args.serve: + session.run("sphinx-autobuild", *shared_args) + else: + session.run("sphinx-build", "--keep-going", *shared_args) + + +@nox.session +def build(session: nox.Session) -> None: + """ + Build an SDist and wheel. + """ + + build_path = DIR.joinpath("build") + if build_path.exists(): + shutil.rmtree(build_path) + + session.install("build") + session.run("python", "-m", "build") +[% if repo_name == 'ss-pybind11' %] + +@nox.session(reuse_venv=True) +def template_build(session: nox.Session) -> None: + """ + Build template for the current repo only. + """ + import os + + excludes = [".", ".git", "template", "includes", ".nox", "copier.yml"] + for dir_item in os.listdir("."): + if dir_item in excludes: + continue + if Path(dir_item).is_dir(): + shutil.rmtree(dir_item) + else: + Path(dir_item).unlink() + + session.run( + "pipx", + "run", + "copier==9.3.1", + "copy", + "-r", + "HEAD", + "--data-file", + "includes/copier-answers-sample.yml", + *session.posargs, + "-f", + ".", + ".", + ) + Path(".copier-answers.yml").unlink() +[%- endif %] diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja new file mode 100644 index 0000000..db33cbe --- /dev/null +++ b/template/pyproject.toml.jinja @@ -0,0 +1,205 @@ +[% from pathjoin("includes", "version_compare.jinja") import version_between -%] +[build-system] +requires = ["scikit-build-core"] +build-backend = "scikit_build_core.build" + +[project] +name = "{{ module_name }}" +description = "{{ project_description }}" +readme = "README.md" +[%- if copyright_license == "Apache Software License" %] +license = { text = "Apache-2.0" } +[%- elif copyright_license == "Boost Software License 1.0 (BSL-1.0)" %] +license = { text = "BSL-1.0" } +[%- elif copyright_license == "GNU Affero General Public License v3" %] +license = { text = "AGPLv3" } +[%- elif copyright_license == "GNU General Public License v3 (GPLv3)" %] +license = { text = "GPLv3" } +[%- elif copyright_license == "GNU Lesser General Public License v3 (LGPLv3)" %] +license = { text = "LGPLv3" } +[%- elif copyright_license == "MIT License" %] +license = { text = "MIT" } +[%- elif copyright_license == "Mozilla Public License 2.0 (MPL 2.0)" %] +license = { text = "MPL-2.0" } +[%- elif copyright_license == "The Unlicense (Unlicense)" %] +license = { text = "Unlicense" } +[%- endif %] +authors = [ + { email = "{{ author_email }}", name = "{{ author_name }}" }, +] +requires-python = ">={{ min_py }}" +classifiers = [ +[%- if development_status == "Planning" %] + "Development Status :: 1 - Planning", +[%- elif development_status == "Alpha" %] + "Development Status :: 3 - Alpha", +[%- elif development_status == "Beta" %] + "Development Status :: 4 - Beta", +[%- elif development_status == "Stable" %] + "Development Status :: 5 - Production/Stable", +[%- endif %] + "Intended Audience :: Science/Research", + "Intended Audience :: Developers", + "License :: OSI Approved :: {{ copyright_license }}", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", +[%- if version_between("3.8", min_py, max_py) %] + "Programming Language :: Python :: 3.8", +[%- endif %] +[%- if version_between("3.9", min_py, max_py) %] + "Programming Language :: Python :: 3.9", +[%- endif %] +[%- if version_between("3.10", min_py, max_py) %] + "Programming Language :: Python :: 3.10", +[%- endif %] +[%- if version_between("3.11", min_py, max_py) %] + "Programming Language :: Python :: 3.11", +[%- endif %] +[%- if version_between("3.12", min_py, max_py) %] + "Programming Language :: Python :: 3.12", +[%- endif %] +[%- if version_between("3.13", min_py, max_py) %] + "Programming Language :: Python :: 3.13", +[%- endif %] + "Topic :: Scientific/Engineering", + "Typing :: Typed", +] +dynamic = ["version"] +dependencies = ["typing-extensions >=3.10.0; python_version<'3.9'"] + +[project.optional-dependencies] +test = ["pytest >=6", "pytest-cov >=3"] +dev = ["pytest >=6", "pytest-cov >=3"] +docs = [ +[%- if docs_type == 'sphinx' %] + "sphinx>=7.0", + "myst_parser>=0.13", + "sphinx_copybutton", + "sphinx_autodoc_typehints", + "furo>=2023.08.17", +[%- endif %] +[%- if docs_type == 'mkdocs' %] + "mkdocs>=1.6.0", + "mkdocs-git-revision-date-localized-plugin>=1.2.6", + "mkdocs-material>=9.5.29", + "mkdocs-minify-plugin>=0.8.0", + "mkdocs-same-dir>=0.1.3", +[%- endif %] +] + +[project.urls] +Homepage = "https://github.com/serious-scaffold/{{ repo_name }}" +"Bug Tracker" = "https://github.com/serious-scaffold/{{ repo_name }}/issues" +Discussions = "https://github.com/serious-scaffold/{{ repo_name }}/discussions" +Changelog = "https://github.com/serious-scaffold/{{ repo_name }}/releases" + +[tool.scikit-build] +minimum-version = "0.4" +build-dir = "build/{wheel_tag}" +metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" +sdist.include = ["src/{{ module_name }}/_version.py"] +cmake.args = [ + "-DBUILD_TESTING=OFF", + "-DCMAKE_TOOLCHAIN_FILE=cmake/vcpkg/vcpkg.toolchain.cmake", + "-DVCPKG_OVERLAY_TRIPLETS=cmake/vcpkg/triplets", + "-DVCPKG_OVERLAY_PORTS=cmake/vcpkg/ports" +] + +[tool.setuptools_scm] +write_to = "src/{{ module_name }}/_version.py" + +[tool.cibuildwheel] +test-command = "pytest {project}/tests" +test-extras = ["test"] +test-skip = ["*universal2:arm64"] + +[tool.cibuildwheel.linux] +before-build =[ + 'yum install zip -y || apk add zip || true', + 'apt update && apt install zip -y || true', + 'pip install cmake ninja', + 'cmake --version', 'git --version', 'ninja --version', +] + +[tool.pytest.ini_options] +minversion = "6.0" +addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"] +xfail_strict = true +filterwarnings = ["error"] +log_cli_level = "INFO" +testpaths = ["tests"] + +[tool.coverage] +run.source = ["{{ module_name }}"] +report.exclude_also = ['\.\.\.', 'if typing.TYPE_CHECKING:'] + +[tool.mypy] +files = ["src", "tests"] +python_version = "3.8" +warn_unused_configs = true +strict = true +enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] +warn_unreachable = true +disallow_untyped_defs = false +disallow_incomplete_defs = false + +[[tool.mypy.overrides]] +module = "{{ module_name }}.*" +disallow_untyped_defs = true +disallow_incomplete_defs = true + +[tool.ruff] +src = ["src"] + +[tool.ruff.lint] +extend-select = [ + "B", # flake8-bugbear + "I", # isort + "ARG", # flake8-unused-arguments + "C4", # flake8-comprehensions + "EM", # flake8-errmsg + "ICN", # flake8-import-conventions + "G", # flake8-logging-format + "PGH", # pygrep-hooks + "PIE", # flake8-pie + "PL", # pylint + "PT", # flake8-pytest-style + "PTH", # flake8-use-pathlib + "RET", # flake8-return + "RUF", # Ruff-specific + "SIM", # flake8-simplify + "T20", # flake8-print + "UP", # pyupgrade + "YTT", # flake8-2020 + "EXE", # flake8-executable + "NPY", # NumPy specific rules + "PD", # pandas-vet +] +ignore = [ + "PLR09", # Too many <...> + "PLR2004", # Magic value used in comparison + "ISC001", # Conflicts with formatter +] +isort.required-imports = ["from __future__ import annotations"] +# Uncomment if using a _compat.typing backport +# typing-modules = ["{{ module_name }}._compat.typing"] + +[tool.ruff.lint.per-file-ignores] +"tests/**" = ["T20"] +"noxfile.py" = ["T20"] + +[tool.pylint] +py-version = "{{ min_py }}" +ignore-paths = [".*/_version.py"] +extension-pkg-allow-list = ["{{ module_name }}._core"] +reports.output-format = "colorized" +similarities.ignore-imports = "yes" +messages_control.disable = [ + "design", + "fixme", + "line-too-long", + "missing-module-docstring", + "wrong-import-position", +] diff --git a/template/src/CMakeLists.txt b/template/src/CMakeLists.txt new file mode 100644 index 0000000..3b11226 --- /dev/null +++ b/template/src/CMakeLists.txt @@ -0,0 +1,12 @@ +file( + GLOB _sub_dirs + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/*) + +foreach(_sub_dir ${_sub_dirs}) + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_sub_dir}/CMakeLists.txt") + add_subdirectory(${_sub_dir}) + endif() +endforeach() + +unset(_sub_dirs) diff --git a/template/src/_core/CMakeLists.txt b/template/src/_core/CMakeLists.txt new file mode 100644 index 0000000..00222fa --- /dev/null +++ b/template/src/_core/CMakeLists.txt @@ -0,0 +1,26 @@ +set(PYBIND11_FINDPYTHON ON) + +find_package(pybind11 CONFIG REQUIRED) + +set(target_name _core) + +file(GLOB_RECURSE internal_srcs "src/*.cpp") +file(GLOB_RECURSE internal_hdrs "include/*.hpp") + +generate_git_header(VERSION_NAMESPACE_PREFIX _core) + +pybind11_add_module(${target_name} MODULE ${internal_srcs} ${internal_hdrs}) +warn_target(${target_name}) +harden_target(${target_name}) +sanitize_target(${target_name}) + +target_include_interface_directories( + ${target_name} ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_BINARY_DIR}/git_version) + +target_link_libraries(${target_name} PRIVATE ${target_name_internal}) + +install(TARGETS ${target_name} DESTINATION ${SKBUILD_PROJECT_NAME}) + +install_dependency(TARGETS ${target_name} INSTALL_SYSTEM_LIBS + DEPENDS_DESTINATION ${SKBUILD_PROJECT_NAME}) diff --git a/template/src/_core/include/_core.hpp b/template/src/_core/include/_core.hpp new file mode 100644 index 0000000..bf3b3e3 --- /dev/null +++ b/template/src/_core/include/_core.hpp @@ -0,0 +1,3 @@ +#pragma once + +#include "_version.hpp" diff --git a/template/src/_core/src/pybind.cpp b/template/src/_core/src/pybind.cpp new file mode 100644 index 0000000..4caf98c --- /dev/null +++ b/template/src/_core/src/pybind.cpp @@ -0,0 +1,14 @@ +#include +#include "_core.hpp" + +namespace py = pybind11; + +PYBIND11_MODULE(_core, m) { + m.doc() = R"pbdoc( + Pybind11 _core plugin + ----------------------- + .. currentmodule:: _core + )pbdoc"; + + m.attr("__version__") = _core::ProjectVersion(); +} diff --git a/template/src/{{ module_name }}/__init__.py.jinja b/template/src/{{ module_name }}/__init__.py.jinja new file mode 100644 index 0000000..d57fea0 --- /dev/null +++ b/template/src/{{ module_name }}/__init__.py.jinja @@ -0,0 +1,12 @@ +""" +Copyright (c) {{ copyright_year }} {{ copyright_holder }}. All rights reserved. + +{{ repo_name }}: {{ project_description }} +""" + + +from __future__ import annotations + +from ._version import version as __version__ + +__all__ = ["__version__"] diff --git a/template/src/{{ module_name }}/_core.pyi b/template/src/{{ module_name }}/_core.pyi new file mode 100644 index 0000000..2ae8fa0 --- /dev/null +++ b/template/src/{{ module_name }}/_core.pyi @@ -0,0 +1,3 @@ +"""Pybind11 _core plugin interfaces""" + +__version__: str = ... diff --git a/template/src/{{ module_name }}/_version.pyi b/template/src/{{ module_name }}/_version.pyi new file mode 100644 index 0000000..91744f9 --- /dev/null +++ b/template/src/{{ module_name }}/_version.pyi @@ -0,0 +1,4 @@ +from __future__ import annotations + +version: str +version_tuple: tuple[int, int, int] | tuple[int, int, int, str, str] diff --git a/template/src/{{ module_name }}/py.typed b/template/src/{{ module_name }}/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/template/tests/test_compiled.py.jinja b/template/tests/test_compiled.py.jinja new file mode 100644 index 0000000..ff67632 --- /dev/null +++ b/template/tests/test_compiled.py.jinja @@ -0,0 +1,8 @@ +from __future__ import annotations + +from {{ module_name }} import _core + + +def test_core_version(): + core_version: str = _core.__version__ + assert core_version != "" diff --git a/template/tests/test_package.py.jinja b/template/tests/test_package.py.jinja new file mode 100644 index 0000000..884deb0 --- /dev/null +++ b/template/tests/test_package.py.jinja @@ -0,0 +1,9 @@ +from __future__ import annotations + +import importlib.metadata + +import {{ module_name }} as m + + +def test_version(): + assert importlib.metadata.version("{{ module_name }}") == m.__version__ diff --git a/template/vcpkg.json.jinja b/template/vcpkg.json.jinja new file mode 100644 index 0000000..5194b44 --- /dev/null +++ b/template/vcpkg.json.jinja @@ -0,0 +1,82 @@ +[%- from pathjoin("includes", "variable.jinja") import repo_url with context -%] +{ + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", + "name": "{{ repo_name }}", + "description": "{{ project_description }}", + "builtin-baseline": "7adc2e4d49e8d0efc07a369079faa6bc3dbb90f3", + "homepage": "https://{{ repo_url() }}", + "dependencies": [ + "pybind11", +[%- if use_conan == true %] + "cmake-conan", +[%- endif %] +[%- if use_cpm == true %] + "cmake-cpm", +[%- endif %] + "cmake-modules", + "robotology-cmake-ycm" + ], + "overrides": [ + { + "name": "pybind11", + "version": "2.13.5" + }, +[%- if use_conan == true %] + { + "name": "cmake-conan", + "version": "0.18.1" + }, +[%- endif %] +[%- if use_cpm == true %] + { + "name": "cmake-cpm", + "version": "0.38.6#2" + }, +[%- endif %] + { + "name": "cmake-modules", + "version": "1.6.5" + }, + { + "name": "robotology-cmake-ycm", + "version": "0.16.3" + } + ], + "features": { + "test": { + "description": "Dependencies for testing", + "dependencies": [ + { + "name": "gtest", + "version>=": "1.14.0" + } + ] + } + }, + "vcpkg-configuration": { + "registries": [ + { + "kind": "git", + "baseline": "94eec2ad9432c08ee1a1adfce536e5585d1355ba", + "repository": "https://github.com/msclock/cmake-registry", + "packages": [ +[%- if use_conan == true %] + "cmake-conan", +[%- endif %] +[%- if use_cpm == true %] + "cmake-cpm", +[%- endif %] + "cmake-modules", + "robotology-cmake-ycm", + "vcpkg-cmake-module" + ] + } + ], + "overlay-ports": [ + "cmake/vcpkg/ports" + ], + "overlay-triplets": [ + "cmake/vcpkg/triplets" + ] + } +} diff --git a/template/{{_copier_conf.answers_file}}.jinja b/template/{{_copier_conf.answers_file}}.jinja new file mode 100644 index 0000000..d0f5d97 --- /dev/null +++ b/template/{{_copier_conf.answers_file}}.jinja @@ -0,0 +1 @@ +{{ _copier_answers|to_nice_yaml -}} diff --git a/tests/test_compiled.py b/tests/test_compiled.py new file mode 100644 index 0000000..eeeed55 --- /dev/null +++ b/tests/test_compiled.py @@ -0,0 +1,8 @@ +from __future__ import annotations + +from ss_pybind11 import _core + + +def test_core_version(): + core_version: str = _core.__version__ + assert core_version != "" diff --git a/tests/test_package.py b/tests/test_package.py new file mode 100644 index 0000000..4f73063 --- /dev/null +++ b/tests/test_package.py @@ -0,0 +1,9 @@ +from __future__ import annotations + +import importlib.metadata + +import ss_pybind11 as m + + +def test_version(): + assert importlib.metadata.version("ss_pybind11") == m.__version__ diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..6135607 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,57 @@ +{ + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", + "name": "ss-pybind11", + "description": "A template of serious scaffold family based on pybind11.", + "builtin-baseline": "7adc2e4d49e8d0efc07a369079faa6bc3dbb90f3", + "homepage": "https://github.com/serious-scaffold/ss-pybind11", + "dependencies": [ + "pybind11", + "cmake-modules", + "robotology-cmake-ycm" + ], + "overrides": [ + { + "name": "pybind11", + "version": "2.13.5" + }, + { + "name": "cmake-modules", + "version": "1.6.5" + }, + { + "name": "robotology-cmake-ycm", + "version": "0.16.3" + } + ], + "features": { + "test": { + "description": "Dependencies for testing", + "dependencies": [ + { + "name": "gtest", + "version>=": "1.14.0" + } + ] + } + }, + "vcpkg-configuration": { + "registries": [ + { + "kind": "git", + "baseline": "94eec2ad9432c08ee1a1adfce536e5585d1355ba", + "repository": "https://github.com/msclock/cmake-registry", + "packages": [ + "cmake-modules", + "robotology-cmake-ycm", + "vcpkg-cmake-module" + ] + } + ], + "overlay-ports": [ + "cmake/vcpkg/ports" + ], + "overlay-triplets": [ + "cmake/vcpkg/triplets" + ] + } +}