Flatpak

From Lazarus wiki
Jump to navigationJump to search

Instructions

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

  <name>App</name>
  <summary>Example application</summary>
  <developer_name>Developer</developer_name>

  <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>

  <screenshots>
    <screenshot type="default">
      <caption>Game interface and world map</caption>
      <image>https://github.com/flathub/com.domain.App/raw/master/Screenshots/Main.jpg</image>
    </screenshot>
    <screenshot>
      <caption>Main menu</caption>
      <image>https://github.com/flathub/com.domain.App/raw/master/screenshots/Another.jpg</image>
    </screenshot>
  </screenshots>

  <releases>
    <release version="1.0.0" date="2024-01-01"/>
  </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-23.08'
sdk: org.kde.Sdk
sdk-extensions:
  - org.freedesktop.Sdk.Extension.freepascal
command: c-evo
finish-args:
  - --share=ipc
  - --socket=fallback-x11
  - --socket=wayland
  - --filesystem=home
  - --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 -d -m 755 $FLATPAK_DEST/share/App
      - install -s -m 755 App $FLATPAK_DEST/share/App
      - install -d -m 755 $FLATPAK_DEST/bin
      - ln -s $FLATPAK_DEST/share/App/App $FLATPAK_DEST/bin/App
      - install -d -m 755 $FLATPAK_DEST/share/applications
      - install -m 755 Install/flatpak/${FLATPAK_ID}.desktop $FLATPAK_DEST/share/applications
      - install -d -m 755 $FLATPAK_DEST/share/icons/hicolor/64x64/apps
      - install -m 644 App.png $FLATPAK_DEST/share/icons/hicolor/64x64/apps/${FLATPAK_ID}.png
      - install -D Install/flatpak/com.domain.App.appdata.xml -t $FLATPAK_DEST/share/metainfo/com.domain.App.metainfo.xml
  • Create a build script named build.sh
#!/bin/bash

FLATPAK_ID=com.domain.App
BUILD_DIR=build
EXPORT_DIR=export

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

# Build
flatpak-builder --force-clean $BUILD_DIR $FLATPAK_ID.yml

# Optionally build a bundle
flatpak build-export $EXPORT_DIR $BUILD_DIR
flatpak build-bundle $EXPORT_DIR App.flatpak $FLATPAK_ID

# Install
flatpak-builder --user --install --force-clean $BUILD_DIR $FLATPAK_ID.yml

# Run
flatpak run $FLATPAK_ID

Notes

Flathub offers a very limited number of "platforms" that your application needs to fit into. It does not offer a GTK2 one but does have a QT5 one. However that platform does not contain all the libraries normally found on a Qt5 system so expect to have to bundle libraries into your Flatpack if your application makes use of other libraries.

Does not sound like a very FPC/Lazarus (as it stands now) friendly environment but there are some of "our" applications there.

See also

External links