Rust
rust ¶
Rust Environment Helper Functions.
Helpers to check that Rust tools are present needed to compile Rust code during firmare build.
This functionality can be used to provide faster, direct feedback to a developer about the changes they may need to make to successfully build Rust code. Otherwise, the build will fail much later during firmware code compilation when Rust tools are invoked with messages that are ambiguous or difficult to find.
Note
- Individual tools can be opted out by setting the environment variable
RUST_ENV_CHECK_TOOL_EXCLUSIONS
with a comma separated list of the tools to exclude. For example, "rustup, cargo tarpaulin" would not require that those tools be installed.
RustToolInfo ¶
Represents information about a Rust tool.
Attributes:
Name | Type | Description |
---|---|---|
presence_cmd |
tuple[str]
|
A tuple of command-line arguments to check for the presence of the tool. |
install_help |
str
|
Help text for installing the tool. |
required_version |
str
|
The required version of the tool. |
regex |
str
|
Regular expression pattern to match the tool's version. |
RustToolChainInfo ¶
Represents information about a Rust toolchain.
Attributes:
Name | Type | Description |
---|---|---|
error |
bool
|
Indicates whether an error occurred while retrieving the toolchain information. |
toolchain |
str
|
The name of the Rust toolchain. |
CustomToolFilter ¶
Represents a custom tool filter.
Attributes:
Name | Type | Description |
---|---|---|
filter_fn |
Callable[[RustToolInfo, str], bool]
|
A callable function
that takes a |
error_msg |
str
|
The error message to be displayed if the tool is filtered. |
error_only |
bool
|
A boolean value indicating whether the error message should be displayed only when the tool is filtered. |
verify_workspace_rust_toolchain_is_installed ¶
verify_workspace_rust_toolchain_is_installed() -> (
RustToolChainInfo
)
Verifies the rust toolchain used in the workspace is available.
Note
This function does not use the toml library to parse the toml file since the file is very simple and its not desirable to add the toml module as a dependency.
Returns:
Name | Type | Description |
---|---|---|
RustToolChainInfo |
RustToolChainInfo
|
A tuple that indicates if the toolchain is available and includes the toolchain version if found. |
get_workspace_toolchain_version ¶
get_workspace_toolchain_version() -> RustToolChainInfo
Returns the rust toolchain version specified in the workspace toolchain file.
Returns:
Name | Type | Description |
---|---|---|
RustToolChainInfo |
RustToolChainInfo
|
The rust toolchain information. If an error occurs, the error field will be True with no toolchain info. |
run ¶
run(
custom_tool_checks: Dict[str, RustToolInfo] = {},
custom_tool_filters: List[CustomToolFilter] = [],
) -> int
Checks the current environment for Rust build support.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
custom_tool_checks |
Dict[str, RustToolInfo]
|
A dictionary
of custom tools to check. The key is the tool name and the value
is a |
{}
|
custom_tool_filters |
List[CustomToolFilter]
|
A list of custom tool filters. Defaults to []. |
[]
|
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Then number of errors discovered. 0 indicates success. |