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/directory to the repository root.
Set /Project/name to the name of the project.
Set /Results/Dashboard/dashboard_url to the URL where the Axivion Dashboard is hosted.
If /Results/Dashboard/database_mode is
shared_database, set the environment variableAXIVION_DATABASES_DIRto the correct location.
Setup of AxivionRustFrontend¶
Create a new copy of the AxivionRustFrontend action.
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 uses the directory given by the environment variableRUST_SRC_PATHor, if that is not set,lib/rustlib/src/rust/libraryin the sysroot. If the sources are missing andsysroot_pathisdiscover, the tool attempts to install them usingrustup component add rust-src. Ifsysroot_pathisnone, no standard library sources are loaded.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. The default isdefault, which enables the default features; a list withoutdefaultdisables them.
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)
Clone Detection (using RustCloneDetection)
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 the 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 all
taskattributes, where the actual text may be#[task(priority = 1)], use a trailing wildcard:task*.
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 detects mismatches in Foreign Function Interface (FFI) signatures declared in Rust. It compares the Rust declarations from AxivionRustFrontend with the routines exported by the C/C++ IR; consequently, the analysis requires both, with /Project/ir set, but no combined RFG. This analysis can identify differences in the number of parameters, the types of parameters, and the return type between Rust FFI declarations and their C/C++ implementations.