Last week, we published Introduction to snapcraft, a tutorial that provided a detailed overview of the snap build process. We touched on the concepts like snap ecosystem components, snapcraft command line, snapcraft.yaml syntax, and more. We’d like to expand on the first lesson, and today, we are going to talk about parts and plugins, used in the build process of snaps.
Our tasks for today include:
As their name implies, parts are the raw building blocks of a snap, used to collect and build binaries and their dependencies. Each part defines a source needed to assemble your application into a snap. Parts can be anything – programs, libraries, or other needed assets.
Parts support a large number of keys and values to describe the build process. However, before we demonstrate, let’s discuss plugins too, as the two are tightly coupled.
If you work with complex projects, having to manually define every part can be tedious. Snapcraft uses plugins, which help simplify the build process. They are declared within parts to better integrate projects using existing programming languages and frameworks.
You can also check specific details for each plugin, like:
snapcraft help ruby
Each plugin comes with its own capabilities and language-specific keywords. To illustrate the power and flexibility of plugins, let’s examine a real snap use case.
This is a section of code from a simple snapcraft.yaml file:
What do we have here?
Now, let’s examine a Go plugin example:
What do we have here?
In the Go example, you can also see the use of another keyword: build-packages. This is one of the important keys available in the parts section of the snapcraft.yaml file. Specifically, build-packages defines the list of packages required to build a snap.
If you have compiled code on Ubuntu-based systems, you may be familiar with the build-essential package. This is a meta package that defines a large number of compilation tools and dependencies, like gcc, make, headers, and more.
You can also list specific packages that your project needs. For instance: libnetfilter-queue-dev or portaudio19-dev.
These packages are installed using the package manager inside the snapcraft build instance. Some other examples of parts keywords include:
And there are many other keys, available in the snapcraft documentation.
This brings us to the end of this tutorial. Today, we learned about parts and plugins, used in the build process of snaps. We also saw several language-specific examples and examined the differences between them. In the next episode, we will talk more about snap confinement.
If you have any questions or feedback, please join our forum for a discussion.
Learn how the Ubuntu desktop operating system powers millions of PCs and laptops around the world.
Drones, and their wide-ranging uses, have been a constant topic of conversation for some years now, but we’re only just beginning to move away from the hypothetical and into reality. The FAA estimates that there will be 2 million drones in…
This was a fairly busy two weeks for the Web & design team at Canonical. Here are some of the highlights of our completed work. Web Web is the squad that develop and maintain most of the brochure websites across the Canonical.…
Snaps. The final frontier. These are the voyages of the OSS Snapcraft. Its continuing mission, to provide snap users with simple, clear and effective tips and tricks on how to build and publish their applications. In this tutorial, we are…