snapcraft.yaml
The Architectures how-to guide provides examples of how to use the platforms and architectures keywords.
core24
The root keyword platforms defines a list of platforms, each containing a build-on and build-for keyword with the following syntax:
platforms:
<platform 1>:
build-on: [<arch 1>, <arch 2>]
build-for: [<arch 1>]
<platform 2>:
build-on: [<arch 3>]
build-for: [<arch 4>]
...
platform
The platform name describes a build-on/build-for pairing. If the platform name is a valid debian architecture, then build-on and build-for can be omitted (see below for details).
See here for a list of supported architectures.
The recommended platform name is build-for arch.
build-on
The build-on field is an optional list of architectures where the snap can be built. It can contain multiple architectures.
If the platform name is a valid architecture and build-for is not defined, then build-on can be omitted. build-on will assume the platform name.
build-for
The build-for field is an optional single-element list containing the architecture where the snap should run.
If the platform name is a valid architecture, then build-for will assume the platform name.
core22
The root keyword architectures defines a list of build-on->build-for pairs with the following syntax:
architectures:
- build-on: [<arch 1>, <arch 2>]
build-for: [<arch 1>]
- build-on: [<arch 3>]
build-for: [<arch 4>]
...
See here for a list of supported architectures.
Data types
If the value is a single item, it can be written as a single element list or a scalar. For example:
architectures:
- build-on: amd64
build-for: arm64
is equivalent to:
architectures:
- build-on: [amd64]
build-for: [arm64]
Using a list is the recommended syntax. Scalars are not recommended.
build-on
The build-on field is required and can contain multiple architectures.
build-for
The build-for field is optional and should be a single element list. If it is not defined, the build-for will be set the build-on for each build in the build plan.
build-for: [all] is a special keyword to denote an architecture-independent snap. If the all keyword is used, no other build-on/build-for pairs can be defined. See this page to learn how to use the all keyword.
all cannot be used for build-on.
The same architecture cannot be defined in multiple build-for entries.
core20
The above syntax and rules for core22 apply for core20 except that run-on is used in place of build-for. Additionally, core20 supports multiple architectures in the run-on field, which will create multi-architecture snaps.
Shorthand format
As an alternative to the explicit format described above, core20 snaps support a shorthand format for simple build-on/run-on pairs. The following shorthand:
architectures: [amd64, arm64]
is equivalent to:
architectures:
- build-on: [amd64]
run-on: [amd64]
- build-on: [arm64]
run-on: [arm64]
The explicit and shorthand format cannot be mixed.
Project variables
core24
| Project variable | Description |
|---|---|
CRAFT_ARCH_BUILD_FOR |
The architecture of the platform the snap is built for. |
CRAFT_ARCH_BUILD_ON |
The architecture of the platform the snap is built on. |
CRAFT_ARCH_TRIPLET_BUILD_FOR |
The architecture triplet of the platform the snap is built for. |
CRAFT_ARCH_TRIPLET_BUILD_ON |
The architecture triplet of the platform the snap is built on. |
core22
| Project variable | Description |
|---|---|
CRAFT_ARCH_BUILD_FOR |
The architecture of the platform the snap is built for. |
CRAFT_ARCH_BUILD_ON |
The architecture of the platform the snap is built on. |
CRAFT_ARCH_TRIPLET_BUILD_FOR |
The architecture triplet of the platform the snap is built for. |
CRAFT_ARCH_TRIPLET_BUILD_ON |
The architecture triplet of the platform the snap is built on. |
CRAFT_ARCH_TRIPLET |
Deprecated. Use CRAFT_ARCH_TRIPLET_BUILD_FOR instead. |
CRAFT_TARGET_ARCH |
Deprecated. Use CRAFT_ARCH_BUILD_FOR instead. |
core20
core20 snaps use the terminology run-on in the architectures field in snapcraft.yaml. The project variables and documentation use the preferred term build-for.
| Project variable | Description |
|---|---|
SNAPCRAFT_ARCH_BUILD_FOR |
The architecture of the platform the snap is built for. |
SNAPCRAFT_ARCH_BUILD_ON |
The architecture of the platform the snap is built on. |
SNAPCRAFT_ARCH_TRIPLET_BUILD_FOR |
The architecture triplet of the platform the snap is built for. |
SNAPCRAFT_ARCH_TRIPLET_BUILD_ON |
The architecture triplet of the platform the snap is built on. |
SNAPCRAFT_ARCH_TRIPLET |
The architecture triplet specified by --target-arch. If a target arch is not provided, then the architecture of the build-on platform is used. |
SNAPCRAFT_TARGET_ARCH |
The architecture specified by --target-arch. If a target arch is not provided, then the architecture of the build-on platform is used. |
SNAPCRAFT_ARCH_BUILD_FOR and SNAPCRAFT_ARCH_TRIPLET_BUILD_FOR are not available in either of the following scenarios:
- When the build-for architecture is not in the list of supported architectures
- When building a multi-architecture snap
Supported architectures
Supported locally
The following architectures can be used when building a snap locally.
- amd64
- arm64
- armhf
- i386
- powerpc
- ppc64el
- riscv64
- s390x
Supported by Launchpad
The following architectures are supported by Launchpad for remote building.
- amd64
- arm64
- armhf
- ppc64el
- riscv64
- s390x
Environment variables and command line arguments
core22
The command line argument --build-for=<arch> or environment variable SNAPCRAFT_BUILD_FOR=<arch> is used to build a single snap package for an architecture. It selects a single build-on->build-for pair from the build plan. It does not allow building a snap not defined by the build plan.
The command line argument takes priority over the environment variable.
See build plans for more information on how build plans are created.
core20
--target-arch=<arch> is used for cross-compiling in core20. It adds repositories for the target arch, which are used for stage-packages. The target arch does not need to be listed in the snapcraft.yaml architectures keyword.
The --target-arch argument can only be used in destructive mode and with --enable-experimental-target-arch or the environment variable SNAPCRAFT_ENABLE_EXPERIMENTAL_TARGET_ARCH.
The full usage is snapcraft --destructive-mode --enable-experimental-target-arch --target-arch=<arch>.