Platforms

A project’s platforms key has a default schema as well as a way for applications to override it.

The following mockup shows all the valid ways to create platform entries:

platforms:
  <platform 1 name as a string>:
    build-on: [<arch 1>, <arch 2>]
    build-for: [<arch 1>]
  <platform 2>:
    build-on: <arch 3>
    build-for: [<arch 4>]
  <platform 3>:
    build-on: [<arch 3>]
    build-for: <arch 4>
  <platform 4>:
    build-on: <arch 1>
    build-for: <arch 2>
  <arch 1>:
  <arch 2>:
    build-on: <arch 1>
  <arch 3>:
    build-on: [<arch 1>, <arch 2>]
    build-for: <arch 2>

Platform schema

A single platform entry in the platforms dictionary.

This model defines how a single value under the platforms key works for a project.

build-on

Type

list

Description

Architectures to build on.

This list must contain unique values. If this field is a string containing the build-on architecture, it will be parsed at runtime into a single-entry list.

Examples

build-on: amd64
build-on:
  - arm64
  - riscv64

build-for

Type

list

Description

Target architecture for the build.

If this field is a string containing the target architecture, it will be parsed at runtime into a single-entry list. build-for is optional if the name of the platform is a valid build-for entry, but the model will contain the correct value.

Examples

build-for: amd64
build-for:
  - arm64
  - riscv64

Default PlatformsDict

The platforms dictionary is implemented as a non-generic child class of GenericPlatformsDict.

class craft_application.models.PlatformsDict

Bases: GenericPlatformsDict[Platform]

A dictionary with a Pydantic schema for the general platforms key.

This is the default Pydantic model for the platforms dictionary on a Project model. Most applications will simply use this without modification, as it provides the default implementation. An application that uses the generic Platform schema may use this directly. Applications that need their own Platform model can override GenericPlatformsDict.

Inheritance

Applications may override the default model for each platform by inheriting from the craft_application.models.Platform class and modifying it as needed. There is a how-to guide to Customize platforms in a project model with implementation instructions. The class has several validators that may need to be modified.

class craft_application.models.Platform(*, build_on: MinLen(min_length=1)], build_for: Annotated[list[str], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1), MaxLen(max_length=1)])] | str)

A single platform entry in the platforms dictionary.

This model defines how a single value under the platforms key works for a project.

classmethod _validate_architectures(values: list[str]) list[str]

Validate the architecture entries.

Entries must be a valid debian architecture or ‘all’. Architectures may be preceded by an optional base prefix formatted as ‘[<base>:]<arch>’.

Raises:

ValueError – If any of the bases or architectures are not valid.

classmethod _validate_build_on_real_arch(values: list[str]) list[str]

Validate that we must build on a real architecture.

class craft_application.models.GenericPlatformsDict

A generic dictionary describing the contents of the platforms key.

This class exists to generate Pydantic and JSON schemas for the platforms key on a project. By making it a generic, an application can override the Platform definition and provide its own PlatformsDict. A side effect of this, however, is that an application cannot simply use the generic directly. Instead, it must create a non-generic child class and use that.

classmethod __get_pydantic_core_schema__(source_type: type, handler: GetCoreSchemaHandler) InvalidSchema | AnySchema | NoneSchema | BoolSchema | IntSchema | FloatSchema | DecimalSchema | StringSchema | BytesSchema | DateSchema | TimeSchema | DatetimeSchema | TimedeltaSchema | LiteralSchema | EnumSchema | IsInstanceSchema | IsSubclassSchema | CallableSchema | ListSchema | TupleSchema | SetSchema | FrozenSetSchema | GeneratorSchema | DictSchema | AfterValidatorFunctionSchema | BeforeValidatorFunctionSchema | WrapValidatorFunctionSchema | PlainValidatorFunctionSchema | WithDefaultSchema | NullableSchema | UnionSchema | TaggedUnionSchema | ChainSchema | LaxOrStrictSchema | JsonOrPythonSchema | TypedDictSchema | ModelFieldsSchema | ModelSchema | DataclassArgsSchema | DataclassSchema | ArgumentsSchema | ArgumentsV3Schema | CallSchema | CustomErrorSchema | JsonSchema | UrlSchema | MultiHostUrlSchema | DefinitionsSchema | DefinitionReferenceSchema | UuidSchema | ComplexSchema

Get the Pydantic CoreSchema for this PlatformsDict.

From a Pydantic perspective, this dict is merely a dict[str, PT], where PT is the type of the Platform field. It is unlikely to need to override this method.

classmethod __get_pydantic_json_schema__(core_schema: InvalidSchema | AnySchema | NoneSchema | BoolSchema | IntSchema | FloatSchema | DecimalSchema | StringSchema | BytesSchema | DateSchema | TimeSchema | DatetimeSchema | TimedeltaSchema | LiteralSchema | EnumSchema | IsInstanceSchema | IsSubclassSchema | CallableSchema | ListSchema | TupleSchema | SetSchema | FrozenSetSchema | GeneratorSchema | DictSchema | AfterValidatorFunctionSchema | BeforeValidatorFunctionSchema | WrapValidatorFunctionSchema | PlainValidatorFunctionSchema | WithDefaultSchema | NullableSchema | UnionSchema | TaggedUnionSchema | ChainSchema | LaxOrStrictSchema | JsonOrPythonSchema | TypedDictSchema | ModelFieldsSchema | ModelSchema | DataclassArgsSchema | DataclassSchema | ArgumentsSchema | ArgumentsV3Schema | CallSchema | CustomErrorSchema | JsonSchema | UrlSchema | MultiHostUrlSchema | DefinitionsSchema | DefinitionReferenceSchema | UuidSchema | ComplexSchema, handler: GetJsonSchemaHandler) dict[str, Any]

Get the JSON schema for this PlatformsDict.

This method converts the pydantic core schema into a JSON schema dictionary. The default implementation adds the possible values from _shorthand_keys as keys that do not require a value or can have build-on values without declaring a build-for value.

_shorthand_keys

alias of DebianArchitecture