initial setup

Buildscripts, nix shell, skeleton project
This commit is contained in:
outfoxxed 2023-10-27 03:02:07 -07:00
commit f5c43c4fb4
Signed by: outfoxxed
GPG Key ID: 4C88A185FB89301E
11 changed files with 284 additions and 0 deletions

82
.clang-format Normal file
View File

@ -0,0 +1,82 @@
AlignArrayOfStructures: None
AlignAfterOpenBracket: BlockIndent
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
BinPackArguments: false
BinPackParameters: false
Cpp11BracedListStyle: true
LambdaBodyIndentation: Signature
UseCRLF: false
UseTab: ForIndentation
SpacesInSquareBrackets: false
SpacesInParentheses: false
SpacesInCStyleCastParentheses: false
SpacesInAngles: Never
SpaceInEmptyParentheses: false
SpaceInEmptyBlock: false
SpaceBeforeSquareBrackets: false
SpaceBeforeRangeBasedForLoopColon: false
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: false
SpaceBeforeInheritanceColon: false
SpaceBeforeParens: ControlStatementsExceptControlMacros
SortIncludes: CaseSensitive
PointerAlignment: Left
PackConstructorInitializers: NextLine
LineEnding: LF
InsertBraces: false
BreakConstructorInitializers: AfterColon
BreakBeforeBraces: Custom
BreakInheritanceList: AfterColon
AllowAllParametersOfDeclarationOnNextLine: false
AllowAllArgumentsOnNextLine: false
AlwaysBreakTemplateDeclarations: Yes
BraceWrapping:
AfterClass: false
AfterFunction: false
AfterCaseLabel: false
AfterEnum: false
AfterNamespace: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: false
SplitEmptyNamespace: false
AfterControlStatement: MultiLine
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeTernaryOperators: true
AlignOperands: AlignAfterOperator
InsertTrailingCommas: Wrapped
MaxEmptyLinesToKeep: 1
ExperimentalAutoDetectBinPacking: false
ColumnLimit: 100
IndentWidth: 2
TabWidth: 2
AllowAllConstructorInitializersOnNextLine: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
NamespaceIndentation: None
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<(cassert|cctype|cerrno|cfenv|cfloat|cinttypes|climits|clocale|cmath|csetjmp|csignal|cstdarg|cstdbool|cstddef|cstdint|cstdio|cstdlib|cstring|ctime|cuchar|cwchar|cwctype|algorithm|any|array|atomic|bitset|chrono|codecvt|complex|condition_variable|deque|exception|filesystem|forward_list|fstream|functional|future|initializer_list|iomanip|ios|iosfwd|iostream|istream|iterator|latch|limits|list|locale|map|memory|mutex|new|numeric|optional|ostream|queue|random|ratio|regex|scoped_allocator|set|shared_mutex|sstream|stack|stdexcept|streambuf|string|string_view|strstream|syncstream|system_error|thread|tuple|type_traits|typeindex|typeinfo|unordered_map|unordered_set|utility|valarray|variant|vector|version|assert.h|ctype.h|errno.h|fenv.h|float.h|inttypes.h|limits.h|locale.h|math.h|setjmp.h|signal.h|stdarg.h|stddef.h|stdint.h|stdio.h|stdlib.h|string.h|time.h|uchar.h|wchar.h|wctype.h)>$'
Priority: 0
- Regex: '^<.*>$'
Priority: 1
- Regex: '^".*"$'
Priority: 2
- Regex: '.+'
Priority: 3

48
.clang-tidy Normal file
View File

@ -0,0 +1,48 @@
WarningsAsErrors: '*'
HeaderFilterRegex: '.*\.hpp'
FormatStyle: file
Checks: >
-*,
bugprone-*,
concurrency-*,
cppcoreguidelines-*,
-cppcoreguidelines-owning-memory,
google-build-using-namespace.
google-explicit-constructor,
google-global-names-in-headers,
google-readability-casting,
google-runtime-int,
google-runtime-operator,
misc-*,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
modernize-*,
-modernize-return-braced-init-list,
-modernize-use-trailing-return-type,
performance-*,
portability-std-allocator-const,
readability-*,
-readability-function-cognitive-complexity,
-readability-function-size,
-readability-identifier-length,
-readability-magic-numbers,
-readability-uppercase-literal-suffix,
tidyfox-*,
CheckOptions:
performance-for-range-copy.WarnOnAllAutoCopies: true
performance-inefficient-string-concatenation.StrictMode: true
readability-braces-around-statements.ShortStatementLines: 1
readability-identifier-naming.ClassCase: CamelCase
readability-identifier-naming.ConstantCase: UPPER_CASE
readability-identifier-naming.EnumCase: CamelCase
readability-identifier-naming.FunctionCase: lower_case
readability-identifier-naming.MemberCase: lower_case
readability-identifier-naming.NamespaceCase: lower_case
readability-identifier-naming.LocalConstantCase: lower_case
readability-identifier-naming.MethodCase: lower_case
readability-identifier-naming.ParameterCase: lower_case
readability-identifier-naming.VariableCase: lower_case
# does not appear to work
readability-operators-representation.BinaryOperators: '&&;&=;&;|;~;!;!=;||;|=;^;^='
readability-operators-representation.OverloadedOperators: '&&;&=;&;|;~;!;!=;||;|=;^;^='

