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:

  1. Set /Project/directory to the repository root.

  2. Set /Project/name to the name of the project.

  3. Set /Results/Dashboard/dashboard_url to the URL where the Axivion Dashboard is hosted.

  4. If /Results/Dashboard/database_mode is shared_database, set the environment variable AXIVION_DATABASES_DIR to the correct location.

Setup of AxivionRustFrontend

  1. Create a new copy of the AxivionRustFrontend action.

  2. Set manifest_path to the path of the main Cargo.toml file for your Rust workspace or project.

  3. Configure the Rust toolchain settings:

  1. Set sysroot_path to the Rust toolchain directory:

  • Use discover (default) to automatically detect the sysroot using rustc --print sysroot

  • Use none to rely on environment variables (RUSTC or PATH)

  • Provide a specific path (e.g., $HOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu)

  1. Optionally set sysroot_src_path to the location of Rust standard library source code. If not specified, the tool uses the directory given by the environment variable RUST_SRC_PATH or, if that is not set, lib/rustlib/src/rust/library in the sysroot. If the sources are missing and sysroot_path is discover, the tool attempts to install them using rustup component add rust-src. If sysroot_path is none, 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.

  1. Configure proc-macro settings:

  1. Set enable_proc_macros to true (default) to enable expansion of proc macros.

  2. Optionally set proc_macro_server_path to specify a custom rust-analyzer-compatible proc-macro server. If not set, the tool will use the proc-macro server from the configured sysroot.

  1. Configure build settings:

  1. Set run_build_scripts to true (default) to execute build.rs scripts in the workspace.

  2. Set build_path to specify the build output directory (default: target).

  3. Use cargo_args to pass additional arguments to Cargo commands.

  4. Use cargo_env to set additional environment variables for Cargo execution.

  1. Configure feature settings:

  1. Set enable_all_features to true to enable all available features (overrides the features list).

  2. Use the features list to specify which Cargo features to enable. The default is default, which enables the default features; a list without default disables them.

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

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.