diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9a1ef0..937f849 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,143 +10,121 @@ jobs: build: runs-on: ${{ matrix.os }} strategy: - fail-fast: false matrix: os: [ubuntu-latest, windows-latest] include: - os: ubuntu-latest - install: | + install_cmd: | sudo apt-get update - sudo apt-get install -y autoconf automake libtool pkg-config - sudo apt-get install -y libsdl2-dev libvulkan-dev - sudo apt-get install -y clang-format cppcheck lcov - sudo apt-get install -y libgtest-dev - cd /usr/src/gtest - sudo cmake CMakeLists.txt - sudo make - sudo cp lib/*.a /usr/lib - cc: gcc - cxx: g++ - coverage: true - coverage_flags: "--coverage -fprofile-arcs -ftest-coverage" + sudo apt-get install -y \ + autoconf \ + automake \ + libtool \ + pkg-config \ + wget \ + tar \ + clang-format \ + libsdl2-dev \ + libvulkan-dev \ + vulkan-tools \ + vulkan-validationlayers-dev \ + spirv-tools + # Set up environment variables + echo "SDL2_CFLAGS=-I/usr/include/SDL2" >> $GITHUB_ENV + echo "SDL2_LIBS=-lSDL2" >> $GITHUB_ENV + echo "VULKAN_SDK=/usr" >> $GITHUB_ENV + echo "VULKAN_CFLAGS=-I/usr/include" >> $GITHUB_ENV + echo "VULKAN_LIBS=-lvulkan" >> $GITHUB_ENV + # Add pkg-config paths + echo "PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/share/pkgconfig" >> $GITHUB_ENV + # Add additional include paths + echo "CPATH=/usr/include/SDL2:/usr/include/vulkan" >> $GITHUB_ENV + echo "C_INCLUDE_PATH=/usr/include/SDL2:/usr/include/vulkan" >> $GITHUB_ENV + echo "CPLUS_INCLUDE_PATH=/usr/include/SDL2:/usr/include/vulkan" >> $GITHUB_ENV - os: windows-latest - install: | - choco install autoconf automake libtool pkg-config - choco install mingw - choco install vulkan-sdk - choco install llvm - # Install Google Test - git clone https://github.com/google/googletest.git - cd googletest - cmake -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=C:/gtest . - mingw32-make - mingw32-make install - cd .. - cc: gcc - cxx: g++ - coverage: false - coverage_flags: "" + install_cmd: | + # Install build tools + choco install -y ` + autoconf ` + automake ` + libtool ` + pkgconfig ` + wget ` + tar ` + llvm ` + mingw ` + make + + # Download and install Vulkan SDK + $vulkanSdkUrl = "https://sdk.lunarg.com/sdk/download/latest/windows/vulkan-sdk.exe" + Invoke-WebRequest -Uri $vulkanSdkUrl -OutFile vulkan-sdk.exe + Start-Process -FilePath "vulkan-sdk.exe" -ArgumentList "--accept-licenses --default-answer --confirm-command" -Wait + + # Download and extract SDL2 + $sdl2Version = "2.28.5" + $sdl2Url = "https://github.com/libsdl-org/SDL/releases/download/release-$sdl2Version/SDL2-devel-$sdl2Version-mingw.tar.gz" + Invoke-WebRequest -Uri $sdl2Url -OutFile SDL2.tar.gz + tar xf SDL2.tar.gz + Move-Item -Path "SDL2-$sdl2Version" -Destination "C:\SDL2" + + # Set up environment variables + echo "SDL2_CFLAGS=-IC:/SDL2/include/SDL2" | Out-File -FilePath $env:GITHUB_ENV -Append + echo "SDL2_LIBS=-LC:/SDL2/lib -lSDL2" | Out-File -FilePath $env:GITHUB_ENV -Append + echo "VULKAN_SDK=C:/VulkanSDK/latest" | Out-File -FilePath $env:GITHUB_ENV -Append + echo "VULKAN_CFLAGS=-IC:/VulkanSDK/latest/Include" | Out-File -FilePath $env:GITHUB_ENV -Append + echo "VULKAN_LIBS=-LC:/VulkanSDK/latest/Lib -lvulkan-1" | Out-File -FilePath $env:GITHUB_ENV -Append + # Add pkg-config paths + echo "PKG_CONFIG_PATH=C:/SDL2/lib/pkgconfig;C:/VulkanSDK/latest/lib/pkgconfig" | Out-File -FilePath $env:GITHUB_ENV -Append + # Add additional include paths + echo "INCLUDE=C:/SDL2/include/SDL2;C:/VulkanSDK/latest/Include" | Out-File -FilePath $env:GITHUB_ENV -Append + echo "C_INCLUDE_PATH=C:/SDL2/include/SDL2;C:/VulkanSDK/latest/Include" | Out-File -FilePath $env:GITHUB_ENV -Append + echo "CPLUS_INCLUDE_PATH=C:/SDL2/include/SDL2;C:/VulkanSDK/latest/Include" | Out-File -FilePath $env:GITHUB_ENV -Append + + # Add to PATH + echo "C:\SDL2\bin" | Out-File -FilePath $env:GITHUB_PATH -Append + echo "C:\VulkanSDK\latest\Bin" | Out-File -FilePath $env:GITHUB_PATH -Append steps: - uses: actions/checkout@v3 - - name: Cache dependencies + - name: Install Dependencies + shell: pwsh + run: ${{ matrix.install_cmd }} + + - name: Cache Dependencies uses: actions/cache@v3 with: path: | - deps/build - deps/install - googletest - key: ${{ runner.os }}-deps-${{ hashFiles('deps/download_deps.sh') }} + C:/SDL2 + C:/VulkanSDK + key: ${{ runner.os }}-deps-${{ hashFiles('**/*.yml') }} restore-keys: | ${{ runner.os }}-deps- - - name: Install dependencies - run: ${{ matrix.install }} - - - name: Set up environment - shell: bash - run: | - echo "CC=${{ matrix.cc }}" >> $GITHUB_ENV - echo "CXX=${{ matrix.cxx }}" >> $GITHUB_ENV - if [ "${{ runner.os }}" = "Windows" ]; then - echo "GTEST_ROOT=C:/gtest" >> $GITHUB_ENV - fi - - - name: Code format check - if: runner.os == 'Linux' - run: | - find src tests -name '*.cpp' -o -name '*.h' | xargs clang-format -n -Werror - - - name: Static analysis - if: runner.os == 'Linux' + - name: Check Code Format run: | - cppcheck --enable=all --error-exitcode=1 --suppress=missingInclude src/ tests/ - - - name: Generate build system - shell: bash - run: | - ./autogen.sh - - - name: Configure - shell: bash - run: | - if [ "${{ matrix.coverage }}" = "true" ]; then - ./configure CFLAGS="-Wall -Wextra ${{ matrix.coverage_flags }}" CXXFLAGS="-Wall -Wextra ${{ matrix.coverage_flags }}" --enable-testing - else - ./configure CFLAGS="-Wall -Wextra" CXXFLAGS="-Wall -Wextra" --enable-testing - fi + ./format_code.sh + git diff --exit-code || (echo "Code formatting issues found. Run ./format_code.sh locally and commit changes." && exit 1) - name: Build - shell: bash - run: | - make -j$(nproc) - - - name: Run tests - shell: bash - run: | - make check - - - name: Run tests with coverage - if: matrix.coverage - shell: bash + shell: pwsh + env: + CFLAGS: "${{ matrix.os == 'ubuntu-latest' && '-I/usr/include/SDL2 -I/usr/include/vulkan' || '-IC:/SDL2/include/SDL2 -IC:/VulkanSDK/latest/Include' }}" + CXXFLAGS: "${{ matrix.os == 'ubuntu-latest' && '-I/usr/include/SDL2 -I/usr/include/vulkan' || '-IC:/SDL2/include/SDL2 -IC:/VulkanSDK/latest/Include' }}" run: | - # 运行测试并生成覆盖率报告 - make check - lcov --capture --directory . --output-file coverage.info - lcov --remove coverage.info '/usr/*' --output-file coverage.info - lcov --list coverage.info + ./autogen.sh + ./configure + make - - name: Upload coverage to Coveralls - if: matrix.coverage - uses: coverallsapp/github-action@v2 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - file: coverage.info - format: lcov + - name: Run Tests + if: ${{ matrix.os == 'ubuntu-latest' }} # Only run tests on Linux for now + run: make check - - name: Upload artifacts + - name: Upload Build Artifacts uses: actions/upload-artifact@v3 with: name: doom_pp-${{ matrix.os }} path: | doom_pp doom_pp.exe - tests/unit/test_runner - if-no-files-found: ignore - - analyze: - needs: build - runs-on: ubuntu-latest - if: github.event_name == 'pull_request' - - steps: - - uses: actions/checkout@v3 - - - name: Run CodeQL - uses: github/codeql-action/init@v2 - with: - languages: cpp - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 \ No newline at end of file + if-no-files-found: ignore \ No newline at end of file diff --git a/configure.ac b/configure.ac index 917ee2a..e358c2c 100644 --- a/configure.ac +++ b/configure.ac @@ -1,188 +1,50 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) -AC_INIT([DOOM_PP], [0.1], [your_email@example.com]) -AC_COPYRIGHT([Copyright (C) 2024. Licensed under BSD Zero Clause License. -Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.]) - -# 确保源码目录存在 +AC_INIT([doom_pp], [0.1], [bugs@example.com]) +AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AC_CONFIG_SRCDIR([src/main.cpp]) - -# 设置宏目录 +AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIRS([m4]) -AC_CONFIG_AUX_DIR([build-aux]) -# 初始化automake -AM_INIT_AUTOMAKE([foreign -Wall -Werror subdir-objects]) - -# 检查基本编译工具 -AC_PROG_CC +# Checks for programs AC_PROG_CXX -AC_PROG_INSTALL -AC_PROG_MAKE_SET +AC_PROG_CC AC_PROG_RANLIB -AM_PROG_AR -LT_INIT +AC_PROG_WGET +AC_PROG_TAR -# 检查操作系统类型 +# Platform detection AC_CANONICAL_HOST case $host_os in - *mingw* | *cygwin* | *msys* ) - windows=yes - AC_DEFINE([WINDOWS], [1], [Building on Windows]) - ;; - *) - windows=no - ;; + *mingw* | *cygwin* | *msys*) + AC_DEFINE([WINDOWS], [1], [Windows platform]) + AM_CONDITIONAL([WINDOWS], [true]) + ;; + *) + AM_CONDITIONAL([WINDOWS], [false]) + ;; esac -# 检查pkg-config -PKG_PROG_PKG_CONFIG - -# 检查wget和tar -AC_PATH_PROG([WGET], [wget]) -AC_PATH_PROG([TAR], [tar]) - -# 检查C++11支持 -AX_CXX_COMPILE_STDCXX_11([mandatory], [noext]) - -# SDL2检查和自动下载 -SDL2_VERSION="2.26.5" -AC_ARG_WITH([sdl2], - [AS_HELP_STRING([--with-sdl2=PATH], [path to SDL2 installation])], - [SDL2_PATH="$withval"], - [SDL2_PATH=""]) - -AS_IF([test "x$SDL2_PATH" != "x"], - [SDL2_CFLAGS="-I$SDL2_PATH/include" - if test "x$windows" = "xyes"; then - SDL2_LIBS="-L$SDL2_PATH/lib -lSDL2main -lSDL2" - else - SDL2_LIBS="-L$SDL2_PATH/lib -lSDL2" - fi], - [PKG_CHECK_MODULES([SDL2], [sdl2], - [AC_MSG_NOTICE([SDL2 found])], - [AC_MSG_NOTICE([SDL2 not found, will download and build from source]) - need_download_sdl2=yes])]) - -# Vulkan检查和自动下载 -VULKAN_VERSION="1.3.261.1" -AC_ARG_WITH([vulkan-sdk], - [AS_HELP_STRING([--with-vulkan-sdk=DIR], [Vulkan SDK installation directory])], - [VULKAN_SDK="$withval"], - [VULKAN_SDK=""]) - -# 检查Vulkan头文件 -AC_CHECK_HEADERS([vulkan/vulkan.h], [], - [if test "x$VULKAN_SDK" != "x"; then - VULKAN_CFLAGS="-I$VULKAN_SDK/include" - export CPPFLAGS="$CPPFLAGS $VULKAN_CFLAGS" - unset ac_cv_header_vulkan_vulkan_h - AC_CHECK_HEADERS([vulkan/vulkan.h], [], - [AC_MSG_ERROR([Vulkan headers not found even with specified SDK])]) - else - AC_MSG_ERROR([Vulkan headers not found. Please install Vulkan SDK or specify its location]) - fi]) +# Enable C++11 +AX_CXX_COMPILE_STDCXX_11([noext], [mandatory]) -AS_IF([test "x$VULKAN_SDK" != "x"], - [VULKAN_CFLAGS="-I$VULKAN_SDK/include" - if test "x$windows" = "xyes"; then - VULKAN_LIBS="-L$VULKAN_SDK/lib -lvulkan-1" - else - VULKAN_LIBS="-L$VULKAN_SDK/lib -lvulkan" - fi], - [PKG_CHECK_MODULES([VULKAN], [vulkan], - [AC_MSG_NOTICE([Vulkan found])], - [AC_MSG_NOTICE([Vulkan SDK not found, will download and build from source]) - need_download_vulkan=yes])]) +# Check for SDL2 +PKG_CHECK_MODULES([SDL2], [sdl2]) -# 配置依赖下载命令 -AC_CONFIG_COMMANDS([download-deps], - [if test "x$need_download_sdl2" = "xyes"; then - sh $srcdir/deps/download_deps.sh sdl2 $SDL2_VERSION - fi - if test "x$need_download_vulkan" = "xyes"; then - sh $srcdir/deps/download_deps.sh vulkan $VULKAN_VERSION - fi], - [need_download_sdl2=$need_download_sdl2 - need_download_vulkan=$need_download_vulkan - SDL2_VERSION=$SDL2_VERSION - VULKAN_VERSION=$VULKAN_VERSION]) +# Check for Vulkan +AC_CHECK_HEADERS([vulkan/vulkan.h], [], [AC_MSG_ERROR([Vulkan headers not found])]) +AC_CHECK_LIB([vulkan], [vkCreateInstance], [], [AC_MSG_ERROR([Vulkan library not found])]) -# Optional: Check for optional dependencies -PKG_CHECK_MODULES([GLSLANG], [glslang], [have_glslang=yes], [have_glslang=no]) - -# 检查头文件 -AC_CHECK_HEADERS([stdlib.h string.h]) -if test "x$windows" != "xyes"; then - AC_CHECK_HEADERS([unistd.h]) -fi - -# 检查函数 -AC_CHECK_FUNCS([memset]) - -# Windows特定设置 -if test "x$windows" = "xyes"; then - AC_DEFINE([SDL_MAIN_HANDLED], [1], [SDL main handling]) - LIBS="$LIBS -lmingw32" -fi - -# 导出变量 -AC_SUBST([SDL2_CFLAGS]) -AC_SUBST([SDL2_LIBS]) -AC_SUBST([VULKAN_CFLAGS]) -AC_SUBST([VULKAN_LIBS]) - -# 配置输出文件 -AC_CONFIG_FILES([Makefile - src/Makefile - deps/Makefile]) - -# 生成配置头文件 -AC_CONFIG_HEADERS([config.h]) - -# 添加测试支持 +# Enable testing AC_ARG_ENABLE([testing], - [AS_HELP_STRING([--enable-testing], [enable unit testing with Google Test])], - [enable_testing=$enableval], - [enable_testing=no]) - + AS_HELP_STRING([--enable-testing], [Enable unit testing])) AM_CONDITIONAL([ENABLE_TESTING], [test "x$enable_testing" = "xyes"]) -if test "x$enable_testing" = "xyes"; then - # 检查Google Test - AC_LANG_PUSH([C++]) - AC_CHECK_HEADERS([gtest/gtest.h], [], - [AC_MSG_ERROR([Google Test headers not found. Please install Google Test.])]) - - save_LIBS=$LIBS - LIBS="$LIBS -lgtest -lgtest_main -lpthread" - AC_MSG_CHECKING([for Google Test library]) - AC_LINK_IFELSE( - [AC_LANG_PROGRAM([#include ], - [testing::InitGoogleTest(nullptr, nullptr);])], - [AC_MSG_RESULT([yes])], - [AC_MSG_RESULT([no]) - AC_MSG_ERROR([Google Test library not found])]) - LIBS=$save_LIBS - AC_LANG_POP([C++]) - - # 导出Google Test变量 - AC_SUBST([GTEST_LIBS], ["-lgtest -lgtest_main -lpthread"]) -fi - -AC_OUTPUT - -# 显示配置摘要 -AC_MSG_NOTICE([ -Configuration summary: - Host system: $host - Windows build: $windows - SDL2: ${SDL2_PATH:-system} - Vulkan SDK: ${VULKAN_SDK:-system} - GLSLANG: $have_glslang - -Download summary: - SDL2: $need_download_sdl2 - Vulkan: $need_download_vulkan -]) \ No newline at end of file +AC_CONFIG_FILES([ + Makefile + deps/Makefile + src/Makefile + tests/unit/Makefile +]) +AC_OUTPUT \ No newline at end of file diff --git a/src/Makefile.am b/src/Makefile.am index 44c027c..1e74481 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,8 +11,13 @@ libdoom_a_CPPFLAGS = \ $(VULKAN_CFLAGS) \ -I$(top_srcdir)/src \ -std=c++11 \ - -D_USE_MATH_DEFINES \ - -DVK_USE_PLATFORM_WIN32_KHR + -D_USE_MATH_DEFINES + +if WINDOWS +libdoom_a_CPPFLAGS += -DVK_USE_PLATFORM_WIN32_KHR +else +libdoom_a_CPPFLAGS += -DVK_USE_PLATFORM_XCB_KHR +endif pkginclude_HEADERS = \ renderer/vulkan_renderer.h \ diff --git a/src/main.cpp b/src/main.cpp index 2305899..609ede8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,12 @@ #include "game/game_logic.h" #include "renderer/vulkan_renderer.h" -#include +#ifdef _WIN32 + #include +#else + #include +#endif + #include int main(int argc, char* argv[]) { diff --git a/src/renderer/vulkan_renderer.h b/src/renderer/vulkan_renderer.h index bc13333..d177fde 100644 --- a/src/renderer/vulkan_renderer.h +++ b/src/renderer/vulkan_renderer.h @@ -1,12 +1,18 @@ #ifndef VULKAN_RENDERER_H #define VULKAN_RENDERER_H -#include -#include +#ifdef _WIN32 + #include + #include +#else + #include + #include +#endif + +#include #include #include #include -#include class VulkanRenderer { public: