Skip to content

Commit 0a2ecfc

Browse files
PTNobelclaude
andcommitted
Add diff_engine_core as git subtree (replacing submodule)
Squashed from https://github.com/dance858/DNLP-diff-engine at fa65481. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2 parents d327c42 + ceb2a72 commit 0a2ecfc

142 files changed

Lines changed: 18047 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

diff_engine_core/.clang-format

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# .clang-format for C project with Allman style braces
2+
BasedOnStyle: LLVM
3+
4+
# Indentation
5+
IndentWidth: 4
6+
UseTab: Never
7+
TabWidth: 4
8+
9+
# Line length
10+
ColumnLimit: 85
11+
BinPackParameters: true
12+
BinPackArguments: true
13+
14+
# Braces style
15+
BreakBeforeBraces: Allman # Allman style: brace on next line
16+
BraceWrapping:
17+
AfterFunction: true
18+
AfterControlStatement: true
19+
AfterStruct: true
20+
AfterClass: true
21+
AfterNamespace: false
22+
IndentBraces: false
23+
24+
# Pointers
25+
PointerAlignment: Right
26+
27+
# Spaces
28+
SpaceAfterCStyleCast: true
29+
SpaceAfterLogicalNot: false
30+
SpacesInParentheses: false
31+
SpacesInContainerLiterals: false
32+
SpaceBeforeParens: ControlStatements
33+
34+
# Allow single-line short statements if simple
35+
AllowShortIfStatementsOnASingleLine: true
36+
AllowShortLoopsOnASingleLine: true
37+
AllowShortFunctionsOnASingleLine: Inline
38+
AllowAllParametersOfDeclarationOnNextLine: true
39+
40+
41+
# Other
42+
ReflowComments: true
43+
IndentCaseLabels: true
44+
AlignOperands: true
45+
InsertNewlineAtEOF: true
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CMake Build and Test
2+
3+
on:
4+
push:
5+
branches: [main, development]
6+
pull_request:
7+
branches: [main, development]
8+
9+
jobs:
10+
build:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, macos-latest, windows-latest]
15+
build_type: [Release, Debug]
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- name: Configure CMake
21+
run: cmake -B build -S . -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_VERBOSE_MAKEFILE=ON
22+
23+
- name: Build
24+
run: cmake --build build --config ${{ matrix.build_type }}
25+
26+
- name: Run tests
27+
run: cd build && ctest -C ${{ matrix.build_type }} --verbose
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Code Formatting
2+
3+
on:
4+
push:
5+
branches: [main, development]
6+
pull_request:
7+
branches: [main, development]
8+
9+
jobs:
10+
format:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest]
15+
16+
steps:
17+
- uses: actions/checkout@v5
18+
19+
# Install clang-format if needed
20+
- name: Install clang-format (Linux)
21+
if: matrix.os == 'ubuntu-latest'
22+
run: sudo apt-get update && sudo apt-get install -y clang-format
23+
24+
- name: Install clang-format (macOS)
25+
if: matrix.os == 'macos-latest'
26+
run: brew install clang-format || true
27+
28+
# Check formatting
29+
- name: Check C/C++ formatting
30+
run: |
31+
misformatted=$(find . -name '*.c' -o -name '*.h' -print0 | xargs -0 clang-format -style=file -output-replacements-xml | grep "<replacement " || true)
32+
if [ -n "$misformatted" ]; then
33+
echo "ERROR: Some files are not properly formatted. Run clang-format -i."
34+
exit 1
35+
else
36+
echo "All files are properly formatted."
37+
exit 0
38+
fi
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
# Run tests before creating release
10+
test:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, macos-latest]
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Configure CMake
19+
run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
20+
21+
- name: Build
22+
run: cmake --build build --config Release
23+
24+
- name: Run tests
25+
run: ./build/all_tests
26+
27+
# Create GitHub release after tests pass
28+
release:
29+
needs: test
30+
runs-on: ubuntu-latest
31+
permissions:
32+
contents: write
33+
steps:
34+
- uses: actions/checkout@v4
35+
36+
- name: Create Release
37+
uses: softprops/action-gh-release@v2
38+
with:
39+
generate_release_notes: true
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: ASan+UBSan
2+
3+
on:
4+
push:
5+
branches: [main, development]
6+
pull_request:
7+
branches: [main, development]
8+
9+
jobs:
10+
build:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, macos-latest]
15+
16+
steps:
17+
- uses: actions/checkout@v5
18+
19+
# Configure CMake with ASan + UBSan
20+
- name: Configure with sanitizers
21+
run: cmake -B build -S . \
22+
-DCMAKE_BUILD_TYPE=Debug \
23+
-DCMAKE_C_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer -g" \
24+
-DCMAKE_CXX_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer -g"
25+
26+
# Build
27+
- name: Build
28+
run: cmake --build build --config Debug
29+
30+
# Run tests
31+
- name: Run tests under ASan+UBSan
32+
run: ./build/all_tests
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Valgrind
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
linux:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
11+
- name: Install dependencies
12+
run: |
13+
sudo apt-get update
14+
sudo apt-get install -y valgrind
15+
16+
- name: Configure Debug build
17+
run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug
18+
19+
- name: Build
20+
run: cmake --build build --config Debug
21+
22+
- name: Run tests under Valgrind
23+
run: |
24+
valgrind --leak-check=full --show-leak-kinds=all \
25+
--track-origins=yes -s --show-reachable=yes \
26+
--error-exitcode=1 build/all_tests
27+

