From e83303e587bbd66075c16d07af80571bfc719161 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Tue, 27 May 2025 18:34:29 -0300 Subject: [PATCH] fix: gha workflows --- .github/workflows/analysis-sonarcloud.yml | 86 +++++++------ .github/workflows/build-browser.yml | 50 +++++--- .github/workflows/build-docker.yml | 33 ++++- .github/workflows/build-ubuntu.yml | 121 +++++++++++++----- .github/workflows/build-windows-solution.yml | 86 +++++++++++++ .github/workflows/build-windows.yml | 127 ++++++++++++++----- CMakePresets.json | 18 +++ src/CMakeLists.txt | 11 +- vc17/otclient.vcxproj | 60 +++++++-- 9 files changed, 458 insertions(+), 134 deletions(-) create mode 100644 .github/workflows/build-windows-solution.yml diff --git a/.github/workflows/analysis-sonarcloud.yml b/.github/workflows/analysis-sonarcloud.yml index 9555b18a66..fa4be1b3ea 100644 --- a/.github/workflows/analysis-sonarcloud.yml +++ b/.github/workflows/analysis-sonarcloud.yml @@ -1,4 +1,3 @@ ---- name: Analysis - SonarCloud on: @@ -12,7 +11,6 @@ env: VCPKG_BUILD_TYPE: release CMAKE_BUILD_PARALLEL_LEVEL: 2 MAKEFLAGS: '-j 2' - NUMBER_OF_PROCESSORS: 2 jobs: sonarcloud: @@ -20,64 +18,71 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@main - if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }} - with: - fetch-depth: 0 - ref: ${{github.event.pull_request.head.ref}} - repository: ${{github.event.pull_request.head.repo.full_name}} - - - uses: actions/checkout@main - if: ${{ github.event_name == 'push' }} + - name: Checkout repository + uses: actions/checkout@v4 with: fetch-depth: 0 + ref: ${{ github.event_name == 'push' && github.ref || github.event.pull_request.head.ref }} + repository: ${{ github.event_name == 'push' && github.repository || github.event.pull_request.head.repo.full_name }} - name: Install Linux Dependencies - run: > - sudo apt-get update && sudo apt-get install ccache libglew-dev libx11-dev linux-headers-$(uname -r) + run: | + sudo apt-get update + sudo apt-get install -y ccache libglew-dev libx11-dev linux-headers-$(uname -r) - - name: Switch to gcc-11 + - name: Switch to GCC 11 run: | - sudo apt install gcc-11 g++-11 - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11 + sudo apt install -y gcc-11 g++-11 + sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 \ + --slave /usr/bin/g++ g++ /usr/bin/g++-11 \ + --slave /usr/bin/gcov gcov /usr/bin/gcov-11 sudo update-alternatives --set gcc /usr/bin/gcc-11 - - name: CCache - id: ccache - uses: actions/cache@main + - name: Detect CPU core count + id: cpu-count + run: echo "count=$(nproc)" >> "$GITHUB_OUTPUT" + + - name: Cache CCache + uses: actions/cache@v4 with: path: $HOME/.ccache - key: ccache-${{ runner.os }}-${{ hashFiles('**/src') }} + key: ccache-${{ runner.os }}-${{ hashFiles('CMakeLists.txt', 'vcpkg.json', 'src/**/*.cpp', 'src/**/*.h') }} restore-keys: | - ccache-${{ runner.os}}- + ccache-${{ runner.os }}- - - name: Sonar cache - uses: actions/cache@main + - name: Cache SonarCloud analysis data + uses: actions/cache@v4 with: path: $HOME/.cfamily - key: sonar-${{ runner.os}}-${{ hashFiles('**/src') }} + key: sonar-cfamily-${{ runner.os }}-${{ hashFiles('CMakeLists.txt', 'vcpkg.json', 'src/**/*.cpp', 'src/**/*.h') }} restore-keys: | - sonar-${{ runner.os}}- + sonar-cfamily-${{ runner.os }}- - name: Cache SonarCloud packages - uses: actions/cache@main + uses: actions/cache@v4 with: path: $HOME/.sonar/cache - key: sonar-${{ runner.os}}-${{ hashFiles('**/src') }} + key: sonar-packages-${{ runner.os }} restore-keys: | - sonar-${{ runner.os}}- + sonar-packages-${{ runner.os }}- - - name: Restore artifacts and install vcpkg + - name: Extract vcpkg commit ID id: vcpkg-step run: | vcpkgCommitId=$(grep '.builtin-baseline' vcpkg.json | awk -F: '{print $2}' | tr -d '," ') - echo "vcpkg commit ID: $vcpkgCommitId" - echo "name=vcpkgGitCommitId::$vcpkgCommitId" >> $env:GITHUB_OUTPUT + echo "vcpkgGitCommitId=$vcpkgCommitId" >> "$GITHUB_OUTPUT" + + - name: Cache vcpkg installed packages + uses: actions/cache@v4 + with: + path: build/vcpkg_installed + key: vcpkg-installed-${{ runner.os }}-${{ steps.vcpkg-step.outputs.vcpkgGitCommitId }} + restore-keys: | + vcpkg-installed-${{ runner.os }}- - - name: Get vcpkg commit id from vcpkg.json - uses: lukka/run-vcpkg@main + - name: Setup vcpkg with baseline + uses: lukka/run-vcpkg@v11 with: - vcpkgGitURL: "https://github.com/microsoft/vcpkg.git" vcpkgGitCommitId: ${{ steps.vcpkg-step.outputs.vcpkgGitCommitId }} vcpkgJsonIgnores: "['**/vcpkg/**', '**/browser/overlay-ports/**']" @@ -87,7 +92,12 @@ jobs: - name: Generate compilation database run: | mkdir -p build - cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DOPTIONS_ENABLE_CCACHE=ON -DSPEED_UP_BUILD_UNITY=OFF -S . -B build + cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" \ + -DOPTIONS_ENABLE_CCACHE=ON \ + -DSPEED_UP_BUILD_UNITY=OFF \ + -S . -B build - name: Run PR sonar-scanner if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }} @@ -97,13 +107,13 @@ jobs: BRANCH: ${{ github.event.pull_request.head.ref }} run: | sonar-scanner \ - --define sonar.cfamily.threads="${{ env.NUMBER_OF_PROCESSORS }}" \ + --define sonar.cfamily.threads=${{ steps.cpu-count.outputs.count }} \ --define sonar.cfamily.cache.enabled=true \ --define sonar.cfamily.cache.path="$HOME/.cfamily" \ --define sonar.cfamily.compile-commands=build/compile_commands.json \ --define sonar.pullrequest.key=${{ github.event.pull_request.number }} \ --define sonar.pullrequest.branch=$BRANCH \ - --define sonar.pullrequest.base=${{ github.event.pull_request.base_ref }} + --define sonar.pullrequest.base=${{ github.event.pull_request.base.ref }} - name: Run sonar-scanner if: ${{ github.event_name == 'push' }} @@ -112,7 +122,7 @@ jobs: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | sonar-scanner \ - --define sonar.cfamily.threads="${{ env.NUMBER_OF_PROCESSORS }}" \ + --define sonar.cfamily.threads=${{ steps.cpu-count.outputs.count }} \ --define sonar.cfamily.cache.enabled=true \ --define sonar.cfamily.cache.path="$HOME/.cfamily" \ --define sonar.cfamily.compile-commands=build/compile_commands.json diff --git a/.github/workflows/build-browser.yml b/.github/workflows/build-browser.yml index 42f1beaa59..5f8e31ea31 100644 --- a/.github/workflows/build-browser.yml +++ b/.github/workflows/build-browser.yml @@ -3,22 +3,40 @@ name: Build - Emscripten on: workflow_dispatch: pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths: + - "src/**" + - ".github/workflows/build-emscripten.yml" push: + paths: + - "src/**" + - ".github/workflows/build-emscripten.yml" branches: - main jobs: - job: + cancel-runs: + if: github.event_name == 'pull_request' && github.ref != 'refs/heads/main' + runs-on: ubuntu-latest + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@main + with: + access_token: ${{ github.token }} + + build: name: ${{ matrix.buildtype }} runs-on: ubuntu-latest + concurrency: + group: otclient-emscripten-${{ github.workflow }}-${{ github.ref }}-${{ matrix.buildtype }} + cancel-in-progress: true + strategy: fail-fast: false matrix: - buildtype: [emscripten-release, emscripten-debug] + buildtype: [emscripten-debug] include: - - buildtype: emscripten-release - cmake_build_type: Release - buildtype: emscripten-debug cmake_build_type: Debug @@ -37,13 +55,17 @@ jobs: vcpkgCommitId=$(grep '.builtin-baseline' vcpkg.json | awk -F: '{print $2}' | tr -d '," ') echo "vcpkgGitCommitId=$vcpkgCommitId" >> $GITHUB_OUTPUT - - name: Cache vcpkg binary artifacts + - name: Cache full vcpkg artifacts uses: actions/cache@v4 with: - path: ~/.cache/vcpkg/archives - key: vcpkg-binary-cache-${{ steps.vcpkg-step.outputs.vcpkgGitCommitId }}-${{ matrix.buildtype }} + path: | + ~/.cache/vcpkg/archives + ${{ github.workspace }}/vcpkg/installed + ${{ github.workspace }}/vcpkg/buildtrees + ${{ github.workspace }}/vcpkg/downloads + key: vcpkg-${{ matrix.buildtype }}-${{ steps.hash.outputs.hash }} restore-keys: | - vcpkg-binary-cache-${{ steps.vcpkg-step.outputs.vcpkgGitCommitId }}- + vcpkg-${{ matrix.buildtype }}- - name: Setup vcpkg uses: lukka/run-vcpkg@v11 @@ -53,13 +75,9 @@ jobs: - name: Install CMake and Ninja uses: lukka/get-cmake@v3.31.6 - - name: Cache CMake build directory - uses: actions/cache@v4 - with: - path: ${{ github.workspace }}/build-${{ matrix.buildtype }} - key: cmake-cache-${{ github.sha }}-${{ matrix.buildtype }} - restore-keys: | - cmake-cache-${{ github.sha }}-${{ matrix.buildtype }}- + - name: Compute vcpkg hash + id: hash + run: echo "hash=$(sha256sum vcpkg.json | cut -d' ' -f1)" >> $GITHUB_OUTPUT - name: Configure CMake run: | @@ -85,4 +103,4 @@ jobs: with: name: otclient-${{ matrix.buildtype }}-${{ github.sha }} path: ${{ github.workspace }}/build-${{ matrix.buildtype }}/bin/ - retention-days: 30 \ No newline at end of file + retention-days: 30 diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index 1848d3dfa1..7c651d98ce 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -1,22 +1,47 @@ ---- name: Build - Docker on: workflow_dispatch: pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths: + - "Dockerfile" + - ".dockerignore" + - ".github/workflows/build-docker.yml" + - "src/**" push: branches: [ $default-branch ] + paths: + - "Dockerfile" + - ".dockerignore" + - ".github/workflows/build-docker.yml" + - "src/**" env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} jobs: + cancel-runs: + if: github.event_name == 'pull_request' && github.ref != 'refs/heads/main' + runs-on: ubuntu-latest + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@main + with: + access_token: ${{ github.token }} + docker: + name: Docker Build & Push runs-on: ubuntu-latest + + concurrency: + group: otclient-docker-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + steps: - name: Checkout - uses: actions/checkout@main + uses: actions/checkout@v4 with: fetch-depth: 0 @@ -30,15 +55,13 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - # Extract metadata (tags, labels) for Docker - # https://github.com/docker/metadata-action - name: Extract Docker metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - name: Build and push Docker image + - name: Build and push Docker image with cache uses: docker/build-push-action@v5 with: context: . diff --git a/.github/workflows/build-ubuntu.yml b/.github/workflows/build-ubuntu.yml index 06dc0d7445..16114e7d82 100644 --- a/.github/workflows/build-ubuntu.yml +++ b/.github/workflows/build-ubuntu.yml @@ -1,72 +1,135 @@ ---- name: Build - Ubuntu on: workflow_dispatch: pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths: + - "src/**" + - ".github/workflows/build-ubuntu.yml" + merge_group: push: branches: - main + paths: + - "src/**" + - ".github/workflows/build-ubuntu.yml" env: - VCPKG_ENABLE_METRICS: 1 + CMAKE_BUILD_PARALLEL_LEVEL: 2 + MAKEFLAGS: "-j 2" jobs: - job: + cancel-runs: + if: github.event_name == 'pull_request' && github.ref != 'refs/heads/main' + runs-on: ubuntu-latest + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@main + with: + access_token: ${{ github.token }} + + build: + if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }} name: ${{ matrix.os }}-${{ matrix.buildtype }} runs-on: ${{ matrix.os }} + concurrency: + group: otclient-${{ github.workflow }}-${{ github.ref }}-${{ matrix.buildtype }} + cancel-in-progress: true + strategy: fail-fast: false matrix: - os: [ubuntu-22.04, ubuntu-24.04] - buildtype: [linux-release, linux-debug] + os: [ubuntu-24.04] + buildtype: [linux-debug] include: - - os: ubuntu-22.04 - triplet: x64-linux - os: ubuntu-24.04 triplet: x64-linux + cmake_build_type: Debug steps: - name: Checkout repository - uses: actions/checkout@main + uses: actions/checkout@v4 - name: Install Linux Dependencies - run: > - sudo apt-get update && sudo apt-get install ccache libglew-dev libx11-dev linux-headers-$(uname -r) + run: | + sudo apt-get update + sudo apt-get install -y ccache gcc-14 g++-14 libglew-dev libx11-dev linux-headers-$(uname -r) - - name: Switch to gcc-12 + - name: Switch to GCC 14 run: | - sudo apt install gcc-12 g++-12 - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100 --slave /usr/bin/g++ g++ /usr/bin/g++-12 --slave /usr/bin/gcov gcov /usr/bin/gcov-12 - sudo update-alternatives --set gcc /usr/bin/gcc-12 + sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 100 + sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 100 + sudo update-alternatives --set gcc /usr/bin/gcc-14 + sudo update-alternatives --set g++ /usr/bin/g++-14 - - name: Restore artifacts and install vcpkg + - name: Get vcpkg commit ID id: vcpkg-step run: | vcpkgCommitId=$(grep '.builtin-baseline' vcpkg.json | awk -F: '{print $2}' | tr -d '," ') - echo "vcpkg commit ID: $vcpkgCommitId" - echo "vcpkgGitCommitId=$vcpkgCommitId" >> "$GITHUB_OUTPUT" + echo "vcpkgGitCommitId=$vcpkgCommitId" >> $GITHUB_OUTPUT + + - name: Compute vcpkg.json hash + id: hash + shell: pwsh + run: | + $json = Get-Content "vcpkg.json" -Raw -Encoding UTF8 + $bytes = [System.Text.Encoding]::UTF8.GetBytes($json) + $sha256 = [System.Security.Cryptography.SHA256]::Create() + $hashBytes = $sha256.ComputeHash($bytes) + $hash = [BitConverter]::ToString($hashBytes) -replace '-', '' + "hash=$hash" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 - - name: Get vcpkg commit id from vcpkg.json - uses: lukka/run-vcpkg@main + - name: Cache vcpkg binary artifacts + uses: actions/cache@v4 + with: + path: | + ~/.cache/vcpkg/archives + ${{ github.workspace }}/vcpkg/downloads + ${{ github.workspace }}/vcpkg/installed + ${{ github.workspace }}/vcpkg/buildtrees + key: vcpkg-${{ matrix.os }}-${{ matrix.buildtype }}-${{ steps.hash.outputs.hash }} + restore-keys: | + vcpkg-${{ matrix.buildtype }}- + + - name: Setup vcpkg + uses: lukka/run-vcpkg@v11 with: vcpkgGitCommitId: ${{ steps.vcpkg-step.outputs.vcpkgGitCommitId }} - vcpkgJsonIgnores: "['**/vcpkg/**', '**/browser/overlay-ports/**']" - - name: Get latest CMake and ninja + - name: Install CMake and Ninja uses: lukka/get-cmake@v3.31.6 - - name: Run CMake - uses: lukka/run-cmake@main + - name: Cache CMake build directory + uses: actions/cache@v4 with: - configurePreset: ${{ matrix.buildtype }} - buildPreset: ${{ matrix.buildtype }} + path: ${{ github.workspace }}/build-${{ matrix.buildtype }} + key: cmake-dir-${{ matrix.buildtype }} + restore-keys: | + cmake-dir-${{ matrix.buildtype }} + + - name: Configure and Build + run: | + cmake -G Ninja -S . -B build-${{ matrix.buildtype }} \ + -DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} \ + -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake \ + -DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }} \ + -DTOGGLE_BIN_FOLDER=ON \ + -DOPTIONS_ENABLE_IPO=OFF \ + -DTOGGLE_BOT_PROTECTION=OFF \ + -DCMAKE_C_COMPILER=gcc \ + -DCMAKE_CXX_COMPILER=g++ + + cmake --build build-${{ matrix.buildtype }} --target otclient + + - name: Check otclient.exe path + run: Get-ChildItem -Recurse -Filter "otclient*.exe" + shell: pwsh - - name: Create and Upload Artifact - if: ${{ github.event_name != 'pull_request' }} - uses: actions/upload-artifact@main + - name: Upload Artifact + uses: actions/upload-artifact@v4 with: name: otclient-${{ matrix.os }}-${{ matrix.buildtype }}-${{ github.sha }} path: | - ${{ github.workspace }}/otclient + ${{ github.workspace }}/build-${{ matrix.buildtype }}/bin/ diff --git a/.github/workflows/build-windows-solution.yml b/.github/workflows/build-windows-solution.yml new file mode 100644 index 0000000000..ef2c3afa45 --- /dev/null +++ b/.github/workflows/build-windows-solution.yml @@ -0,0 +1,86 @@ +name: Build - Windows - Solution + +on: + workflow_dispatch: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths: ["src/**"] + push: + branches: [main] + paths: ["src/**"] + +env: + CMAKE_BUILD_PARALLEL_LEVEL: 2 + MAKEFLAGS: "-j 2" + +jobs: + build: + runs-on: windows-2022 + strategy: + matrix: + buildtype: [Debug] + triplet: [x64-windows] + + steps: + - uses: actions/checkout@v4 + - uses: microsoft/setup-msbuild@v1.1 + + - name: Get vcpkg commit ID + id: vcpkg-step + shell: pwsh + run: | + $json = Get-Content vcpkg.json -Raw | ConvertFrom-Json + $commit = $json.'builtin-baseline' + echo "vcpkgGitCommitId=$commit" >> $env:GITHUB_OUTPUT + + - name: Compute vcpkg.json hash + id: hash + shell: pwsh + run: | + $bytes = [System.Text.Encoding]::UTF8.GetBytes((Get-Content "${{ github.workspace }}\vcpkg.json" -Raw)) + $sha256 = [System.Security.Cryptography.SHA256]::Create().ComputeHash($bytes) + $hash = [BitConverter]::ToString($sha256) -replace '-', '' + "hash=$hash" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + + - name: Cache vcpkg artifacts + uses: actions/cache@v4 + with: + path: | + ${{ github.workspace }}\vcpkg\installed + ${{ github.workspace }}\vcpkg\buildtrees + ${{ github.workspace }}\vcpkg\downloads + key: vcpkg-${{ matrix.triplet }}-${{ steps.hash.outputs.hash }} + restore-keys: | + vcpkg-${{ matrix.triplet }}- + + - name: Install vcpkg + uses: lukka/run-vcpkg@v11 + with: + vcpkgGitCommitId: ${{ steps.vcpkg-step.outputs.vcpkgGitCommitId }} + + - name: Configure and Build + uses: lukka/run-cmake@main + with: + configurePreset: windows-debug-msbuild + buildPreset: windows-debug-msbuild + + - name: Prepare & upload artifacts + shell: pwsh + run: | + $out = "$env:GITHUB_WORKSPACE\artifacts" + New-Item -ItemType Directory -Force -Path $out | Out-Null + $exePath = Get-ChildItem -Recurse -Path $env:GITHUB_WORKSPACE -Filter "otclient*.exe" | Select-Object -First 1 + if (-not $exePath) { + Write-Error "Not found otclient*.exe!" + exit 1 + } + Copy-Item $exePath.FullName -Destination $out + $dlls = Get-ChildItem -Path $exePath.Directory.FullName -Filter "*.dll" + foreach ($dll in $dlls) { + Copy-Item $dll.FullName -Destination $out + } + + - uses: actions/upload-artifact@v4 + with: + name: otclient-${{ matrix.buildtype }} + path: artifacts diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index 37ff655cbd..2b4d6f2b5d 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -1,79 +1,138 @@ ---- name: Build - Windows on: workflow_dispatch: pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths: + - "src/**" + - ".github/workflows/build-windows.yml" + merge_group: push: + paths: + - "src/**" + - ".github/workflows/build-windows.yml" branches: - main env: CMAKE_BUILD_PARALLEL_LEVEL: 2 - MAKEFLAGS: '-j 2' + MAKEFLAGS: "-j 2" jobs: - job: + cancel-runs: + if: github.event_name == 'pull_request' && github.ref != 'refs/heads/main' + runs-on: ubuntu-latest + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.1 + with: + access_token: ${{ github.token }} + + build: + if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }} name: ${{ matrix.os }}-${{ matrix.buildtype }} runs-on: ${{ matrix.os }} + + concurrency: + group: otclient-${{ github.workflow }}-${{ github.ref }}-${{ matrix.buildtype }} + cancel-in-progress: true + strategy: + fail-fast: false matrix: os: [windows-2022] - buildtype: [windows-release, windows-release-asan, windows-debug] + buildtype: [windows-release] include: - os: windows-2022 - triplet: x64-windows - packages: > - sccache + triplet: x64-windows-static + packages: sccache steps: - name: Checkout repository - uses: actions/checkout@main + uses: actions/checkout@v4 + + - name: Get vcpkg commit ID + id: vcpkg-step + shell: pwsh + run: | + $json = Get-Content vcpkg.json -Raw | ConvertFrom-Json + $commit = $json.'builtin-baseline' + echo "vcpkgGitCommitId=$commit" >> $env:GITHUB_OUTPUT + + - name: Compute vcpkg.json hash + id: hash + shell: pwsh + run: | + $json = Get-Content "vcpkg.json" -Raw -Encoding UTF8 + $bytes = [System.Text.Encoding]::UTF8.GetBytes($json) + $sha256 = [System.Security.Cryptography.SHA256]::Create() + $hashBytes = $sha256.ComputeHash($bytes) + $hash = [BitConverter]::ToString($hashBytes) -replace '-', '' + "hash=$hash" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 + + - name: Cache vcpkg artifacts (Windows) + uses: actions/cache@v4 + with: + path: | + ${{ github.workspace }}/vcpkg/installed + ${{ github.workspace }}/vcpkg/buildtrees + ${{ github.workspace }}/vcpkg/downloads + key: vcpkg-${{ matrix.os }}-${{ matrix.buildtype }}-${{ steps.hash.outputs.hash }} + restore-keys: | + vcpkg-${{ matrix.os }}-${{ matrix.buildtype }}- - - name: CCache + - name: CCache with SCCACHE uses: hendrikmuhs/ccache-action@main with: max-size: "1G" variant: "sccache" key: ccache-${{ matrix.os }}-${{ matrix.buildtype }} restore-keys: | - ccache-${{ matrix.os }} + ccache-${{ matrix.os }}-${{ matrix.buildtype }} - - name: Restore artifacts and install vcpkg - id: vcpkg-step - run: | - $json=Get-Content vcpkg.json -Raw | ConvertFrom-Json - $vcpkgCommitId=$json.'builtin-baseline' - Write-Host "vcpkg commit ID: $vcpkgCommitId" - echo "vcpkgGitCommitId=$vcpkgCommitId" >> "$GITHUB_OUTPUT" + - name: Remove Windows pre-installed MySQL (for clean builds) + run: Remove-Item -Recurse -Force -ErrorAction SilentlyContinue "C:/mysql*" - - name: Get vcpkg commit id from vcpkg.json - uses: lukka/run-vcpkg@main + - name: Install vcpkg + if: ${{ matrix.buildtype == 'windows-release' }} + uses: lukka/run-vcpkg@v11 with: - vcpkgGitURL: "https://github.com/microsoft/vcpkg.git" vcpkgGitCommitId: ${{ steps.vcpkg-step.outputs.vcpkgGitCommitId }} - vcpkgJsonIgnores: "['**/vcpkg/**', '**/browser/overlay-ports/**']" - - name: Get latest CMake and ninja + - name: Get latest CMake and Ninja uses: lukka/get-cmake@v3.31.6 - - name: Run CMake + - name: Configure and Build + if: ${{ matrix.buildtype == 'windows-release' }} uses: lukka/run-cmake@main with: configurePreset: ${{ matrix.buildtype }} buildPreset: ${{ matrix.buildtype }} - - name: Create and Upload Artifact (exe) - uses: actions/upload-artifact@main - with: - name: otclient-${{ matrix.os }}-${{ matrix.buildtype }}-${{ github.sha }} - path: | - ${{ github.workspace }}/otclient.exe + - name: Prepare artifact folder + shell: pwsh + run: | + $artifactDir = "$env:GITHUB_WORKSPACE\artifacts" + New-Item -ItemType Directory -Force -Path $artifactDir | Out-Null + + $exePath = Get-ChildItem -Recurse -Path $env:GITHUB_WORKSPACE -Filter "otclient*.exe" | Select-Object -First 1 + + if (-not $exePath) { + Write-Error "Not found otclient*.exe!" + exit 1 + } - - name: Create and Upload Artifact (dlls) - uses: actions/upload-artifact@main + Copy-Item $exePath.FullName -Destination $artifactDir + + $dlls = Get-ChildItem -Path $exePath.Directory.FullName -Filter "*.dll" + foreach ($dll in $dlls) { + Copy-Item $dll.FullName -Destination $artifactDir + } + + - name: Upload Executable Artifact (MSBuild) + uses: actions/upload-artifact@v4 with: - name: otclient-dlls-${{ matrix.os }}-${{ matrix.buildtype }}-${{ github.sha }} + name: otclient-${{ matrix.os }}-${{ matrix.buildtype }} path: | - ${{ github.workspace }}/*.dll - + ${{ github.workspace }}/artifacts diff --git a/CMakePresets.json b/CMakePresets.json index 06fb7a37e8..14d89ec0ff 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -37,6 +37,20 @@ "rhs": "Windows" } }, + { + "name": "windows-debug-msbuild", + "inherits": "windows-debug", + "displayName": "Windows - Debug (msbuild)", + "description": "Windows Debug build using vcpkg-test manifest", + "generator": "Visual Studio 17 2022", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "DEBUG_LOG": "ON", + "ASAN_ENABLED": "ON", + "BUILD_STATIC_LIBRARY": "OFF", + "VCPKG_TARGET_TRIPLET": "x64-windows" + } + }, { "name": "linux-release", "displayName": "Linux - Release", @@ -158,6 +172,10 @@ "name": "windows-debug", "configurePreset": "windows-debug" }, + { + "name": "windows-debug-msbuild", + "configurePreset": "windows-debug-msbuild" + }, { "name": "macos-release", "configurePreset": "macos-release" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b2cdbadb1f..36ac194649 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -164,7 +164,6 @@ endif() # Client options add_definitions(-DCLIENT) -add_definitions(-D_WIN32_WINNT=0x0501) add_definitions(${FRAMEWORK_DEFINITIONS}) add_definitions(-D"VERSION=${VERSION}") @@ -217,8 +216,8 @@ if(TOGGLE_FRAMEWORK_SOUND) find_package(OpenAL CONFIG REQUIRED) endif() find_package(VorbisFile REQUIRED) - find_package(Vorbis REQUIRED) - find_package(Ogg REQUIRED) + find_package(Vorbis CONFIG REQUIRED) + find_package(Ogg CONFIG REQUIRED) endif() if(ANDROID) set(LUA_LIBRARY ${LUA_LIBRARY} ${Android_LIBRARIES}/liblua.a) @@ -609,6 +608,9 @@ elseif(WASM) OpenSSL::Crypto httplib::httplib fmt::fmt + Ogg::ogg + Vorbis::vorbisfile + Vorbis::vorbis ) @@ -689,6 +691,9 @@ else() # Linux OpenSSL::Crypto httplib::httplib fmt::fmt-header-only + Ogg::ogg + Vorbis::vorbisfile + Vorbis::vorbis ) if(CMAKE_BUILD_TYPE STREQUAL "Debug") diff --git a/vc17/otclient.vcxproj b/vc17/otclient.vcxproj index 7733f93089..cf67249e49 100644 --- a/vc17/otclient.vcxproj +++ b/vc17/otclient.vcxproj @@ -169,7 +169,13 @@ ProgramDatabase Disabled StreamingSIMDExtensions2 - $(VcpkgRoot)\installed\$(VcpkgTriplet)\include\luajit;generated;%(AdditionalIncludeDirectories) + + $(VcpkgRoot)\installed\$(VcpkgTriplet)\include\luajit; + $(GITHUB_WORKSPACE)\vcpkg\installed\$(VcpkgTriplet)\include\; + generated; + %(AdditionalIncludeDirectories) + + /utf-8 %(AdditionalOptions) stdcpp20 4244;4251;4996;%(DisableSpecificWarnings) true @@ -188,7 +194,13 @@ ProgramDatabase Disabled AdvancedVectorExtensions - $(VcpkgRoot)\installed\$(VcpkgTriplet)\include\luajit;generated;%(AdditionalIncludeDirectories) + + $(VcpkgRoot)\installed\$(VcpkgTriplet)\include\luajit; + $(GITHUB_WORKSPACE)\vcpkg\installed\$(VcpkgTriplet)\include\; + generated; + %(AdditionalIncludeDirectories) + + /utf-8 %(AdditionalOptions) stdcpp20 4244;4251;4996;%(DisableSpecificWarnings) true @@ -207,7 +219,13 @@ MaxSpeed true true - $(VcpkgRoot)\installed\$(VcpkgTriplet)\include\luajit;generated;%(AdditionalIncludeDirectories) + + $(VcpkgRoot)\installed\$(VcpkgTriplet)\include\luajit; + $(GITHUB_WORKSPACE)\vcpkg\installed\$(VcpkgTriplet)\include\; + generated; + %(AdditionalIncludeDirectories) + + /utf-8 %(AdditionalOptions) stdcpp20 Default 4244;4251;4996;%(DisableSpecificWarnings) @@ -231,7 +249,13 @@ MaxSpeed true true - $(VcpkgRoot)\installed\$(VcpkgTriplet)\include\luajit;generated;%(AdditionalIncludeDirectories) + + $(VcpkgRoot)\installed\$(VcpkgTriplet)\include\luajit; + $(GITHUB_WORKSPACE)\vcpkg\installed\$(VcpkgTriplet)\include\; + generated; + %(AdditionalIncludeDirectories) + + /utf-8 %(AdditionalOptions) stdcpp20 Default 4244;4251;4996;%(DisableSpecificWarnings) @@ -256,7 +280,13 @@ MaxSpeed true true - $(VcpkgRoot)\installed\$(VcpkgTriplet)\include\luajit;generated;%(AdditionalIncludeDirectories) + + $(VcpkgRoot)\installed\$(VcpkgTriplet)\include\luajit; + $(GITHUB_WORKSPACE)\vcpkg\installed\$(VcpkgTriplet)\include\; + generated; + %(AdditionalIncludeDirectories) + + /utf-8 %(AdditionalOptions) stdcpp20 Default 4244;4251;4996;4267;%(DisableSpecificWarnings) @@ -279,7 +309,13 @@ MaxSpeed true true - $(VcpkgRoot)\installed\$(VcpkgTriplet)\include\luajit;generated;%(AdditionalIncludeDirectories) + + $(VcpkgRoot)\installed\$(VcpkgTriplet)\include\luajit; + $(GITHUB_WORKSPACE)\vcpkg\installed\$(VcpkgTriplet)\include\; + generated; + %(AdditionalIncludeDirectories) + + /utf-8 %(AdditionalOptions) stdcpp20 Default 4244;4251;4996;4267;%(DisableSpecificWarnings) @@ -640,15 +676,21 @@ + + + true false + + + $(ProjectDir)vcpkg_installed\$(VcpkgTriplet)\tools\protobuf\protoc - $(SourcePath)protobuf + ..\$(SourcePath)\protobuf $(ProjectDir)vcpkg_installed\$(VcpkgTriplet)\tools\protobuf\protoc @@ -658,8 +700,7 @@ - - + false @@ -673,5 +714,6 @@ + \ No newline at end of file