Build and staging dependencies

When building a snap and constructing a part, you commonly need to specify build and staging dependencies. These dependencies are listed in snapcraft.yaml within a part definition as either package names, or snap names, with the following metadata:

For packages:

  • build-packages: packages required for the part to build
  • stage-packages: packages required to run the part

For snaps:

  • build-snaps: snaps required for the part to build.
  • stage-snaps: snaps required to run the part

Snaps are downloaded from the Snap Store and unpacked into the snap being built. If a specific channel is required, the syntax is of the form <snap-name>/<channel> (see Channels for more details on the syntax).

For staged snaps, the meta and snap directories from the snap will be available as meta.<snap-name> and snap.<snap-name> for cases where assets from those locations are desired for reuse.

The following is a typical example of a part’s build- and stage- sections for a command tool line thats interacts with git:

  - pkg-config
  - libreadline-dev
  - libncurses5-dev
  - go
  - ffmpeg/latest/edge
  - git

Adding additional repositories:
See Snapcraft package repositories for details on how to add apt repositories as sources for build-packages and stage-packages , including those hosted on a PPA.

Package names

Package dependencies are listed as package names for the snap’s build environment.

For a default Snapcraft installation running Multipass, the build environment is invariably Ubuntu 18.04 LTS (Bionic Beaver). Consequently, dependencies are listed using their apt package names.

It’s also feasible to have a build environment built on Fedora for example, using Fedora packages, or those of your own host environment.

The packages you need are likely to be identical to those you need to either build your project (build-packages) or install your project (stage-packages). You’ll often find them listed in a project’s, or alongside any build instructions.

Debugging missing packages

Working out your project’s dependencies can be an iterative process, much like compiling a third-party package:

  1. when you have a workable framework snapcraft.yaml for your snap, run snapcraft --debug until you hit an error
  2. If that error is a build dependency, use the debug interactive shell to work out which package is required
  3. add the package to your snapcraft.yaml and type snapcraft within the build environment to see if you have the same error

Automatic filtering of stage-package dependencies

Snapcraft minimizes the size of a target snap by filtering out stage-package dependencies, if they are available in the base, e.g. core18.

In some cases, it may be desirable to stage a package’s dependencies inside the snap, avoiding the use of the package available in the base snap. To do this, explicitly add each desired package to stage-packages list - Snapcraft will always stage any package explicitly listed.

To find the list of packages that are available in the base snap, you may find the manifest at:

Build and testing best practices

See Iterating over a build for build and testing best-practices.

Troubleshooting build errors

See Troubleshoot snap building for help with resolving build errors.

Last updated 5 months ago.