diff_engine_core/.gitignore

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Object files
5+
*.o
6+
*.ko
7+
*.obj
8+
*.elf
9+
10+
# Linker output
11+
*.ilk
12+
*.map
13+
*.exp
14+
15+
# Precompiled Headers
16+
*.gch
17+
*.pch
18+
19+
# Libraries
20+
*.lib
21+
*.a
22+
*.la
23+
*.lo
24+
25+
# Shared objects (inc. Windows DLLs)
26+
*.dll
27+
*.so
28+
*.so.*
29+
*.dylib
30+
31+
# Executables
32+
*.exe
33+
*.out
34+
*.app
35+
*.i*86
36+
*.x86_64
37+
*.hex
38+
39+
# Debug files
40+
*.dSYM/
41+
*.su
42+
*.idb
43+
*.pdb
44+
45+
# Kernel Module Compile Results
46+
*.mod*
47+
*.cmd
48+
.tmp_versions/
49+
modules.order
50+
Module.symvers
51+
Mkfile.old
52+
dkms.conf
53+
54+
# CMake
55+
CMakeCache.txt
56+
CMakeFiles/
57+
CMakeScripts/
58+
Testing/
59+
Makefile
60+
cmake_install.cmake
61+
install_manifest.txt
62+
compile_commands.json
63+
CTestTestfile.cmake
64+
_deps
65+
build/
66+
Build/
67+
out/
68+
69+
# IDEs
70+
.vscode/
71+
.idea/
72+
*.swp
73+
*.swo
74+
*~
75+
.DS_Store
76+
77+
.venv/
78+
__pycache__/
79+
uv.lock

diff_engine_core/CMakeLists.txt

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(DNLP_Diff_Engine C)
3+
set(CMAKE_C_STANDARD 99)
4+
5+
set(DIFF_ENGINE_VERSION_MAJOR 0)
6+
set(DIFF_ENGINE_VERSION_MINOR 1)
7+
set(DIFF_ENGINE_VERSION_PATCH 1)
8+
set(DIFF_ENGINE_VERSION "${DIFF_ENGINE_VERSION_MAJOR}.${DIFF_ENGINE_VERSION_MINOR}.${DIFF_ENGINE_VERSION_PATCH}")
9+
add_compile_definitions(DIFF_ENGINE_VERSION="${DIFF_ENGINE_VERSION}")
10+
11+
message(STATUS "Configuring DNLP Differentiation Engine (version ${DIFF_ENGINE_VERSION})")
12+
13+
14+
#Set default build type to Release if not specified
15+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
16+
message(STATUS "Setting build type to 'Release' as none was specified.")
17+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
18+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
19+
else()
20+
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
21+
endif()
22+
23+
# Warning flags (compiler-specific)
24+
if(MSVC)
25+
add_compile_options(/W4 /WX)
26+
else()
27+
add_compile_options(
28+
-Wall # Enable most warnings
29+
-Wextra # Extra warnings
30+
-Wpedantic # Strict ISO C compliance
31+
-Wshadow # Warn about variable shadowing
32+
-Wformat=2 # Extra format string checks
33+
-Wcast-qual # Warn about cast that removes qualifiers
34+
-Wcast-align # Warn about pointer cast alignment issues
35+
-Wunused # Warn about unused variables/functions
36+
-Wdouble-promotion # Warn about float to double promotion
37+
-Wnull-dereference # Warn about null pointer dereference
38+
)
39+
endif()
40+
41+
# Include directories
42+
include_directories(${PROJECT_SOURCE_DIR}/include)
43+
44+
# Source files - automatically gather all .c files from src/
45+
file(GLOB_RECURSE SOURCES "src/*.c")
46+
47+
48+
# Create core library
49+
add_library(dnlp_diff ${SOURCES})
50+
51+
# Link math library (Unix/Linux only)
52+
if(NOT MSVC)
53+
target_link_libraries(dnlp_diff m)
54+
endif()
55+
56+
# Config-specific compile options (compiler-specific)
57+
if(MSVC)
58+
target_compile_options(dnlp_diff PRIVATE
59+
$<$<CONFIG:Debug>:/Od /Zi>
60+
$<$<CONFIG:Release>:/O2 /DNDEBUG>
61+
$<$<CONFIG:RelWithDebInfo>:/O2 /Zi /DNDEBUG>
62+
$<$<CONFIG:MinSizeRel>:/Os /DNDEBUG>
63+
)
64+
else()
65+
target_compile_options(dnlp_diff PRIVATE
66+
$<$<CONFIG:Debug>:-g -O0>
67+
$<$<CONFIG:Release>:-O3 -DNDEBUG>
68+
$<$<CONFIG:RelWithDebInfo>:-O2 -g -DNDEBUG>
69+
$<$<CONFIG:MinSizeRel>:-Os -DNDEBUG>
70+
)
71+
endif()
72+
73+
# This is needed for clock_gettime on Linux without compiler extensions
74+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
75+
add_compile_definitions(_POSIX_C_SOURCE=200809L)
76+
endif()
77+
78+
# Enable position-independent code for shared library compatibility
79+
set_property(TARGET dnlp_diff PROPERTY POSITION_INDEPENDENT_CODE ON)
80+
81+
# =============================================================================
82+
# C tests (only for standalone builds)
83+
# =============================================================================
84+
if(NOT SKBUILD)
85+
include_directories(${PROJECT_SOURCE_DIR}/tests)
86+
enable_testing()
87+
88+
add_executable(all_tests
89+
tests/all_tests.c
90+
tests/test_helpers.c
91+
)
92+
target_link_libraries(all_tests dnlp_diff)
93+
add_test(NAME AllTests COMMAND all_tests)
94+
endif()

0 commit comments

Comments
 (0)