12
.editorconfig Normal file
View File

@ -0,0 +1,12 @@
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = tab
[{*.nix,.clang-format,.clang-tidy}]
indent_style = space
indent_size = 2

10
.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
# build files
/build
/compile_commands.json
# clangd
/.cache/
# direnv
/.envrc
/.direnv/

25
CMakeLists.txt Normal file
View File

@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.20)
project(tidyfox VERSION "0.0.1")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
add_compile_options(-Wall -Wextra)
# nix workaround
if (CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
endif()
find_package(Clang REQUIRED)
add_library(tidyfox MODULE
src/lib.cpp
src/explicit_thisptr.cpp
)
target_link_libraries(tidyfox PRIVATE clang-tidy)
if (NOT STREQUAL ${CMAKE_INSTALL_LIBDIR} "")
install(TARGETS tidyfox LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()

31
Justfile Normal file
View File

@ -0,0 +1,31 @@
fmt:
clang-format -i src/**
check-format:
clang-format -i src/** --dry-run
# the lint ends up running over a large amount of llvm surface area and it takes considerably
# longer than the extra build time from using release mode
lint: release
clang-tidy src/** --load=build/release/libtidyfox.so
build:
cmake -GNinja -B build/debug \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
ln -sf build/debug/compile_commands.json compile_commands.json
cmake --build build/debug
release:
cmake -GNinja -B build/release \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cmake --build build/release
clean:
rm -rf build
rm -f compile_commands.json
pre-commit: check-format lint

28
README.md Normal file
View File

@ -0,0 +1,28 @@
# tidyfox
outfoxxed's clang-tidy lint collection. Lints I end up needing will go here.
# Installation
There is a nix package in `default.nix` which can be used to install tidyfox in `lib/libtidyfox.so`.
If you aren't running nix, use the provided Justfile.
Run `just release` to make a release build. You must have llvm and clang 16 dev packages in $PATH. (`FindClang.cmake` must exist)
# Usage
Tidyfox lints are supplied under the `tidyfox-` namespace. Currently there are no lints.
The plugin can be loaded via `clang-tidy -load=/path/to/libtidyfox.so`
# Contributing
There is a `shell.nix` file which will load all the necessary dependencies.
If not using nix the requirements are the same as in [Installation](#installation) above.
Run `just build` to create a debug build and a clang compilation database.
Run `just fmt` to format the sources.
Run `just lint` to run clang-tidy on tidyfox, with tidyfox itself as a plugin.
Run `just release` to create a release build.
Run `just pre-commit` before committing to catch anything.
When committing, follow [conventional commits](https://www.conventionalcommits.org).

1
default.nix Normal file
View File

@ -0,0 +1 @@
{ pkgs ? import <nixpkgs> {} }: pkgs.callPackage ./package.nix {}

18
package.nix Normal file
View File

@ -0,0 +1,18 @@
{ cmake, ninja, llvmPackages_16, clang16Stdenv }:
clang16Stdenv.mkDerivation {
pname = "tidyfox";
version = "0.1.0";
src = ./.;
nativeBuildInputs = [
cmake
ninja
];
buildInputs = with llvmPackages_16; [
llvm.dev
clang-unwrapped.dev
];
buildPhase = "ninjaBuildPhase";
}

13
shell.nix Normal file
View File

@ -0,0 +1,13 @@
{ pkgs ? import <nixpkgs> {} }: let
tidyfox = import ./default.nix { inherit pkgs; };
in pkgs.mkShell.override {
stdenv = tidyfox.stdenv;
} {
name = "tidyfox";
nativeBuildInputs = with pkgs; [
just
];
inputsFrom = [ tidyfox ];
}

16
src/lib.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <cstdio>
#include <clang-tidy/ClangTidyModule.h>
#include <clang-tidy/ClangTidyModuleRegistry.h>
namespace clang::tidy::tidyfox {
class TidyfoxClangTidyModule: public ClangTidyModule {
public:
void addCheckFactories([[maybe_unused]] ClangTidyCheckFactories& check_factories) override {}
};
static const ClangTidyModuleRegistry::Add<TidyfoxClangTidyModule>
X("tidyfox", "outfoxxed's lint collection");
} // namespace clang::tidy::tidyfox