When building a snap with Snapcraft, parts are used to describe your application, where its various components can be found, its build and run-time requirements, and those of its dependencies. Consequently, a snap always has one or more parts.
A part’s definition within snapcraft.yaml is purposely flexible to allow for varied and disparate sources.
At its simplest, a part will locate a project’s source code and to invoke a plugin to build and deploy the consequent application within your snap environment. But a part can equally be used to source and unpack a binary executable from an RPM file, or override into the correct location.
A part can also download tagged code from a remote repository, pull in dependencies, define a build order, and completely override both the snapcraft build and the snapcraft stage phases of the process.
For more details on how parts are built within the snapcraft environment, including build stages and the directories they use, see Parts lifecycle.
Defining a part
snapcraft init command creates the following part template in snapcraft.yaml:
parts: my-part: # See 'snapcraft plugins' plugin: nil
A part starts with an arbitrary name, such as
my-part, which is followed by enough Snapcraft parts metadata to build the functionality you require.
The core of a typical part will commonly consist of the following metadata:
Used to simplify and accelerate your build on commonly used frameworks and platforms. A plugin will often add, and may require, its own additional metadata. See Snapcraft plugins for more details.
The location of the file or files needed to build your part. It can refer to a directory tree, a compressed archive, or a revision control repository.
A list of the packages required to build your part. Package names are those used by the build host’s package manager, such as apt or dnf.
[pkg-config, libncursesw5-dev, sed ]
A list of the snaps required to build your part. Snap names can include track and channel options (
A list of the packages required by your part to run. Package names are those used by the build host’s package manager, such as apt or dnf.
[gnome-themes-standard, libncursesw5, dbus]
A list of the snaps required by your part to run. As with build-snaps, you can optionally add the track and channel of the snaps you wish to include.
As per the YAML specification, the members of a list in snapcraft.yaml can be formatted in either of the following ways:
build-packages: [g++, make, git, sed] build-packages: - g++ - make - git - sed
For help on working out which packages you need for both building and staging your snap, take a look at Build and staging dependencies, and see Snapcraft parts metadata for a complete list of supported parts keywords.
Parts can also be sourced from shell scripts outside of the snapcraft.yaml. See Scriptlets for details.
Last updated 14 days ago.