By default, Snapcraft builds a snap to run on the same architecture as the build environment. This behaviour can be modified with the top-level keywords architectures
and platforms
in the snap’s snapcraft.yaml
.
The architectures
and platforms
keywords are used to create a build plan. See build plans for an explanation of how build plans are created.
The keywords are base-dependent:
platforms
is used for core24
snapsarchitectures
is used for core20
and core22
snapsTo create a snap that will be built on amd64
and built for amd64
, use one of the snapcraft.yaml
snippets below.
platforms:
amd64:
build-on: [amd64]
build-for: [amd64]
Building on amd64
will produce one snap built for amd64
. If build-for
is omitted, it will assume the platform name. The following snippet will produce the same result:
platforms:
amd64:
build-on: [amd64]
If the platform name is a valid architecture, then build-on
and build-for
will assume the platform name. The following snippet will produce the same result:
platforms:
amd64:
Note that build-for
can be omitted if build-on
is defined but the converse is not true; build-on
cannot be omitted if build-for
is defined.
architectures:
- build-on: [amd64]
build-for: [amd64]
Building on amd64
will produce one snap built for amd64
. Snapcraft will raise an error when building on another architecture.
If build-for
is omitted, it will assume the value of build-on
. The following snippet will produce the same result:
architectures:
- build-on: [amd64]
architectures:
- build-on: [amd64]
run-on: [amd64]
Building on amd64
will produce one snap built for amd64
. Snapcraft will not raise an error when building on another architecture. Instead, it will ignore the architectures
keyword and build for the build-on architecture.
If run-on
is omitted, it will assume the value of build-on
. The following snippet snippet will produce the same result:
architectures:
- build-on: [amd64]
The shorthand format will also produce the same result:
architectures:
- amd64
core24
snaps accept a single build-for
architecture per-platform. To create a set of snaps for multiple architectures, define a set of platforms:
platforms:
amd64:
build-on: [amd64]
build-for: [amd64]
arm64:
build-on: [arm64]
build-for: [arm64]
Building on amd64
will produce one snap for amd64
. Building on arm64
will produce one snap for arm64
. Snapcraft will raise an error when building on another architecture.
If build-for
is omitted, it will assume the value of build-on
. The following snippet will produce the same result:
platforms:
amd64:
build-on: [amd64]
arm64:
build-on: [arm64]
If the platform name is a valid architecture, then build-on
and build-for
will assume the platform name. The following snippet will produce the same result:
platforms:
amd64:
arm64:
core22
snaps accept a single build-for
architecture per build-on
/build-for
pair. To create a set of snaps for multiple architectures, define a set of build-on
/build-for
pairs:
architectures:
- build-on: [amd64]
build-for: [amd64]
- build-on: [arm64]
build-for: [arm64]
Building on amd64
will produce one snap for amd64
. Building on arm64
will produce one snap for arm64
. Snapcraft will raise an error when building on another architecture.
If build-for
is omitted, it will assume the value of build-on
. The following snippet will produce the same result:
architectures:
- build-on: [amd64]
- build-on: [arm64]
architectures:
- build-on: [amd64]
run-on: [amd64]
- build-on: [arm64]
run-on: [arm64]
Building on amd64
will produce one snap built for amd64
. Building on arm64
will produce one snap built for arm64
. Snapcraft will not raise an error when building on another architecture. Instead, it will ignore the architectures
keyword and build for the build-on architecture.
If run-on
is omitted, it will assume the value of build-on
. The following snippet will produce the same result:
architectures:
- build-on: [amd64]
- build-on: [arm64]
The shorthand format will also produce the same result:
architectures: [amd64, arm64]
build-for: [all]
is used for a snap that can run on all architectures, like a shell or python script snap. It cannot be combined with other architectures. Click here for more information on the all
keyword.
Snapcraft does not support architecture-independent snaps for core24
. Instead, a different snap package should be created for each architecture.
To support all architectures, either omit the platforms
keyword or list all architectures:
platforms:
amd64:
arm64:
...
architectures:
- build-on: [amd64]
build-for: [all]
architectures:
- build-on: [amd64]
run-on: [all]
platforms:
arm64:
build-on: [amd64]
build-for: [arm64]
Building on amd64
will produce one snap built for amd64
. If build-for
is omitted, it will assume the platform name. The following snippet will produce the same result:
platforms:
arm64:
build-on: [amd64]
core24
can handle complex build plans. For example:
platforms:
amd64:
build-on: [amd64]
build-for: [amd64]
arm64:
build-on: [amd64, arm64]
build-for: [arm64]
Building on arm64
will produce one snap built for arm64
.
Building on amd64
will produce two snaps, one built for amd64
and one built for arm64
. This only occurs using remote-build
or a build provider. In destructive mode, Snapcraft can only produce one snap. --build-for
or --platform
must be used to narrow down the build plan to a single snap. For example, snapcraft pack --destructive-mode --platform arm64
on amd64
will produce one snap built for arm64
.
Snapcraft will raise an error when building on another architecture.
architectures:
- build-on: [amd64]
build-for: [arm64]
Building on amd64
will produce one snap built for arm64
. Snapcraft will raise an error when building on another architecture.
core22
can handle complex build plans. For example:
architectures:
- build-on: [amd64]
build-for: [amd64]
- build-on: [amd64, arm64]
build-for: [arm64]
Building on amd64
will produce two snaps, one built for amd64
and one built for arm64
. Building on arm64
will produce one snap built for arm64
. Snapcraft will raise an error when building on another architecture.
architectures:
- build-on: [amd64]
run-on: [arm64]
Building on amd64
will produce one snap built for arm64
. Snapcraft will not raise an error when building on another architecture. Instead, it will ignore the architectures
keyword and build for the build-on architecture.
Complex build plans like the previous core22
example are not supported for core20
.
To use an i386
package for an amd64
snap, use the following snapcraft.yaml
snippet for core22
:
architectures:
- build-on: [amd64]
build-for: [amd64]
package-repositories:
- type: apt
formats: [deb]
architectures: [i386]
components: [main]
suites: [jammy]
key-id: F23C5A6CF475977595C89F51BA6932366A755776
url: https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu
parts:
mypart:
stage-packages:
- libpython3.11-minimal:i386
This is supported for related architectures. A snap built for amd64
can stage i386
packages and a snap built for i386
can stage amd64
packages. Similarly, a snap built for arm64
can stage armhf
packages and a snap built for armhf
can stage amd64
packages.
Last updated 6 months ago.