Flatpak

From Free Pascal wiki
Jump to navigationJump to search

Instructions

  • Assume an application called App with Flatpak ID: com.domain.App
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
  <id>com.domain.App</id>

  <name>App</name>
  <summary>Example application</summary>
  <developer id="org.example">
    <name>Developer name</name>
  </developer>

  <url type="homepage">https://domain.com/App/</url>

  <metadata_license>CC0-1.0</metadata_license>
  <project_license>CC0-1.0</project_license>

  <description>
    <p>
      A description of the App.
    </p>
  </description>

  <launchable type="desktop-id">com.domain.App.desktop</launchable>

  <branding>
    <color type="primary" scheme_preference="light">#ff00ff</color>
    <color type="primary" scheme_preference="dark">#993d3d</color>
  </branding>

  <screenshots>
    <screenshot type="default">
      <caption>Main screenshot</caption>
      <image>https://domain.com/Screenshot.jpg</image>
    </screenshot>
    <screenshot>
      <caption>Another screenshot</caption>
      <image>https://domain.com/Screenshot2.jpg</image>
    </screenshot>
  </screenshots>

  <releases>
    <release version="1.0.0" date="2024-01-01">
      <url type="details">https://domain.com/Release_notes.txt</url>
      <description>
        <ul>
          <li>Added new.</li>
          <li>Changed existing.</li>
          <li>Fixed bug.</li>
        </ul>
      </description>
    </release>
  </releases>

  <categories>
    <category>Games</category>
  </categories>

  <content_rating type="oars-1.1"/>
</component>
  • Create a file named com.domain.App.yml:
app-id: com.domain.App
runtime: org.kde.Platform
runtime-version: '5.15-24.08'
sdk: org.kde.Sdk
sdk-extensions:
  - org.freedesktop.Sdk.Extension.freepascal
command: App
finish-args:
  - --share=ipc
  - --socket=fallback-x11
  - --socket=wayland
  - --device=dri
modules:
  - name: qt5pas
    buildsystem: qmake
    config-opts:
      - -after
      - target.path=/app/lib
    sources:
      - type: shell
        commands:
          - cp -r /usr/lib/sdk/freepascal/share/lazarus/lcl/interfaces/qt5/cbindings/. .
  - name: App
    sources:
      - type: svn
        url: https://domain.com/App/trunk
        revision: r1
    buildsystem: simple
    build-commands:
      - |
        . /usr/lib/sdk/freepascal/enable.sh
        lazbuild --build-mode=Release --ws=qt5 App.lpi
      - install -Dm755 App -t $FLATPAK_DEST/share/App
      - install -d $FLATPAK_DEST/bin
      - ln -s $FLATPAK_DEST/share/App/App $FLATPAK_DEST/bin/App
      - install -Dm644 ${FLATPAK_ID}.desktop -t $FLATPAK_DEST/share/applications
      - install -Dm644 App.png $FLATPAK_DEST/share/icons/hicolor/256x256/apps/${FLATPAK_ID}.png
      - install -Dm644 ${FLATPAK_ID}.metainfo.xml $FLATPAK_DEST/share/metainfo/${FLATPAK_ID}.metainfo.xml
  • Create a file com.domain.App.desktop:
[Desktop Entry]
Encoding=UTF-8
Name=App
Comment=Example application
Exec=App
Icon=com.domain.App.png
Terminal=false
Type=Game
Categories=Game
StartupNotify=true
MimeType=application/type1;application/type2
Keywords=keyword1;keyword1;keyword3
  • Create a build script named build.sh:
#!/bin/bash

BUILD_DIR=build
REPO_DIR=repo
FLATPAK_ID=com.domain.App

# Install dependencies
flatpak install --system flathub org.kde.Sdk//5.15-24.08
flatpak install --system flathub org.kde.Platform//5.15-24.08
flatpak install --system flathub org.freedesktop.Sdk.Extension.freepascal//24.08
flatpak install --system flathub org.flatpak.Builder

# Build
flatpak run org.flatpak.Builder --force-clean --sandbox --user --install --ccache --mirror-screenshots-url=https://dl.flathub.org/media/ --repo=$REPO_DIR $BUILD_DIR $FLATPAK_ID.yml

# Run
flatpak run $FLATPAK_ID

# Linter
flatpak run --command=flatpak-builder-lint org.flatpak.Builder manifest $FLATPAK_ID.yml
flatpak run --command=flatpak-builder-lint org.flatpak.Builder repo $REPO_DIR
  • Run the build.sh script and test the application.
  • Follow the submission process to submit your app to Flathub.

Gtk2

Flatpak supports both Qt and Gtk toolkits. To use legacy Gtk2 toolkit which is needed to run many Lazarus apps use the following yml file example:

app-id: com.domain.App
runtime: org.freedesktop.Platform
runtime-version: '24.08'
sdk: org.freedesktop.Sdk
sdk-extensions:
  - org.freedesktop.Sdk.Extension.freepascal
command: App
finish-args:
  - --share=ipc
  - --socket=fallback-x11
  - --socket=wayland
  - --device=dri
modules:
  - shared-modules/gtk2/gtk2.json
  - name: App
    sources:
      - type: svn
        url: https://domain.com/App/trunk
        revision: r1
    buildsystem: simple
    build-commands:
      - |
        . /usr/lib/sdk/freepascal/enable.sh
        lazbuild --build-mode=Release --ws=gtk2 App.lpi
      - install -Dm755 App -t $FLATPAK_DEST/share/App
      - install -d $FLATPAK_DEST/bin
      - ln -s $FLATPAK_DEST/share/App/App $FLATPAK_DEST/bin/App
      - install -Dm644 ${FLATPAK_ID}.desktop -t $FLATPAK_DEST/share/applications
      - install -Dm644 App.png $FLATPAK_DEST/share/icons/hicolor/256x256/apps/${FLATPAK_ID}.png
      - install -Dm644 ${FLATPAK_ID}.metainfo.xml $FLATPAK_DEST/share/metainfo/${FLATPAK_ID}.metainfo.xml
git submodule add https://github.com/flathub/shared-modules.git
  • On Flathub page the app built with Gtk2 will be marked as "Legacy windowing system - Uses a legacy windowing system".

Debugging

Normally flatpak-builder removes debug symbols from the executable and moves them to the extra $FLATPAK_ID.Debug package. If you want to build your application with debug symbols you need to add the following option to your yml file:

build-options:
    no-debuginfo: true

and rebuild your project with debug build mode if defined:

lazbuild --build-mode=Debug --ws=qt5 App.lpi

To run installed flatpak in shell mode use:

flatpak run --command=sh --devel com.domain.App

Run the app:

/app/bin/App

See also Flatpak Debugging

See also

External links