Difference between revisions of "Create snap package"

From Lazarus wiki
Jump to navigationJump to search
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
=Create snapcraft.yaml=
 
=Create snapcraft.yaml=
* Install snapcraft to your Ubuntu machine with '''sudo apt install snapcraft'''
+
* Install snapcraft to your Ubuntu machine with <code>sudo apt install snapcraft</code>
 
* Create '''snap''' subdirectory in your project
 
* Create '''snap''' subdirectory in your project
* Execute '''snapcraft init''' to create '''snap/snapcraft.yaml''' initial file
+
* Execute <code>snapcraft init</code> to create '''snap/snapcraft.yaml''' initial file
 
* Example file:
 
* Example file:
 
<pre>
 
<pre>
Line 59: Line 59:
 
     override-build: |
 
     override-build: |
 
       lazbuild --build-mode=Release myapp.lpi
 
       lazbuild --build-mode=Release myapp.lpi
       install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/myapp
+
       install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/bin
       install -s -m 755 myapp $SNAPCRAFT_PART_INSTALL/usr/share/myapp
+
       install -s -m 755 myapp $SNAPCRAFT_PART_INSTALL/usr/bin/myapp
 
       install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/applications
 
       install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/applications
       install -m 755 Install/deb/myapp.desktop $SNAPCRAFT_PART_INSTALL/usr/share/applications
+
       install -m 755 myapp.desktop $SNAPCRAFT_PART_INSTALL/usr/share/applications
 
     stage:
 
     stage:
      - etc
+
    - etc
      - lib
+
    - lib
      - usr
+
    - usr
      - usr/share/myapp
+
    - usr/bin
      - usr/share/applications/myapp.desktop
+
    - usr/share/myapp
 +
    - usr/share/applications/myapp.desktop
  
 
apps:
 
apps:
 
   myapp:
 
   myapp:
     command: usr/share/myapp/myapp
+
     command: usr/bin/myapp/myapp
 
     desktop: usr/share/applications/myapp.desktop
 
     desktop: usr/share/applications/myapp.desktop
 
     plugs:
 
     plugs:
      - home
+
    - home
      - desktop
+
    - desktop
      - x11
+
    - x11
 
</pre>
 
</pre>
 
