From f0070b6ac4f688931166dbfac57939bf336d9db9 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Thu, 6 Jun 2024 16:18:28 +0700 Subject: [PATCH] building dependencies with vcpkg on Linux (#1724) --- .github/workflows/main.yml | 24 ++-- .github/workflows/packages.yml | 121 ++++++++++++++++++ .github/workflows/win_msvc.yml | 98 -------------- .../triplets/x64-linux-dynamic-release.cmake | 9 ++ vcpkg.json | 32 ++++- 5 files changed, 168 insertions(+), 116 deletions(-) create mode 100644 .github/workflows/packages.yml delete mode 100644 .github/workflows/win_msvc.yml create mode 100644 cmake/triplets/x64-linux-dynamic-release.cmake diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 816950243..c3310e910 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,7 @@ jobs: - name: Linux GCC os: ubuntu-24.04 compiler: gcc - extra-options: -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=OFF + extra-options: -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=OFF shell: bash - name: macOS Clang @@ -109,21 +109,13 @@ jobs: cd build cpack - - name: Upload AppImage - if: runner.os == 'Linux' - uses: actions/upload-artifact@v4 - with: - name: Nugget-Doom-AppImage - path: build/*.appimage - - - name: Extract Version Number - if: ${{ contains(github.ref, 'tags') && runner.os == 'Linux' }} - shell: bash - run: echo "VERSION=${GITHUB_REF##*_}" >> $GITHUB_ENV - - cppcheck: - name: Cppcheck - runs-on: ubuntu-latest + linter: + name: ${{ matrix.name }} + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + name: [Cppcheck , Clang-Tidy] steps: - name: Install dependencies diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml new file mode 100644 index 000000000..311255f60 --- /dev/null +++ b/.github/workflows/packages.yml @@ -0,0 +1,121 @@ +name: Build Packages + +on: + push: + branches: [ master ] + tags: ['*'] + paths-ignore: ['**.md'] + pull_request: + branches: [ master ] + paths-ignore: ['**.md'] + workflow_dispatch: + +env: + VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" + +jobs: + build: + name: ${{ matrix.config.name }} + runs-on: ${{ matrix.config.os }} + + strategy: + matrix: + config: + - name: Linux GCC + os: ubuntu-22.04 + triplet: x64-linux-dynamic-release + artifact-name: AppImage + artifact-path: build/*.appimage + + - name: MSVC x64 + os: windows-latest + arch: x64 + triplet: x64-windows-static-release + artifact-name: Win-64 + artifact-path: build/*.zip + + - name: MSVC x86 + os: windows-latest + arch: x86 + triplet: x86-windows-static-release + artifact-name: Win-32 + artifact-path: build/*.zip + + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies (Linux) + if: runner.os == 'Linux' + run: | + sudo sed -i 's/# deb-src/deb-src/' /etc/apt/sources.list + sudo apt-get update + sudo apt-get install ninja-build + sudo apt-get build-dep libsdl2-dev + + - name: Developer Command Prompt + if: runner.os == 'Windows' + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: ${{ matrix.config.arch }} + + - name: Export GitHub Actions cache environment variables + uses: actions/github-script@v7 + with: + script: | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + + - name: Configure (Linux) + if: runner.os == 'Linux' + shell: bash + run: | + cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DENABLE_WERROR=ON -DENABLE_HARDENING=ON -DENABLE_LTO=ON \ + -DCMAKE_TOOLCHAIN_FILE="$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" \ + -DVCPKG_OVERLAY_TRIPLETS="cmake/triplets" \ + -DVCPKG_TARGET_TRIPLET=${{ matrix.config.triplet }} \ + -DCMAKE_INSTALL_PREFIX=/usr + + - name: Configure (Windows) + if: runner.os == 'Windows' + run: | + cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release ` + -DENABLE_WERROR=ON -DENABLE_LTO=ON ` + -DCMAKE_TOOLCHAIN_FILE="${env:VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake" ` + -DVCPKG_OVERLAY_TRIPLETS="cmake/triplets" ` + -DVCPKG_TARGET_TRIPLET=${{ matrix.config.triplet }} ` + -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded ` + -DCMAKE_IGNORE_PATH="C:/Strawberry/perl/bin;C:/Strawberry/c/lib" + + - name: Build + run: cmake --build build --config "Release" + + - name: Test + if: github.event_name == 'workflow_dispatch' + run: | + cd demotest + pip install pyyaml joblib + python demotest --jobs 4 --port ../build/src/woof + + - name: Package (Linux) + if: runner.os == 'Linux' + run: | + export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${{ github.workspace }}/build/vcpkg_installed/${{ matrix.config.triplet }}/lib" + cd build + cpack + + - name: Package (Windows) + if: runner.os == 'Windows' + run: | + cd build + cpack + + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.config.artifact-name }} + path: ${{ matrix.config.artifact-path }} + + - name: Extract Version Number + shell: bash + run: echo "VERSION=${GITHUB_REF##*_}" >> $GITHUB_ENV diff --git a/.github/workflows/win_msvc.yml b/.github/workflows/win_msvc.yml deleted file mode 100644 index 650bbb137..000000000 --- a/.github/workflows/win_msvc.yml +++ /dev/null @@ -1,98 +0,0 @@ -name: Continuous Integration (MSVC) - -on: - push: - branches: [ master ] - tags: ['*'] - paths-ignore: ['**.md'] - pull_request: - branches: [ master ] - paths-ignore: ['**.md'] - workflow_dispatch: - -env: - VCPKG_DIR: C:\vcpkg - VCPKG_BINARY_SOURCES: "clear;nuget,GitHub,readwrite" - -jobs: - build: - if: ${{ github.repository == 'MrAlaux/Nugget-Doom' }} - name: MSVC ${{ matrix.config.arch }} - runs-on: windows-latest - - strategy: - matrix: - config: - - name: x64 - arch: x64 - - - name: Win32 - arch: x86 - - steps: - - uses: actions/checkout@v4 - - - name: Latest CMake and Ninja - uses: lukka/get-cmake@latest - - - name: Developer Command Prompt - uses: ilammy/msvc-dev-cmd@v1 - with: - # The version of the toolset is specified due to faulty version discovery. - toolset: 14.39 - arch: ${{ matrix.config.arch }} - - - name: Setup vcpkg and NuGet - shell: bash - run: | - set -euo pipefail - - cd "${{ env.VCPKG_DIR }}" - - NUGET=$(vcpkg fetch nuget | tail -n 1) - GH_PACKAGES_URL="https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" - - "$NUGET" sources add \ - -source "$GH_PACKAGES_URL" \ - -storepasswordincleartext \ - -name "GitHub" \ - -username "${{ github.repository_owner }}" \ - -password "${{ secrets.GITHUB_TOKEN }}" - - "$NUGET" setapikey "${{ secrets.GITHUB_TOKEN }}" \ - -source "$GH_PACKAGES_URL" - - - name: Configure - run: | - cmake -B build -G Ninja ` - -DCMAKE_BUILD_TYPE=Release -DENABLE_WERROR=ON -DENABLE_LTO=ON ` - -DCMAKE_TOOLCHAIN_FILE="${{ env.VCPKG_DIR }}/scripts/buildsystems/vcpkg.cmake" ` - -DVCPKG_TARGET_TRIPLET="${{ matrix.config.arch }}-windows-static-release" ` - -DVCPKG_OVERLAY_TRIPLETS="cmake/triplets" ` - -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded ` - -DCMAKE_IGNORE_PATH="C:/Strawberry/perl/bin;C:/Strawberry/c/lib" - - - name: Build - run: cmake --build build --config "Release" - - - name: Test - if: github.event_name == 'workflow_dispatch' - run: | - cd demotest - pip install pyyaml joblib - python demotest --jobs 4 --port ../build/src/nugget-doom - - - name: Package - run: | - cd build - cpack - - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: Win-${{ matrix.config.arch }} - path: build/*.zip - - - name: Extract Version Number - shell: bash - run: echo "VERSION=${GITHUB_REF##*_}" >> $GITHUB_ENV diff --git a/cmake/triplets/x64-linux-dynamic-release.cmake b/cmake/triplets/x64-linux-dynamic-release.cmake new file mode 100644 index 000000000..f1c43bdb3 --- /dev/null +++ b/cmake/triplets/x64-linux-dynamic-release.cmake @@ -0,0 +1,9 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE dynamic) + +set(VCPKG_CMAKE_SYSTEM_NAME Linux) + +set(VCPKG_FIXUP_ELF_RPATH ON) + +set(VCPKG_BUILD_TYPE release) diff --git a/vcpkg.json b/vcpkg.json index 1b1a0f837..13ef1397f 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,9 +1,37 @@ { "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "dependencies": [ - "sdl2", + { + "name": "sdl2", + "features": [ + { + "name": "vulkan", + "platform": "linux" + }, + { + "name": "wayland", + "platform": "linux" + }, + { + "name": "x11", + "platform": "linux" + }, + { + "name": "ibus", + "platform": "linux" + } + ] + }, "sdl2-net", - "openal-soft", + { + "name": "openal-soft", + "features": [ + { + "name": "pipewire", + "platform": "linux" + } + ] + }, "libsndfile", { "name": "fluidsynth",