sdk-extensions:
  #- org.freedesktop.Sdk.Extension.dotnet6   # Needed for Ryujinx - Removed, check if it's not breaking something else
  finish-args:
  #- --env=QT_QPA_PLATFORM=xcb #not sure if this will break something
  
  # pcsx2-qt needs QT6, maybe others, here until every qt emulator will support qt6 (not yuzu atm)
  # from: https://github.com/flathub/org.profex_xrd.Profex

  # - name: qt6-core5compat
  #   buildsystem: cmake-ninja
  #   builddir: true
  #   sources:
  #     - type: archive
  #       url: https://download.qt.io/official_releases/qt/6.2/6.2.4/submodules/qt5compat-everywhere-src-6.2.4.tar.xz
  #       sha256: 5de2b9e25bf7de161fbb88ecdd468ed1788bc899392fc05ed80aa590ebb352fa
  #       x-checker-data:
  #         type: html
  #         url: https://download.qt.io/official_releases/qt/6.2/
  #         version-pattern: '>([\d\.-]*)/<'
  #         url-template: https://download.qt.io/official_releases/qt/6.2/$version/submodules/qt5compat-everywhere-src-$version.tar.xz
  #   post-install:
  #     - mkdir -p /app/lib/mkspecs
  #     - cp -R /app/mkspecs/* /app/lib/mkspecs/
  #     - ln -fsr ${FLATPAK_DEST}/lib/${FLATPAK_ARCH}-linux-gnu/libQt*.so* -t ${FLATPAK_DEST}/lib/
  #     - sed -i 's/\\([0-9]\\+\\.[0-9]\\+\\)\\.[0-9]\\+ ${_Qt6.*_FIND_VERSION_EXACT}/\\1/'
  #       ${FLATPAK_DEST}/lib/${FLATPAK_ARCH}-linux-gnu/cmake/Qt6*/Qt6*Config.cmake
  #     - sed -e 's@PATHS \"${CMAKE_CURRENT_LIST_DIR}/..\" NO_DEFAULT_PATH@PATHS \"${CMAKE_CURRENT_LIST_DIR}/..\"
  #       \"/usr/lib/${CMAKE_CXX_LIBRARY_ARCHITECTURE}/cmake/\" NO_DEFAULT_PATH@' -i
  #       ${FLATPAK_DEST}/lib/${FLATPAK_ARCH}-linux-gnu/cmake/Qt6*/Qt6*Config.cmake
  #     - sed -e 's@\\($$QT_MODULE_BIN_BASE\\)@\\1 '${FLATPAK_DEST}'/bin @' -i ${FLATPAK_DEST}/lib/mkspecs/modules/*.pri
  #     - sed -e 's@\\($$QT_MODULE_INCLUDE_BASE \\)@\\1'${FLATPAK_DEST}'/include @'
  #       -i ${FLATPAK_DEST}/lib/mkspecs/modules/*.pri
  #     - sed -e 's@$$QT_MODULE_INCLUDE_BASE/@'${FLATPAK_DEST}'/include/@g' -i ${FLATPAK_DEST}/lib/mkspecs/modules/*.pri
  #     - sed -e 's@$$QT_MODULE_LIB_BASE@'${FLATPAK_DEST}'/lib@g' -i ${FLATPAK_DEST}/lib/mkspecs/modules/*.pri
  #   cleanup:
  #     - /app/mkspecs

  # XEMU: libglu removed due to a certificate issue, check libglu module for more info
  # - name: libglu
  #   buildsystem: meson
  #   cleanup:
  #     - /include
  #     - /lib/debug
  #     - /lib/pkgconfig
  #     - /lib/*.a
  #   sources:
  #     - type: archive
  #       url: http://mesa.freedesktop.org/archive/glu/glu-9.0.2.tar.xz
  #       sha256: 6e7280ff585c6a1d9dfcdf2fca489251634b3377bfc33c29e4002466a38d02d4
  #       x-checker-data:
  #         type: anitya
  #         project-id: 13518
  #         stable-only: true
  #         url-template: http://mesa.freedesktop.org/archive/glu/glu-$version.tar.xz

    # Duckstation - START
  # https://github.com/flathub/org.duckstation.DuckStation
  # Disabled until we completely switch to QT6

  # - name: duckstation
  #   buildsystem: cmake-ninja
  #   no-make-install: true
  #   builddir: true
  #   config-opts:
  #     - -DCMAKE_BUILD_TYPE=RelWithDebInfo
  #     - -DUSE_EGL=ON
  #     - -DUSE_SDL2=ON
  #     - -DUSE_WAYLAND=ON
  #     - -DUSE_X11=ON
  #     - -DUSE_DRMKMS=ON
  #     - -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON
  #   post-install:
  #     - install -m755 bin/duckstation-qt /app/bin
  #     - cp -r ../data/* bin/translations /app/bin
  #   sources:
  #     - type: git
  #       url: https://github.com/stenzek/duckstation.git
  #       commit: 6f709468601183083b8581d4952aaba7baf77084
  #       # Cloning dep/msvc/qt is only necessary for Windows
  #       disable-submodules: true

  # Duckstation - END

  # Duckstation-DontUpdate - START
  # Old version moved to QT6 so it's either this or AppImage
  # But AppImage is a single one that keep getting updated at the same link so the sha (that's mandatory) will break the build
  # So yeah we're stuck with this for a while

  # - name: duckstation-DontUpdate
  #   buildsystem: cmake-ninja
  #   no-make-install: true
  #   builddir: true
  #   config-opts:
  #     - -DCMAKE_BUILD_TYPE=Release
  #     - -DUSE_EGL=ON
  #     - -DUSE_SDL2=ON
  #     - -DUSE_WAYLAND=ON
  #     - -DUSE_X11=ON
  #     - -DUSE_DRMKMS=ON
  #     - -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON
  #   post-install:
  #     - install -m 755 -t /app/bin/ bin/duckstation-nogui bin/duckstation-qt
  #     - |-
  #       for px in 16 32 48 64 128 256; do
  #         install -Dm644 ../extras/icons/icon-${px}px.png /app/share/icons/hicolor/${px}x${px}/apps/org.duckstation.DuckStation.png
  #       done
  #     - cp -r ../data/* bin/translations /app/bin
  #   sources:
  #     - type: git
  #       url: https://github.com/stenzek/duckstation.git
  #       commit: 3fb61865e505ba639609fbf16cb8bdf5c66e020c

  # Duckstation-DontUpdate - END

  # Ryujinx - START
  # https://github.com/flathub/org.ryujinx.Ryujinx

  - name: Ryujinx
    buildsystem: simple
    build-options:
      no-debuginfo: true
      no-debuginfo-compression: true
      strip: false
      arch:
        x86_64:
          env:
            RUNTIME: linux-x64
      env:
        PKG_CONFIG_PATH: /app/lib/pkgconfig:/app/share/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig
        DOTNET_CLI_TELEMETRY_OPTOUT: 'true'
        DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 'true'
        RYUJINX_VERSION: 1.1.1014
        RYUJINX_TARGET_RELEASE_CHANNEL_OWNER: flathub
        RYUJINX_TARGET_RELEASE_CHANNEL_REPO: org.ryujinx.Ryujinx
        RYUJINX_TARGET_RELEASE_CHANNEL_NAME: master
    build-commands:
    - |
      export PATH=$PATH:/run/build/Ryujinx/dotnet-sdk
      export RYUJINX_GIT_SHORT_HASH=$(git rev-parse --short HEAD)
      export RUNTIME_FRAMEWORK_VERSION=$(find nuget-sources -name 'microsoft.netcore.app.host.linux-x64.*' | grep -oP '(\d.\d.\d+.nupkg)' | grep -oP '(\d.\d.\d+)')
      sed -r --in-place "s/\%\%RYUJINX_BUILD_VERSION\%\%/$RYUJINX_VERSION/g;" src/Ryujinx.Common/ReleaseInformation.cs
      sed -r --in-place "s/\%\%RYUJINX_BUILD_GIT_HASH\%\%/$RYUJINX_GIT_SHORT_HASH/g;" src/Ryujinx.Common/ReleaseInformation.cs
      sed -r --in-place "s/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_NAME\%\%/$RYUJINX_TARGET_RELEASE_CHANNEL_NAME/g;" src/Ryujinx.Common/ReleaseInformation.cs
      sed -r --in-place "s/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_OWNER\%\%/$RYUJINX_TARGET_RELEASE_CHANNEL_OWNER/g;" src/Ryujinx.Common/ReleaseInformation.cs
      sed -r --in-place "s/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_REPO\%\%/$RYUJINX_TARGET_RELEASE_CHANNEL_REPO/g;" src/Ryujinx.Common/ReleaseInformation.cs
      mkdir -p /app/bin
      dotnet publish -c Release -r $RUNTIME /p:DebugType=embedded src/Ryujinx /p:Version=$RYUJINX_VERSION /p:SourceRevisionId=$RYUJINX_GIT_SHORT_HASH /p:ExtraDefineConstants="DISABLE_UPDATER%2CFORCE_EXTERNAL_BASE_DIR" /p:RuntimeFrameworkVersion=$RUNTIME_FRAMEWORK_VERSION --self-contained --source nuget-sources
      if [ $? -ne 0 ]; then
          exit 1;
      fi;
      cp -r --remove-destination /run/build/Ryujinx/src/Ryujinx/bin/Release/net7.0/$RUNTIME/publish/* /app/bin/
      chmod +x /app/bin/Ryujinx.sh
      mkdir -p /app/lib/ffmpeg
      ln -s /usr/lib/x86_64-linux-gnu/libX11.so.6 /app/lib/libX11.so
      install -Dm755 ryujinx-wrapper /app/bin/ryujinx-wrapper
      install -Dm644 distribution/misc/Logo.svg /app/share/icons/hicolor/scalable/apps/ryujinx.svg
    sources:
    - type: archive
      only-arches:
      - x86_64
      dest: dotnet-sdk
      url: https://dotnetcli.azureedge.net/dotnet/Sdk/7.0.401/dotnet-sdk-7.0.401-linux-x64.tar.gz
      sha256: 4634fa4da7ae4e3dadb83e320a87fb26f0cb12a7ca02bf9f10e6c3c1c91d645c
      x-checker-data:
        type: rotating-url
        url: https://aka.ms/dotnet/7.0/dotnet-sdk-linux-x64.tar.gz
        pattern: https://dotnetcli.azureedge.net/dotnet/Sdk/^([\d\.a-z-]+)$/dotnet-sdk-^([\d\.a-z-]+)$-linux-x64.tar.gz
    - rd-submodules/ryujinx/nuget_sources.json
    - type: git
      url: https://github.com/Ryujinx/Ryujinx.git
      commit: 7ccff037e87f82f3461f3e1422235e29800eaa2f
    - type: file
      path: rd-submodules/ryujinx/ryujinx-wrapper

  # Ryujinx - END