Skip to content

Commit

Permalink
Add Rust Environment module
Browse files Browse the repository at this point in the history
Adds helpers for checking if a firmare environment is ready to build
Rust.

The primary purpose of the functionality in rust_environment is to be
used in a build plugin wrapper. However, the public functions may be
used in other contexts as well.

Signed-off-by: Michael Kubacki <[email protected]>
  • Loading branch information
makubacki committed Jul 11, 2024
1 parent 32e6028 commit cde2638
Show file tree
Hide file tree
Showing 3 changed files with 882 additions and 0 deletions.
59 changes: 59 additions & 0 deletions docs/user/features/rust_environment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Rust Environment Helpers

## About Rust Environment Helpers

Firmware developer's machines are often not setup for Rust. As more Rust code is proliferating across the repos, this
code can be used to provide early and direct feedback about the developer's environment so it can successfully build
Rust code using the tools commonly used in the firmware build process.

## Usage

The primary purpose of the functionality in `rust_environment` is to be used in a build plugin wrapper. However, the
public functions may be used in other contexts as well. The following functions are available:

- `run()` - Checks the current environment for Rust build support.
- The checks can be customized with the `custom_tool_checks` and `custom_tool_filters` parameters.
- `get_workspace_toolchain_version()` - Returns the rust toolchain version specified in the workspace toolchain file.
- `verify_workspace_rust_toolchain_is_installed()` - RVerifies the rust toolchain used in the workspace is available.

### Integration Examples

This section provides examples of how to use the functions available in `edk2toolext/codeql.py`.

#### `run()`

Call to check the environment for Rust build support:

```python
import edk2toolext.rust_environment as rust_env

def Run(self):
rust_env.run()
```

#### `get_workspace_toolchain_version()`

Call to get Rust toolchain info:

```python
import edk2toolext.rust_environment as rust_env

def GetWorkspaceToolchainVersion(self):
toolchain = rust_env.get_workspace_toolchain_version()
print(f"Workspace toolchain version: {toolchain_version.toolchain}")
```

#### `verify_workspace_rust_toolchain_is_installed()`

Call to verify the workspace specified toolchain is installed:

```python
import edk2toolext.rust_environment as rust_env

def VerifyWorkspaceRustToolchainIsInstalled(self):
rust_toolchain_info = verify_workspace_rust_toolchain_is_installed()
if rust_toolchain_info.error:
print(f"Error: {rust_toolchain_info.error}")
else:
print(f"Rust toolchain is installed: {rust_toolchain_info.toolchain}")
```
Loading

0 comments on commit cde2638

Please sign in to comment.