6.4.3. Source Code Analysis for Rust¶
6.4.3.1. Introduction¶
The information in this chapter is only relevant to the Rust variant of the Axivion Suite.
AxivionRustFrontend can be used to generate an RFG from Rust source code. This enables Architecture Verification, Dead Code Analysis, Cycle Detection, and other RFG-based analyses.
In addition, the Rust RFG can be merged with a C/C++ RFG to enable cross-language analysis as described in Cross-Language Analysis Setup Guide.
For more details on supported features and Rust analysis capabilities, see Features.
6.4.3.2. Requirements¶
Analysis of Rust source code requires cargo (Rust’s package manager) to be installed.
The project under analysis must be a cargo project (i.e. have a cargo manifest file
Cargo.toml in its root directory).
Note
Cargo requires network access to download project dependencies. If cargo cannot download the dependencies of the project being analyzed, the analysis may be incomplete.
6.4.3.3. Usage with axivion_ci¶
AxivionRustFrontend can be invoked as part of axivion_ci by enabling it
under BuildSystemIntegration in the project configuration.
The following sections detail this configuration using
axivion_config.
Prerequisites¶
Before configuring AxivionRustFrontend for the first time, ensure the following
global configuration properties are set:
Set
/Project/directoryto the repository root.Set
/Project/nameto the name of the project.Set
/Dashboard/dashboard_urlto the URL where the Axivion Dashboard is hosted.Set the environment variable
AXIVION_DATABASES_DIRto the correct location.
Setup of AxivionRustFrontend¶
Create a new copy of the
AxivionRustFrontendaction.Set
manifest_pathto the path of the mainCargo.tomlfile for your Rust workspace or project.Configure the Rust toolchain settings:
Set
sysroot_pathto the Rust toolchain directory:
Use
discover(default) to automatically detect the sysroot usingrustc --print sysrootUse
noneto rely on environment variables (RUSTCorPATH)Provide a specific path (e.g.,
$HOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu)
Optionally set
sysroot_src_pathto the location of Rust standard library source code. If not specified, the tool will attempt to automatically locate or install the sources usingrustup component add rust-src.Note
If the project uses crates from the Rust standard library (e.g.
std,core,alloc), source code for these libraries should be available, otherwise the analysis will be incomplete.
Configure proc-macro settings:
Set
enable_proc_macrostotrue(default) to enable expansion of proc macros.Optionally set
proc_macro_server_pathto specify a custom rust-analyzer compatible proc-macro server. If not set, the tool will use the proc-macro server from the configured sysroot.
Configure build settings:
Set
run_build_scriptstotrue(default) to executebuild.rsscripts in the workspace.Set
build_pathto specify the build output directory (default:target).Use
cargo_argsto pass additional arguments to cargo commands.Use
cargo_envto set additional environment variables for cargo execution.
Configure feature settings:
Set
enable_all_featurestotrueto enable all available features (overrides thefeatureslist).Use the
featureslist to specify which cargo features to enable.
Configure analyses and additional build steps, as necessary. Note that not every rule is applicable to Rust. See Features for more information.
6.4.3.4. Features¶
AxivionRustFrontend produces an RFG that the Axivion Suite uses to provide the following additional features:
Architecture Analysis
Cycle Detection (RFG-based)
Dead Code Detection (RFG-based)
Metrics (see Metrics)
Some MISRA rules for Rust
FFI Signature Checking
Entry Point Configuration for Dead Code Analysis¶
The following additional entry point configurations are supported. Entry point configuration allows addition of extra routines to the RFG Entries view. These entry points are used during Dead Code Analysis.
EntryPoints-EntriesByAttribute: Note: the entire attribute text is matched, including parameters. For example, to match alltask`attributes, where the actual text may be#[task(priority = 1)], use a trailing wildcard:task*.EntryPoints-EntriesByLinknameEntryPoints-EntriesByNameEntryPoints-EntriesByPathEntryPoints-EntriesByMacro
MISRA Rules for Rust¶
The Rust analysis supports the following MISRA-C 2012 directives adapted for Rust:
MisraC2012Directive-4.2: All usage of assembly language should be documented (detects
asm!,global_asm!, etc.)MisraC2012Directive-4.3: Assembly language shall be encapsulated and isolated
FFI Signature Checking¶
The Rust-CheckExternSignatures rule can be used with RFGs that contain merged C/C++
and Rust nodes to detect mismatches in Foreign Function Interface (FFI) signatures
declared in Rust. This analysis can identify differences in number of parameters,
type of parameters and return type between Rust FFI declarations and their C/C++
implementations.