Select platforms¶
By default, Snapcraft builds a snap to run on the same architecture as the build
environment. This behavior can be modified with the top-level keys
architectures and platforms in the snap’s project file.
The architectures and platforms keys are used to create a build
plan. See build plans for an explanation on how build
plans are created.
The keys are base-dependent:
platformsis used for core24 and higher snapsarchitecturesis used for core22 snaps
Target a single architecture¶
To create a snap that will be built on AMD64 and built for AMD64, use one of the following project file snippets.
core24 and higher¶
platforms:
amd64:
build-on: [amd64]
build-for: [amd64]
Building on AMD64 will produce one snap built for AMD64.
If the platform name is a valid architecture and build-for is omitted,
build-for 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.
core22¶
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]
Target multiple architectures¶
core24 and higher¶
core24 and higher 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 the platform name is a valid architecture and build-for is omitted,
build-for will assume the platform name. 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¶
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]
Target all architectures¶
build-for: [all] is used for a snap that can run on all architectures, like
a snap that is a shell or python script. It cannot be combined with other
architectures. Click here for more information on
the all key.
core24 and higher¶
platforms:
all:
build-on: [amd64]
build-for: [all]
core22¶
architectures:
- build-on: [amd64]
build-for: [all]
Target across architectures¶
core24 and higher¶
platforms:
arm64:
build-on: [amd64]
build-for: [arm64]
Building on AMD64 will produce one snap built for ARM64.
If the platform name is a valid architecture and build-for is omitted,
build-for will assume the platform name. The following snippet will produce
the same result:
platforms:
arm64:
build-on: [amd64]
core24 and higher 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.
core22¶
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.
Stage packages across architectures¶
To use an I386 package for an AMD64 snap, use the following project file snippets 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.