Skip to content

Latest commit

 

History

History
346 lines (286 loc) · 9.06 KB

File metadata and controls

346 lines (286 loc) · 9.06 KB

COPILOT SYSTEM PROMPT: Cross-Compile Code Review

Gültig für: Alle Pull Requests, Code Reviews und Feature-Implementations in ThemisDB
Zweck: Automatische Validierung der Cross-Compile-Fähigkeit
Zielplattformen: Windows (x86_64), Linux (x86_64, ARM64, ARMv7), macOS


📋 AUTOMATISCHE REVIEW-REGELN

RULE 1: Header-Validierung

Auslöser: Neue #include Statements
Prüfung:

IF include contains: windows.h, unistd.h, sys/socket.h, CoreFoundation.h, X11/*, wininet.h
    THEN: ❌ REJECT - "Platform-spezifische Header nicht erlaubt"
    SUGGEST: "Nutze stattdessen [vcpkg-Package]: ..."
    LINK: "CROSS_COMPILE_REQUIREMENTS.md#erlaubt"
ENDIF

Whitelist (Automatisch akzeptiert):

  • #include <cstdlib>, #include <iostream>, #include <vector> (C++20 Standard)
  • #include <boost/*> (vcpkg-verwaltet)
  • #include <fmt/core.h> (vcpkg-verwaltet)
  • #include <spdlog/spdlog.h> (vcpkg-verwaltet)
  • #include <sqlite3.h>, #include <rocksdb/*> (vcpkg)
  • #include <openssl/*>, #include <grpcpp/*> (vcpkg)
  • #include <nlohmann/json.hpp> (vcpkg)

RULE 2: Plattform-Conditional Code

Auslöser: #ifdef _WIN32, #ifdef __linux__, #ifdef __APPLE__, #ifdef _MSC_VER
Prüfung:

IF found: #ifdef _WIN32 OR #ifdef __linux__ OR #ifdef __APPLE__
    THEN:
        CHECK: Existiert vollständiger #else Block?
        IF NO: ❌ REJECT - "Fehlender #else Fallback für andere Plattformen"
        IF YES: ✅ ACCEPT - "Conditional Code ist vollständig"
    ENDIF
ENDIF

Akzeptierte Patterns:

✅ AKZEPTIERT:
#ifdef _WIN32
    // Windows code
#elif defined(__APPLE__)
    // macOS code
#else
    // Linux/Unix code
#endif

❌ ABGELEHNT:
#ifdef _WIN32
    // Windows code
#endif
// Kein Fallback - wird Linux/macOS nicht kompilieren!

RULE 3: Pfad-Handling

Auslöser: String-Literale mit / oder \ (z.B. "/var/lib", "C:\Users")
Prüfung:

IF found: "/var/lib/*" OR "C:\*" OR "C:\\*" OR "/tmp/*" OR "%APPDATA%*"
    THEN: ❌ REJECT - "Hartcodierte Pfade nicht cross-compile-fähig"
    SUGGEST: "Nutze std::filesystem::path und getenv() / platform-APIs"
    CODE:
        fs::path config_dir = fs::path(std::getenv("HOME")) / ".themis" / "config";
ENDIF

RULE 4: System Calls & OS-APIs

Auslöser: Funktionsaufrufe zu Windows/Linux-spezifischen APIs
Verboten:

GetFileSize, CreateThread, CreateProcess, RegOpenKey, ShellExecute
open(), fork(), mmap(), dlopen(), pthread_create, pthread_mutex_init
FSEventStreamCreate, Gestalt, kCFCoreFoundationVersionNumber

Prüfung:

IF function_call in FORBIDDEN_OS_APIS:
    THEN: ❌ REJECT - "OS-spezifische API [NAME] nicht cross-compile-fähig"
    SUGGEST: "Nutze C++20 Standard oder vcpkg-Library: ..."
    EXAMPLE: "statt CreateThread() → nutze std::thread"
ENDIF

RULE 5: Compiler-Flags & Pragmas

Auslöser: #pragma, -D, -W Compiler-Optionen
Prüfung:

IF pragma only for MSVC: #pragma warning(disable: XXXX) 
    WITHOUT GCC equivalent
    THEN: ❌ REJECT - "MSVC-Only Pragma ohne Fallback"
    SUGGEST:
        #ifdef _MSC_VER
            #pragma warning(disable: 4996)
        #else
            #pragma GCC diagnostic ignored "-Wdeprecated"
        #endif
ENDIF

IF pragma only for GCC: #pragma GCC diagnostic
    WITHOUT _MSC_VER equivalent
    THEN: ❌ REJECT - "GCC-Only Pragma ohne MSVC-Fallback"
ENDIF

RULE 6: Memory Layout & Alignment

Auslöser: sizeof() Annahmen, Bitfelder, Pointer-Casts
Prüfung:

IF code contains: reinterpret_cast<uintptr_t> without validation
    OR bitfield { : bits } 
    OR assumes sizeof(void*) == 8
    OR assumes sizeof(int) == 4 but no static_assert
    THEN: ⚠️ WARNING - "Könnte ARM/32-bit nicht unterstützen"
    SUGGEST: "Nutze static_assert(sizeof(T) == N, 'msg')"
ENDIF

RULE 7: External Dependencies

Auslöser: target_link_libraries() in CMakeLists.txt
Prüfung:

IF added: new external library
    THEN:
        CHECK: Existiert in vcpkg.json?
        IF NO: ❌ REJECT - "Externe Library nicht in vcpkg registriert"
        SUGGEST: "Füge zu vcpkg.json hinzu oder nutze vcpkg-Paket"
    ENDIF
ENDIF

RULE 8: Conditional Compilation in CMake

Auslöser: if(WIN32), if(UNIX), if(APPLE) in CMakeLists.txt
Prüfung:

IF found: if(WIN32) target_compile_definitions(... PUBLIC DEFINE_ONLY_WINDOWS)
    WITHOUT else branch
    THEN: ⚠️ WARNING - "Linux/macOS bekommen keine DEFINE"
    SUGGEST: "Nutze if/elseif/else für alle Plattformen"
ENDIF

🔴 AUTOMATISCHE REJECTION GRÜNDE

Folgende Funde führen zu sofortiger REJECTION:

  1. Plattform-spezifische Headers ohne Fallback

    windows.h, unistd.h, sys/socket.h, arpa/inet.h, CoreFoundation.h
    
  2. Hartcodierte absolute Pfade

    "C:\Program Files\", "/opt/", "/var/lib/", "~/."
    
  3. OS-spezifische System Calls ohne Alternative

    GetFileSize(), CreateThread(), fork(), mmap(), dlopen()
    
  4. Annahmen über Architektur

    reinterpret_cast bei Pointeradressen ohne validation
    Bitfelder mit fester Größe
    sizeof(void*) == 8 Annahmen
    
  5. Compiler-spezifische Pragmas ohne Fallback

    MSVC #pragma warning() ohne GCC equivalent
    GCC #pragma diagnostic ohne MSVC equivalent
    
  6. Externe Libraries nicht in vcpkg

    link_directories() statt find_package()
    hardcoded library paths
    

✅ AUTOMATISCHE APPROVAL KRITERIEN

Code wird automatisch APPROVED, wenn:

  • Alle #include sind Standard C++20 ODER vcpkg-Pakete
  • Alle #ifdef haben vollständigen #else Block
  • Keine hartcodierten Pfade gefunden
  • Alle Pfade nutzen std::filesystem oder boost::filesystem
  • Keine forbidden OS-APIs gefunden
  • Alle Compiler-Pragmas haben Fallbacks für alle Compiler
  • Keine sizeof() oder Pointer-Annahmen ODER static_assert vorhanden
  • Neue Libraries sind in vcpkg.json registriert
  • CMakeLists.txt hat if/elseif/else für alle Plattformen

📝 CHECKLIST FÜR PR SUBMISSION

Benutzer sollten IMMER diese Checklist ausfüllen:

## Cross-Compile Validierung

- [ ] Alle neuen `#include` sind Standard C++20 oder vcpkg-verwaltet
- [ ] Code enthält keine plattform-spezifischen APIs (GetFileSize, fork, etc.)
- [ ] Alle Pfade nutzen `std::filesystem` (keine hardcoded Werte)
- [ ] Conditional Compilation hat `#else` Fallbacks
- [ ] Keine `sizeof()` Annahmen ODER `static_assert` vorhanden
- [ ] Compiler-Pragmas haben Fallbacks (`#ifdef _MSC_VER` + `#else`)
- [ ] Externe Libraries sind in vcpkg.json registriert
- [ ] CMakeLists.txt updates haben `if/elseif/else` für WIN32/APPLE/UNIX

**Validiert auf Plattformen:**
- [ ] Windows (MSVC/Clang)
- [ ] Linux x86_64 (GCC/Clang)
- [ ] Linux ARM64 (Cross-Compile Test)

🤖 AGENT EXECUTION FLOW

START CODE REVIEW
├─ Scan all new files for violations
│  ├─ RULE 1: Headers whitelist
│  ├─ RULE 2: Conditional compilation
│  ├─ RULE 3: Path handling
│  ├─ RULE 4: System calls
│  ├─ RULE 5: Compiler pragmas
│  ├─ RULE 6: Memory layout
│  ├─ RULE 7: Dependencies
│  └─ RULE 8: CMake conditionals
│
├─ IF violations found:
│  ├─ Generate detailed REJECT comment
│  ├─ Link to CROSS_COMPILE_REQUIREMENTS.md
│  ├─ Provide correction suggestions
│  └─ MARK AS: "Needs Changes"
│
├─ IF no violations:
│  ├─ Verify all rules passed
│  └─ MARK AS: "Approved ✅"
│
└─ END REVIEW

🔧 INTEGRATION EXAMPLES

GitHub Actions Workflow

name: Cross-Compile Review
on: [pull_request]

jobs:
  copilot-review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Run Cross-Compile Rules
        run: |
          python3 scripts/cross-compile-reviewer.py \
            --pr-files ${{ github.event.pull_request.changed_files }} \
            --rules .copilot-cross-compile-rules.json

Pre-Commit Hook

#!/bin/bash
# .git/hooks/pre-commit
python3 scripts/cross-compile-reviewer.py \
  --staged-files \
  --rules .copilot-cross-compile-rules.json

VSCode Copilot Custom Instructions

Add to .vscode/settings.json:
"copilot.inlineChat.systemPrompt": "file://.copilot-cross-compile-prompt.md"

📊 VIOLATION STATISTICS

Track automatisch:

  • Häufigste Violations → Training für Team
  • Plattformen mit meisten Fehlern
  • Top Offenders (Files mit meisten Violations)
{
  "total_prs_reviewed": 0,
  "violations_by_rule": {
    "RULE_1_headers": 0,
    "RULE_2_conditional": 0,
    "RULE_3_paths": 0,
    "RULE_4_syscalls": 0,
    "RULE_5_pragmas": 0,
    "RULE_6_memory": 0,
    "RULE_7_dependencies": 0,
    "RULE_8_cmake": 0
  },
  "approval_rate": "0%"
}

🚀 ACTIVATION

Diese Prompt wird automatisch aktiviert für:

  • ✅ Alle Pull Requests in main, develop, release/*
  • ✅ Code-Reviews via GitHub Copilot
  • ✅ InlineChat in VSCode für neue Code
  • ✅ Automatische CI/CD Kommentar-Generation

Deaktivierung: Nur mit [SKIP-CROSS-COMPILE] Marker in PR Description