craft_parts.plugins.rust_plugin module

The craft Rust plugin.

class craft_parts.plugins.rust_plugin.RustPlugin(*, properties, part_info)[source]

Bases: Plugin

A craft plugin for Rust applications.

This Rust plugin is useful for building Rust based parts.

Rust uses cargo to drive the build.

This plugin uses the common plugin keywords as well as those for “sources”. For more information check the ‘plugins’ topic for the former and the ‘sources’ topic for the latter.

Additionally, this plugin uses the following plugin-specific keywords:
  • rust-channel (string, default “stable”) Used to select which Rust channel or version to use. It can be one of “stable”, “beta”, “nightly” or a version number. If you don’t want this plugin to install Rust toolchain for you, you can put “none” for this option.

  • rust-ignore-toolchain-file (boolean, default False) Whether to ignore the rust-toolchain.toml file. The upstream project can use this file to specify which Rust toolchain to use and which component to install. If you don’t want to follow the upstream project’s specifications, you can put true for this option to ignore the toolchain file.

  • rust-features (list of strings) Features used to build optional dependencies. You can specify [“*”] for all features (including all the optional ones).

  • rust-path (list of strings, default [.]) Build specific crates inside the workspace

  • rust-no-default-features (boolean, default False) Whether to disable the default features in this crate. Equivalent to setting –no-default-features on the commandline.

  • rust-use-global-lto (boolean, default False) Whether to use global LTO. This option may significantly impact the build performance but reducing the final binary size. This will forcibly enable LTO for all the crates you specified, regardless of whether you have LTO enabled in the Cargo.toml file

  • rust-cargo-parameters (list of strings) Append additional parameters to the Cargo command line.

  • rust-inherit-ldflags (boolean, default False) Whether to inherit the LDFLAGS from the environment. This option will add the LDFLAGS from the environment to the Rust linker directives.

Parameters:
get_build_commands()[source]

Return a list of commands to run during the build step.

Return type:

list[str]

get_build_environment()[source]

Return a dictionary with the environment to use in the build step.

Return type:

dict[str, str]

get_build_packages()[source]

Return a set of required packages to install in the build environment.

Return type:

set[str]

get_build_snaps()[source]

Return a set of required snaps to install in the build environment.

Return type:

set[str]

get_pull_commands()[source]

Return a list of commands to run during the pull step.

Return type:

list[str]

properties_class

alias of RustPluginProperties

validator_class

alias of RustPluginEnvironmentValidator

class craft_parts.plugins.rust_plugin.RustPluginEnvironmentValidator(*, part_name, env, properties)[source]

Bases: PluginEnvironmentValidator

Check the execution environment for the Rust plugin.

Parameters:
  • part_name (str) – The part whose build environment is being validated.

  • env (str) – A string containing the build step environment setup.

  • properties (PluginProperties)

validate_environment(*, part_dependencies=None)[source]

Ensure the environment has the dependencies to build Rust applications.

Parameters:

part_dependencies (Optional[list[str]]) – A list of the parts this part depends on.

Return type:

None

class craft_parts.plugins.rust_plugin.RustPluginProperties(**data)[source]

Bases: PluginProperties

The part properties used by the Rust plugin.

Parameters:

data (Any)

after: Optional[Annotated[list[str]]]
model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'alias_generator': <function PluginProperties.<lambda>>, 'extra': 'forbid', 'frozen': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'after': FieldInfo(annotation=Union[Annotated[list[str], AfterValidator], NoneType], required=False, default=None, alias='after', alias_priority=1), 'plugin': FieldInfo(annotation=Literal['rust'], required=False, default='rust', alias='plugin', alias_priority=1), 'rust_cargo_parameters': FieldInfo(annotation=list[str], required=False, default=[], alias='rust-cargo-parameters', alias_priority=1), 'rust_channel': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias='rust-channel', alias_priority=1), 'rust_features': FieldInfo(annotation=list[str], required=False, default=[], alias='rust-features', alias_priority=1, metadata=[AfterValidator(func=<function _validate_list_is_unique>)]), 'rust_ignore_toolchain_file': FieldInfo(annotation=bool, required=False, default=False, alias='rust-ignore-toolchain-file', alias_priority=1), 'rust_inherit_ldflags': FieldInfo(annotation=bool, required=False, default=False, alias='rust-inherit-ldflags', alias_priority=1), 'rust_no_default_features': FieldInfo(annotation=bool, required=False, default=False, alias='rust-no-default-features', alias_priority=1), 'rust_path': FieldInfo(annotation=list[str], required=False, default=['.'], alias='rust-path', alias_priority=1, metadata=[AfterValidator(func=<function _validate_list_is_unique>)]), 'rust_use_global_lto': FieldInfo(annotation=bool, required=False, default=False, alias='rust-use-global-lto', alias_priority=1), 'source': FieldInfo(annotation=str, required=True, alias='source', alias_priority=1)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

plugin: Literal['rust']
rust_cargo_parameters: list[str]
rust_channel: str | None
rust_features: Annotated[list[str]]
rust_ignore_toolchain_file: bool
rust_inherit_ldflags: bool
rust_no_default_features: bool
rust_path: Annotated[list[str]]
rust_use_global_lto: bool
source: str
classmethod validate_rust_channel(value)[source]

Validate the rust-channel property.

Parameters:

value (str | None) – The value to validate.

Return type:

str | None

Returns:

The validated value.