The main building blocks of a snap are parts. They are used to declare pieces of code that will be pulled into your snap package. The parts keys and values in snapcraft.yaml detail how parts are configured and built by the snapcraft command.

See Snapcraft top-level metadata and Snapcraft apps and services metadata for details on how apps and parts are configured within snapcraft.yaml.

parts

Type: dict

A set of independent building blocks.

These independent building blocks are known as parts, and consist of either code or pre-built packages.

parts.<part-name>

Type: dict

The name of the part building block.

<part-name> represents the specific name of a building block which can be then referenced by the command line tool (i.e. snapcraft).

Keys for parts

The following are keys that can be used within parts. (for example, parts.<part-name>.plugin):

after

Type: list[string]

Ensures that all the <part-names> listed in after are staged before this part begins its lifecycle.

build

Type: multiline string

Replaces a plugin’s default build process with a script.

The shell script defined here replaces the build step of the plugin, defined in parts.<part-name>.plugin starts. The working directory is the base build directory for the given part. The defined script is run with /bin/sh and set -e. A set of Environment Variables will be available to the script.

build-attributes

Type: enum

A list of named attributes to modify the behaviour of plugins.

For more information, refer to Snapcraft plugins.

build-packages

Type: list[string]

A list of packages required to build a snap.

Packages are installed using the host’s package manager, such as apt or dnf, and are required for <part-name> to build correctly. This entry supports additional syntax, for more information refer to Advanced grammar.

Example: `[ libssl-dev, libssh-dev, libncursesw5-dev]

build-snaps

Type: list[string]

A list of snap names to install that are necessary to build <part-name>.

If a specific channel is required, the syntax is of the form <snap-name>/<channel>. This entry supports additional syntax, for more information refer to Advanced grammar

filesets

Type: list[string]

A key to represent a group of files, or a single file.

See Snapcraft filesets for further details.

install

Type: multiline string

Runs a script after the plugin’s build step.

The shell script defined here is run after the build step of the plugin defined in parts.<part-name>.plugin starts. The working directory is the base build directory for the given part. The defined script is run with /bin/sh and set -e. A set of Environment Variables will be available to the script.

organize

Type: dict

A map of files to rename.

In the key/value pair, the key represents the path of a file inside the part and the value represents how the file is going to be staged.

Example: bin/snapcraftctl: bin/scriptlet-bin/snapcraftctl

parse-info

Type: string

Defines the content to adopt when using external metadata.

See Using external metadata for more details.

plugin

Type: string

The plugin to drive the build process.

Every part drives its build through a plugin, this entry declares the plugin that will drive the build process for <part-name>. Refer to snapcraft plugins for more information on the available plugins and the specific attributes they add to the parts.<part-name>. namespace.

prepare

Type: multiline string

Runs a script before the plugin’s build step.

The script is run before the build step defined for parts.<part-name>.plugin starts. The working directory is the base build directory for the given part. The defined script is run with /bin/sh and set -e. A set of Environment Variables will be available to the script.

prime

Type: list[string]

A list of files from <part-name> to prime.

Rules applying to the list here are the same as those of filesets. Referencing of fileset keys is done with a $ prefixing the fileset key, which will expand with the value of such key.

source

Type: string

A URL or path to a source tree to build.

This can be a local path or remote, and can refer to a directory tree, a compressed archive or a revision control repository. This entry supports additional syntax, for more information refer to Advanced grammar

source-branch

Type: string

Work on a specific branch for source repositories under version control.

source-checksum

Type: string

Used when source represents a file.

Takes the syntax <algorithm>/<digest>, where <algorithm> can be any of: md5, sha1, sha224, sha256, sha384, sha512, sha3_256, sha3_384 or sha3_512. When set, the source is cached for multiple uses in different snapcraft projects.

source-commit

Type: string

Work on a specific commit for source repositories under version control.

source-depth

Type: integer

Depth of history for sources using version control.

Source repositories under version control are cloned or checked out with full history. Specifying a depth will truncate the history to the specified number of commits.

source-subdir

Type: string

A path within the source to set as the working directory when building.

source-tag

Type: string

Work on a specific tag for source repositories under version control.

source-type

Type: enum

Used when the type-of source entry cannot be detected.

Can be one of the following: [git|bzr|hg|svn|tar|deb|rpm|zip|7z]

stage

Type: list[string]

A list of files from <part-name> to stage.

Rules applying to the list here are the same as those of filesets. Referencing of fileset keys is done with a $ prefixing the fileset key, which will expand with the value of such key.

stage-packages

Type: list[string]

A list of packages required at runtime by a snap.

Packages are installed using the host’s package manager, such as apt or dnf, and are required by <part-name> to run. This entry supports additional syntax, for more information refer to Advanced grammar.

Example: [python-zope.interface, python-bcrypt]