Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Clang-Format configuration for fastmcpp
# Style: Allman braces, 4-space indent, no braces for single statements

BasedOnStyle: LLVM

# Braces on their own line (Allman style)
BreakBeforeBraces: Allman

# Indentation - 4 spaces
IndentWidth: 4
TabWidth: 4
UseTab: Never
ColumnLimit: 100

# Remove braces from single-statement if/else/loop bodies
RemoveBracesLLVM: true

# Allow short control statements
AllowShortBlocksOnASingleLine: Empty
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false

# Alignment
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignOperands: true
AlignTrailingComments: true

# Spacing
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false

# Breaking
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon

# Other
PointerAlignment: Left
SortIncludes: true
IncludeBlocks: Regroup
26 changes: 26 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# Pre-commit hook: auto-format staged C++ files
#
# Enable with: git config core.hooksPath .githooks

STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(cpp|hpp)$')

if [ -z "$STAGED_FILES" ]; then
exit 0
fi

# Check if clang-format is available
if ! command -v clang-format &> /dev/null; then
echo "Warning: clang-format not found, skipping auto-format"
exit 0
fi

# Auto-format and re-stage
for file in $STAGED_FILES; do
if [ -f "$file" ]; then
clang-format -i "$file"
git add "$file"
fi
done

exit 0
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ jobs:
-DFASTMCPP_BUILD_TESTS=ON
-DFASTMCPP_BUILD_EXAMPLES=ON

- name: Build
- name: Build (Unix)
if: runner.os != 'Windows'
run: cmake --build build --config ${{ matrix.build_type }} --parallel

- name: Build (Windows)
if: runner.os == 'Windows'
# Single-threaded build on Windows to avoid compiler heap space issues with large test files
run: cmake --build build --config ${{ matrix.build_type }} --parallel 1

- name: Test
run: ctest --test-dir build -C ${{ matrix.build_type }} --output-on-failure
44 changes: 44 additions & 0 deletions .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Format Check

on:
pull_request:
push:
branches: [main]

jobs:
format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install clang-format
run: |
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository -y "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-19 main"
sudo apt-get update
sudo apt-get install -y clang-format-19

- name: Check formatting
run: |
# Find all source files (excluding build dirs and deps)
FILES=$(find src include examples tests -name "*.cpp" -o -name "*.hpp" 2>/dev/null)

# Check if any files need formatting
UNFORMATTED=""
for f in $FILES; do
if ! clang-format-19 --dry-run --Werror "$f" 2>/dev/null; then
UNFORMATTED="$UNFORMATTED $f"
fi
done

if [ -n "$UNFORMATTED" ]; then
echo "::error::The following files need formatting:"
for f in $UNFORMATTED; do
echo " - $f"
done
echo ""
echo "Run: find src include examples tests -name '*.cpp' -o -name '*.hpp' | xargs clang-format -i"
exit 1
fi

echo "All files are properly formatted!"
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ if(FASTMCPP_BUILD_TESTS)
target_link_libraries(fastmcpp_server_patterns PRIVATE fastmcpp_core)
add_test(NAME fastmcpp_server_patterns COMMAND fastmcpp_server_patterns)

add_executable(fastmcpp_server_interactions tests/server/interactions.cpp)
target_link_libraries(fastmcpp_server_interactions PRIVATE fastmcpp_core)
add_test(NAME fastmcpp_server_interactions COMMAND fastmcpp_server_interactions)

add_executable(fastmcpp_server_context_meta tests/server/context_meta.cpp)
target_link_libraries(fastmcpp_server_context_meta PRIVATE fastmcpp_core)
add_test(NAME fastmcpp_server_context_meta COMMAND fastmcpp_server_context_meta)

add_executable(fastmcpp_client_transports tests/client/transports.cpp)
target_link_libraries(fastmcpp_client_transports PRIVATE fastmcpp_core)
add_test(NAME fastmcpp_client_transports COMMAND fastmcpp_client_transports)
Expand Down
Loading
Loading