:* See [https://snapcraft.io/docs/snapcraft-yaml-reference Snapcraft.yaml reference] for full list of supported properties.
 
:* See [https://snapcraft.io/docs/snapcraft-yaml-reference Snapcraft.yaml reference] for full list of supported properties.
Line 83: Line 84:
 
:* [https://github.com/search?q=filename%3Asnapcraft.yaml+%22lazbuild%22&amp;type=Code Sample snapcraft.yaml files using lazbuild on Github]
 
:* [https://github.com/search?q=filename%3Asnapcraft.yaml+%22lazbuild%22&amp;type=Code Sample snapcraft.yaml files using lazbuild on Github]
 
* Build snap using '''snapcraft''' command
 
* Build snap using '''snapcraft''' command
* Install newly created snap with '''sudo snap install --dangerous myapp_1.0.0_amd64.snap'''
+
* Install newly created snap with <code>sudo snap install --dangerous myapp_1.0.0_amd64.snap</code>
  
 
=Publish your package in Snap Store=
 
=Publish your package in Snap Store=
* <pre>snapcraft register</pre>
+
<pre>
* <pre>snapcraft login</pre>
+
snapcraft register
* <pre>snapcraft upload myapp.snap</pre>
+
snapcraft login
* <pre>snapcraft release myapp 1 stable</pre>
+
snapcraft upload myapp.snap
* Now your snap should be released and available on snapcraft.io store.
+
snapcraft release myapp 1 stable
 +
</pre>
 +
 
 +
Now your snap should be released and available on '''snapcraft.io''' store.
  
 
=Debug snap=
 
=Debug snap=
Line 114: Line 118:
 
     - libgtk2.0-dev
 
     - libgtk2.0-dev
 
     override-build: |
 
     override-build: |
       wget -nc https://deac-ams.dl.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.0.12/lazarus-project_2.0.12-0_amd64.deb
+
       wget -nc https://deac-ams.dl.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.2.0/lazarus-project_2.2.0-0_amd64.deb
       wget -nc https://netix.dl.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.0.12/fpc-laz_3.2.0-1_amd64.deb
+
       wget -nc https://netix.dl.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.2.0/fpc-laz_3.2.2-210709_amd64.deb
       wget -nc https://netix.dl.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.0.12/fpc-src_3.2.0-1_amd64.deb
+
       wget -nc https://netix.dl.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.2.0/fpc-src_3.2.2-210709_amd64.deb
       apt install ./lazarus-project_2.0.12-0_amd64.deb ./fpc-laz_3.2.0-1_amd64.deb ./fpc-src_3.2.0-1_amd64.deb
+
       apt install ./lazarus-project_2.2.0-0_amd64.deb ./fpc-laz_3.2.2-210709_amd64.deb ./fpc-src_3.2.2-210709_amd64.deb
 
     prime: [-*]
 
     prime: [-*]
 
   myapp:
 
   myapp:
 
     after: [lazarus]
 
     after: [lazarus]
 +
</pre>
 +
 +
And remove normal Lazarus build-packages from your app so they are not installed for build:
 +
<pre>
 +
  myapp
 +
    build-packages:
 +
    - fpc
 +
    - lazarus
 +
    - lcl
 +
    - lcl-utils
 +
</pre>
 +
 +
=GTK2 theme support=
 +
 +
There is no snapcraft extension available for GTK2 similarly to GTK3. So GTK2 theming needs to be configured with additional lines.
 +
 +
==Content plugs only==
 +
 +
To support GTK2 themes used by host system the app needs to have access to GTK2 themes. Standard GTK2 themes can be made available by using content plugs. Those content plugs are external shared packages so they won't make snap bigger. But the application can still print some errors into console.
 +
 +
Extend your snapcraft.yaml file with the following:
 +
<pre>
 +
# Additional plugs to pick up the GTK theme and icons from the system
 +
plugs:
 +
  icon-themes:
 +
    interface: content
 +
    target: $SNAP/data-dir/icons
 +
    default-provider: gtk-common-themes
 +
  sound-themes:
 +
    interface: content
 +
    target: $SNAP/data-dir/sounds
 +
    default-provider: gtk-common-themes
 +
  gtk-2-engines:
 +
    interface: content
 +
    target: $SNAP/lib/gtk-2.0
 +
    default-provider: gtk2-common-themes:gtk-2-engines
 +
  gtk-2-themes:
 +
    interface: content
 +
    target: $SNAP/usr/share/themes
 +
    default-provider: gtk2-common-themes:gtk-2-themes
 +
 +
layout:
 +
  /usr/share/themes:
 +
    bind: $SNAP/usr/share/themes
 +
  /usr/lib/$SNAPCRAFT_ARCH_TRIPLET/gtk-2.0:
 +
    bind: $SNAP/lib/gtk-2.0
 +
</pre>
 +
 +
==Full support==
 +
 +
To fully support GTK2 environment we need to use snapcraft desktop helper and include various standard packages. Those packages make snap bigger by ~26 MB so there is a trade-off between size of snap packages and supported features.
 +
 +
Extend your snapcraft.yaml file with the following:
 +
<pre>
 +
parts:
 +
  desktop-gtk2:
 +
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
 +
    source-subdir: gtk
 +
    plugin: make
 +
    make-parameters: ["FLAVOR=gtk2"]
 +
    build-packages:
 +
    - build-essential
 +
    - libgtk2.0-dev
 +
    stage-packages:
 +
    - libxkbcommon0  # XKB_CONFIG_ROOT
 +
    - ttf-ubuntu-font-family
 +
    - dmz-cursor-theme
 +
    - light-themes
 +
    - adwaita-icon-theme
 +
    - gnome-themes-standard
 +
    - shared-mime-info
 +
    - libgtk2.0-0
 +
    - libgdk-pixbuf2.0-0
 +
    - libglib2.0-bin
 +
    - libgtk2.0-bin
 +
    - unity-gtk2-module
 +
    - locales-all
 +
    - libappindicator1
 +
    - xdg-user-dirs
 +
    - ibus-gtk
 +
    - libibus-1.0-5
 +
  myapp:
 +
    after:
 +
    - desktop-gtk2
 +
 +
# Additional plugs to pick up the GTK theme and icons from the system
 +
plugs:
 +
  icon-themes:
 +
    interface: content
 +
    target: $SNAP/data-dir/icons
 +
    default-provider: gtk-common-themes
 +
  sound-themes:
 +
    interface: content
 +
    target: $SNAP/data-dir/sounds
 +
    default-provider: gtk-common-themes
 +
  gtk-2-engines:
 +
    interface: content
 +
    target: $SNAP/lib/gtk-2.0
 +
    default-provider: gtk2-common-themes:gtk-2-engines
 +
  gtk-2-themes:
 +
    interface: content
 +
    target: $SNAP/usr/share/themes
 +
    default-provider: gtk2-common-themes:gtk-2-themes
 +
 +
environment:
 +
  XDG_DATA_DIRS: $SNAP/usr/share:$XDG_DATA_DIRS
 +
  GTK_PATH: $SNAP/lib/gtk-2.0
 +
 +
apps:
 +
  myapp:
 +
    command: usr/bin/myapp
 +
    command-chain:
 +
    - bin/desktop-launch
 +
 
</pre>
 
</pre>
  
Line 129: Line 247:
 
   myapp:
 
   myapp:
 
     plugs:
 
     plugs:
      - audio-playback
+
    - audio-playback
 
</pre>
 
</pre>
  
Line 149: Line 267:
 
   /usr/lib/$SNAPCRAFT_ARCH_TRIPLET/sox:
 
   /usr/lib/$SNAPCRAFT_ARCH_TRIPLET/sox:
 
     bind: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/sox
 
     bind: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/sox
 +
</pre>
 +
 +
=OpenGL support=
 +
 +
To support 3D acceleration it is required to use opengl plug, package related libraries and set correct path for drivers.
 +
<pre>
 +
parts:
 +
  myapp:
 +
    stage-packages:   
 +
    - libglu1-mesa
 +
    - libgl1-mesa-dri
 +
 +
apps:
 +
  myapp:
 +
    plugs:
 +
    - opengl
 +
 +
environment:
 +
  LIBGL_DRIVERS_PATH: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/dri
 +
</pre>
 +
 +
=SDL support=
 +
 +
Add needed build and stage packages.
 +
 +
<pre>
 +
parts:
 +
  myapp:
 +
    build-packages:
 +
    - libsdl2-dev
 +
    - libsdl2-mixer-dev
 +
    - libsdl2-image-dev
 +
    stage-packages:
 +
    - libsdl2-2.0-0
 +
    - libsdl2-image-2.0-0
 +
    - libsdl2-mixer-2.0-0
 
</pre>
 
</pre>
  
Line 172: Line 326:
 
=See also=
 
=See also=
 
* [[Publish project on Launchpad]]
 
* [[Publish project on Launchpad]]
 +
* [[Deploying Your Application]]
  
 
=External links=
 
=External links=

Revision as of 16:31, 17 February 2022

Create snapcraft.yaml

  • Install snapcraft to your Ubuntu machine with sudo apt install snapcraft
  • Create snap subdirectory in your project
  • Execute snapcraft init to create snap/snapcraft.yaml initial file
  • Example file:
name: myapp
version: '1.0.0'
summary: Short description of the package.
description: |
  Some more detailed multi-line description.
confinement: strict
base: core20
grade: stable

parts:
  myapp:
    plugin: nil
    source: .
    source-type: local
    build-packages: 
    - fpc
    - lazarus
    - lcl
    - lcl-utils
    stage-packages:
    # Autodetected dependencies
    - libatk1.0-0
    - libcairo2
    - libdatrie1
    - libfontconfig1
    - libfreetype6
    - libfribidi0
    - libgdk-pixbuf2.0-0
    - libgraphite2-3
    - libgtk2.0-0
    - libharfbuzz0b
    - libpango-1.0-0
    - libpangocairo-1.0-0
    - libpangoft2-1.0-0
    - libpixman-1-0
    - libpng16-16
    - libthai0
    - libx11-6
    - libxau6
    - libxcb-render0
    - libxcb-shm0
    - libxcb1
    - libxcomposite1
    - libxcursor1
    - libxdamage1
    - libxdmcp6
    - libxext6
    - libxfixes3
    - libxi6
    - libxinerama1
    - libxrandr2
    - libxrender1
    override-build: |
      lazbuild --build-mode=Release myapp.lpi
      install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/bin
      install -s -m 755 myapp $SNAPCRAFT_PART_INSTALL/usr/bin/myapp
      install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/applications
      install -m 755 myapp.desktop $SNAPCRAFT_PART_INSTALL/usr/share/applications
    stage:
    - etc
    - lib
    - usr
    - usr/bin
    - usr/share/myapp
    - usr/share/applications/myapp.desktop

apps:
  myapp:
    command: usr/bin/myapp/myapp
    desktop: usr/share/applications/myapp.desktop
    plugs:
    - home
    - desktop
    - x11
  • Build snap using snapcraft command
  • Install newly created snap with sudo snap install --dangerous myapp_1.0.0_amd64.snap

Publish your package in Snap Store

snapcraft register
snapcraft login
snapcraft upload myapp.snap
snapcraft release myapp 1 stable

Now your snap should be released and available on snapcraft.io store.

Debug snap

To get to console of snap virtual filesystem use:

snap run --shell myapp
cd $SNAP

Type exit to leave snap environment. See Debugging snaps for more information.

Use newer Lazarus version

Normally you can use Lazarus IDE version provided by current base (2.0.6 for core20). To use latest stable version with new features you can add following part into your snapcraft.yaml file. This part should be executed before myapp part. You need to update fixed URL based on required Lazarus version. Then those packages will be downloaded and installed before build.

parts:
  lazarus:
    plugin: nil
    source: .
    source-type: local
    build-packages: 
    - wget
    - libgtk2.0-dev
    override-build: |
      wget -nc https://deac-ams.dl.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.2.0/lazarus-project_2.2.0-0_amd64.deb
      wget -nc https://netix.dl.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.2.0/fpc-laz_3.2.2-210709_amd64.deb
      wget -nc https://netix.dl.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.2.0/fpc-src_3.2.2-210709_amd64.deb
      apt install ./lazarus-project_2.2.0-0_amd64.deb ./fpc-laz_3.2.2-210709_amd64.deb ./fpc-src_3.2.2-210709_amd64.deb
    prime: [-*]
  myapp:
    after: [lazarus]

And remove normal Lazarus build-packages from your app so they are not installed for build:

  myapp
    build-packages: 
    - fpc
    - lazarus
    - lcl
    - lcl-utils

GTK2 theme support

There is no snapcraft extension available for GTK2 similarly to GTK3. So GTK2 theming needs to be configured with additional lines.

Content plugs only

To support GTK2 themes used by host system the app needs to have access to GTK2 themes. Standard GTK2 themes can be made available by using content plugs. Those content plugs are external shared packages so they won't make snap bigger. But the application can still print some errors into console.

Extend your snapcraft.yaml file with the following:

# Additional plugs to pick up the GTK theme and icons from the system
plugs: 
  icon-themes:
    interface: content
    target: $SNAP/data-dir/icons
    default-provider: gtk-common-themes
  sound-themes:
    interface: content
    target: $SNAP/data-dir/sounds
    default-provider: gtk-common-themes
  gtk-2-engines:
    interface: content
    target: $SNAP/lib/gtk-2.0
    default-provider: gtk2-common-themes:gtk-2-engines
  gtk-2-themes:
    interface: content
    target: $SNAP/usr/share/themes
    default-provider: gtk2-common-themes:gtk-2-themes

layout:
  /usr/share/themes:
    bind: $SNAP/usr/share/themes
  /usr/lib/$SNAPCRAFT_ARCH_TRIPLET/gtk-2.0:
    bind: $SNAP/lib/gtk-2.0

Full support

To fully support GTK2 environment we need to use snapcraft desktop helper and include various standard packages. Those packages make snap bigger by ~26 MB so there is a trade-off between size of snap packages and supported features.

Extend your snapcraft.yaml file with the following:

parts:
  desktop-gtk2:
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
    source-subdir: gtk
    plugin: make
    make-parameters: ["FLAVOR=gtk2"]
    build-packages:
    - build-essential
    - libgtk2.0-dev
    stage-packages:
    - libxkbcommon0  # XKB_CONFIG_ROOT
    - ttf-ubuntu-font-family
    - dmz-cursor-theme
    - light-themes
    - adwaita-icon-theme
    - gnome-themes-standard
    - shared-mime-info
    - libgtk2.0-0
    - libgdk-pixbuf2.0-0
    - libglib2.0-bin
    - libgtk2.0-bin
    - unity-gtk2-module
    - locales-all
    - libappindicator1
    - xdg-user-dirs
    - ibus-gtk
    - libibus-1.0-5
  myapp:
    after:
    - desktop-gtk2

# Additional plugs to pick up the GTK theme and icons from the system
plugs: 
  icon-themes:
    interface: content
    target: $SNAP/data-dir/icons
    default-provider: gtk-common-themes
  sound-themes:
    interface: content
    target: $SNAP/data-dir/sounds
    default-provider: gtk-common-themes
  gtk-2-engines:
    interface: content
    target: $SNAP/lib/gtk-2.0
    default-provider: gtk2-common-themes:gtk-2-engines
  gtk-2-themes:
    interface: content
    target: $SNAP/usr/share/themes
    default-provider: gtk2-common-themes:gtk-2-themes

environment:
  XDG_DATA_DIRS: $SNAP/usr/share:$XDG_DATA_DIRS
  GTK_PATH: $SNAP/lib/gtk-2.0

apps:
  myapp:
    command: usr/bin/myapp
    command-chain:
    - bin/desktop-launch

Sound support

Snap supports sound through audio-playback plug.

apps:
  myapp:
    plugs:
    - audio-playback

You can play wav and mp3 files from command line using play command. See Play Sound Multiplatform. Then you also need to add additional stage-packages to myapp part and setup sox player for pulseaudio:

parts:
  myapp:
    stage-packages:    
    - sox
    - libsox-fmt-mp3
    - libsox-fmt-pulse
    - libpulse0 

environment:
  LD_LIBRARY_PATH: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio
  PULSE_SERVER: unix:/run/user/1000/pulse/native

layout:
  /usr/lib/$SNAPCRAFT_ARCH_TRIPLET/sox:
    bind: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/sox

OpenGL support

To support 3D acceleration it is required to use opengl plug, package related libraries and set correct path for drivers.

parts:
  myapp:
    stage-packages:    
    - libglu1-mesa
    - libgl1-mesa-dri

apps:
  myapp:
    plugs:
    - opengl

environment:
  LIBGL_DRIVERS_PATH: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/dri

SDL support

Add needed build and stage packages.

parts:
  myapp:
    build-packages: 
    - libsdl2-dev
    - libsdl2-mixer-dev
    - libsdl2-image-dev
    stage-packages:
    - libsdl2-2.0-0
    - libsdl2-image-2.0-0
    - libsdl2-mixer-2.0-0

snapcraft.yaml file in non-standard subdirectory

Snapcraft normally expect snapcraft.yaml file in snap directory. If your project has packaging for multiple other packaging formats, then you need to use build workaround script. Such shell script can put into directory like myapp/install/snap/local as build.sh file.

#!/bin/bash
ln -s install/snap ../../../snap
pushd ../../..
snapcraft
popd
rm ../../../snap

Register app in snap store

Setup build on Launchpad

Snap packages can be built automatically on Launchpad. Open Create snap package link form your application branch page.

See also

External links