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-features (list of strings) Features used to build optional dependencies

  • 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


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

Return type:



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

Return type:

Dict[str, str]


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

Return type:



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

Return type:



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

Return type:



alias of RustPluginProperties


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.

  • 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.


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

Return type:


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

Bases: PluginProperties, PluginModel

The part properties used by the Rust plugin.


data (Any) –

after: Optional[ConstrainedListValue[str]]
rust_channel: Optional[str]
rust_features: ConstrainedListValue[str]
rust_no_default_features: bool
rust_path: ConstrainedListValue[str]
rust_use_global_lto: bool
source: str
classmethod unmarshal(data)[source]

Populate class attributes from the part specification.


data (Dict[str, Any]) – A dictionary containing part properties.

Return type:



The populated plugin properties data object.


pydantic.ValidationError – If validation fails.