diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 152d270..3a1b572 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -21,201 +21,90 @@ defaults: shell: bash jobs: + static-analysis: + name: Static analysis - StaticAnalysis: - name: Static analysis runs-on: ubuntu-latest - steps: + steps: - name: Install - run: | - : - echo ::group::apt update - sudo apt update 2>&1 - echo ::endgroup:: + run: | + sudo apt update sudo apt install cppcheck - name: Clone uses: actions/checkout@v3 - name: cppcheck - run: cppcheck --std=c++17 src/ + run: cppcheck --std=c++17 src/ + + linux: + name: Linux (${{ matrix.arch }}) + + runs-on: ubuntu-20.04 - Build: - name: ${{ matrix.cfg.name }} x${{ matrix.cfg.arch }} - runs-on: ${{ matrix.cfg.os }} - needs: [StaticAnalysis] strategy: fail-fast: false matrix: - cfg: - # - # name .......... overrides job name in GitHub UI - # os ............ defines system image; passed to job..runs-on - # cc ............ defines C compiler; passed to CMake configuration step (as `CC` environment variable) - # cxx ........... defines C++ compiler; passed to CMake configuration step (as `CXX` environment variable) - # ver ........... defines optional suffix to package name when installing compiler with apt, and whenever compiler version is important for build process - # cc: gcc, cxx: g++, ver: null --becomes--> sudo apt install gcc g++ - # cc: gcc, cxx: g++, ver: 10 --becomes--> sudo apt install gcc-10 g++-10 - # arch .......... defines if building 32bit or 64bit application; used in multiple places to prepare build environment - # also used as job name suffix (" x32" or " x64") - # generator ..... passed to CMake configuration step (as `-G` switch) - # can-fail ...... defines if job status should be set to success even if compilation fails - # applies *only* to compilation step; errors in any other steps (installation, preparing build directory, etc.) still mark job as failed - # artifact ...... path to compiled application; use "NO" if given job run should not generate any artifacts (case sensitive) - # artifact-os ... defines artifact name suffix - # - - { name: Linux GCC, os: ubuntu-20.04, cc: gcc, cxx: g++, ver: null, arch: 32, generator: "Unix Makefiles", can-fail: false, artifact: Build/fallout2-ce, artifact-os: linux } - # { name: Linux GCC, os: ubuntu-22.04, cc: gcc, cxx: g++, ver: null, arch: 64, generator: "Unix Makefiles", can-fail: true, artifact: Build/fallout2-ce, artifact-os: linux } - - { name: Linux GCC 10, os: ubuntu-22.04, cc: gcc, cxx: g++, ver: 10, arch: 32, generator: "Unix Makefiles", can-fail: false, artifact: NO, artifact-os: linux } - # { name: Linux GCC 10, os: ubuntu-22.04, cc: gcc, cxx: g++, ver: 10, arch: 64, generator: "Unix Makefiles", can-fail: true, artifact: NO, artifact-os: linux } - # { name: MacOS 11 CLang, os: macOS-11, cc: clang, cxx: clang++, ver: null, arch: 64, generator: "Unix Makefiles", can-fail: true, artifact: NO, artifact-os: mac } - # { name: MacOS 12 CLang, os: macOS-12, cc: clang, cxx: clang++, ver: null, arch: 64, generator: "Unix Makefiles", can-fail: true, artifact: NO, artifact-os: mac } - - { name: Windows VS2019, os: windows-2019, cc: cl, cxx: cl, ver: null, arch: 32, generator: "Visual Studio 16 2019", can-fail: false, artifact: NO, artifact-os: windows } - # { name: Windows VS2019, os: windows-2019, cc: cl, cxx: cl, ver: null, arch: 64, generator: "Visual Studio 16 2019", can-fail: true, artifact: NO, artifact-os: windows } - - { name: Windows VS2022, os: windows-2022, cc: cl, cxx, cl, ver: null, arch: 32, generator: "Visual Studio 17 2022", can-fail: false, artifact: Build/Release/fallout2-ce.exe, artifact-os: windows } - # { name: Windows VS2022, os: windows-2022, cc: cl, cxx, cl, ver: null, arch: 64, generator: "Visual Studio 17 2022", can-fail: true, artifact: Build/Release/fallout2-ce.exe, artifact-os: windows } + arch: + - x86 + - x64 steps: - - name: Configure - run: | - : Here be dragons : - #set -x - arch=${{ matrix.cfg.arch }} - ver="${{ matrix.cfg.ver }}" - cc="${{ matrix.cfg.cc }}" - cxx="${{ matrix.cfg.cxx }}" - - # Variables exported for other steps: - # - # GHA_PM .................. packages manager executable (might include `sudo`); if not exported, `Install` step is skipped - # GHA_PM_COMPILER ......... compiler package(s), including version (if set in matrix) - # GHA_PM_COMPILER_EXTRA ... extra compiler packages - # GHA_PM_LIBS ............. required libraries packages - # GHA_CC .................. C compiler executable, including version (if set in matrix) - # GHA_CXX ................. C++ compiler executable, including version (if set in matrix) - # GHA_PLATFORM ............ CMake -A ... switch, for configure step - # GHA_TOOLCHAIN ........... CMake -DCMAKE_TOOLCHAIN_FILE=... switch, for configure step - - # Compiler executables names - [[ "$ver" != "" ]] && verCMAKE="-$ver" - echo GHA_CC="$cc$verCMAKE" >> $GITHUB_ENV - echo GHA_CXX="$cxx$verCMAKE" >> $GITHUB_ENV - - if [[ $arch -ne 32 ]] && [[ $arch -ne 64 ]]; then - echo "[ERROR] matrix.cfg.arch must be set to 32 or 64" - exit 1 - elif [[ "$ver" != "" ]] && ! [[ "$ver" =~ [0-9]+ ]]; then - echo "[ERROR] matrix.cfg.ver must be null or number" - exit 1 - elif [[ $RUNNER_OS == "Linux" ]]; then - [[ "$ver" != "" ]] && verPM="-$ver" - - echo GHA_PM="sudo apt" >> $GITHUB_ENV - apt="amd64" - - if [[ "$cc" == "clang" ]] && [[ "$cxx" == "clang++" ]]; then - echo GHA_PM_COMPILER="$cc$verPM" >> $GITHUB_ENV - else - echo GHA_PM_COMPILER="$cc$verPM $cxx$verPM" >> $GITHUB_ENV - fi - - # Handle building 32bit executable on 64bit host - if [[ $arch -eq 32 ]]; then - apt="i386" - sudo dpkg --add-architecture $apt - - # Extra packages - echo GHA_PM_COMPILER_EXTRA="gcc${verPM}-multilib g++${verPM}-multilib" >> $GITHUB_ENV - - # Toolchain file; without proper 32@64 toolchain setup CMake can't find OpenGL libraries - echo GHA_TOOLCHAIN="-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/Linux32.cmake" >> $GITHUB_ENV - fi - - echo GHA_PM_LIBS="libsdl2-dev:$apt zlib1g-dev:$apt" >> $GITHUB_ENV - elif [[ $RUNNER_OS == "macOS" ]]; then - [[ "$ver" != "" ]] && verPM="@$ver" - echo GHA_PM="brew" >> $GITHUB_ENV - - if [[ "$cc" == "gcc" ]] && [[ "$cxx" == "g++" ]]; then - echo GHA_PM_COMPILER="$cc$verPM" >> $GITHUB_ENV - elif [[ "$cc" == "clang" ]] && [[ "$cxx" == "clang++" ]]; then - echo GHA_PM_COMPILER="llvm$verPM" >> $GITHUB_ENV - fi - - echo GHA_PM_LIBS="sdl2" >> $GITHUB_ENV - elif [[ $RUNNER_OS == "Windows" ]]; then - # VisualStudio; '-A' switch is used to compile 32bit targets on 64bit hosts - if [[ "${{ matrix.cfg.generator }}" =~ ^Visual ]]; then - if [[ $arch -eq 32 ]]; then - echo GHA_PLATFORM="-A Win32" >> $GITHUB_ENV - else - echo GHA_PLATFORM="-A x64" >> $GITHUB_ENV - fi - fi - fi - - - name: Install - if: env.GHA_PM != '' - run: | - : - #set -x - - echo ::group::Update package manager - $GHA_PM update 2>&1 - echo ::endgroup:: - - if [[ ${{ matrix.cfg.arch }} -eq 32 ]] && ([[ "$ImageOS" == "ubuntu20" ]] || [[ "${{ matrix.cfg.os }}" == "ubuntu-20.04" ]]); then - echo ::group::Fix Ubuntu 20 - $GHA_PM install --allow-downgrades libpcre2-8-0=10.34-7 - echo ::endgroup:: - fi - - if [[ "$GHA_PM_COMPILER" != "" ]] || [[ "$GHA_PM_COMPILER_EXTRA" ]]; then - echo ::group::Compiler - $GHA_PM install $GHA_PM_COMPILER $GHA_PM_COMPILER_EXTRA - echo ::endgroup:: - fi - - if [[ "$GHA_PM_LIBS" != "" ]]; then - echo ::group::Libraries - $GHA_PM install $GHA_PM_LIBS - echo :endgroup:: - fi - - name: Clone uses: actions/checkout@v3 - # Using ${{ env.NAME }} here (instead of usual $NAME) to make full command line clearly displayed, without need to check step environment first - - name: Prepare - run: cmake -B Build -G "${{ matrix.cfg.generator }}" ${{ env.GHA_PLATFORM }} ${{ env.GHA_TOOLCHAIN }} 2>&1 - env: - CC: ${{ env.GHA_CC }} - CXX: ${{ env.GHA_CXX }} + - name: Dependencies (x86) + if: matrix.arch == 'x86' + run: | + sudo dpkg --add-architecture i386 + sudo apt update + sudo apt install --allow-downgrades libpcre2-8-0=10.34-7 + sudo apt install g++-multilib libsdl2-dev:i386 zlib1g-dev:i386 + + - name: Dependencies (x64) + if: matrix.arch == 'x64' + run: | + sudo apt update + sudo apt install libsdl2-dev zlib1g-dev + + - name: Cache cmake build + uses: actions/cache@v3 + with: + path: build + key: linux-${{ matrix.arch }}-cmake-v1 + + - name: Configure (x86) + if: matrix.arch == 'x86' + run: | + cmake \ + -B build \ + -D CMAKE_BUILD_TYPE=RelWithDebInfo \ + -D CMAKE_TOOLCHAIN_FILE=cmake/toolchain/Linux32.cmake \ + # EOL + + - name: Configure (x64) + if: matrix.arch == 'x64' + run: | + cmake \ + -B build \ + -D CMAKE_BUILD_TYPE=RelWithDebInfo \ + # EOL - name: Build - run: cmake --build Build --config Release && echo BUILD_OK=1 >> $GITHUB_ENV - continue-on-error: ${{ matrix.cfg.can-fail }} + run: | + cmake --build build -j $(nproc) - - name: Artifact prepare - if: matrix.cfg.artifact != 'NO' && env.BUILD_OK == 1 - run: | - : - echo BUILD_OK=0 >> $GITHUB_ENV - dir="${{ matrix.cfg.artifact-os }}/x${{ matrix.cfg.arch }}" - mkdir -p "$dir" - cp "${{ matrix.cfg.artifact }}" "$dir" - echo BUILD_OK=1 >> $GITHUB_ENV - - - name: Artifact upload - if: matrix.cfg.artifact != 'NO' && env.BUILD_OK == 1 + - name: Upload uses: actions/upload-artifact@v3 with: - name: fallout2-ce-${{ matrix.cfg.artifact-os }} - path: "${{ matrix.cfg.artifact-os }}/x${{ matrix.cfg.arch }}" + name: fallout2-ce-linux-${{ matrix.arch }} + path: build/fallout2-ce retention-days: 7 macos: + name: macOS + runs-on: macos-latest steps: @@ -226,17 +115,69 @@ jobs: run: | brew install sdl2 + - name: Cache cmake build + uses: actions/cache@v3 + with: + path: build + key: macos-cmake-v1 + - name: Configure run: | - cmake -B build/macos -DCMAKE_BUILD_TYPE=RelWithDebInfo + cmake -B build -D CMAKE_BUILD_TYPE=RelWithDebInfo - name: Build run: | - cmake --build build/macos -j $(sysctl -n hw.physicalcpu) --target package + cmake --build build -j $(sysctl -n hw.physicalcpu) --target package - name: Upload uses: actions/upload-artifact@v3 with: - name: fallout2-ce-macos - path: build/macos/_CPack_Packages/Darwin/DragNDrop/fallout2-ce/fallout2-ce.dmg + name: fallout2-ce-macos.dmg + path: build/_CPack_Packages/Darwin/DragNDrop/fallout2-ce/fallout2-ce.dmg + retention-days: 7 + + windows: + name: Windows (${{ matrix.arch }}) + + runs-on: windows-2019 + + strategy: + fail-fast: false + matrix: + include: + - arch: x86 + generator-platform: Win32 + - arch: x64 + generator-platform: x64 + + steps: + - name: Clone + uses: actions/checkout@v3 + + - name: Cache cmake build + uses: actions/cache@v3 + with: + path: build + key: windows-${{ matrix.arch }}-cmake-v1 + + - name: Configure + run: | + cmake \ + -B build \ + -G "Visual Studio 16 2019" \ + -A ${{ matrix.generator-platform }} \ + # EOL + + - name: Build + run: | + cmake \ + --build build \ + --config RelWithDebInfo \ + # EOL + + - name: Upload + uses: actions/upload-artifact@v3 + with: + name: fallout2-ce-windows-${{ matrix.arch }} + path: build/RelWithDebInfo/fallout2-ce.exe retention-days: 7