3.4. Source Code Analysis Setup Guide for Rust

This guide provides step-by-step instructions for setting up Axivion architecture and static code analysis for Rust projects. It assumes that you already have a working Axivion Suite installation and have configured an instance of the Axivion Dashboard Server.

3.4.1. Overview

Rust Analysis CI Overview

Diagram illustrating the Rust analysis CI workflow with Axivion

Unlike conventional static code analysis tools/linters, the Axivion Suite not only performs analyses at the source code level, it also extracts a model of the code and its dependencies. This abstraction is called “Resource Flow Graph” (RFG). A detailed description of the contents of an RFG for the Rust programming language is available in Language Representation for Rust.

The build integration of the Axivion Suite for Rust works by analyzing Cargo manifest files (Cargo.toml). AxivionRustFrontend uses Cargo’s metadata to extract source files and dependencies. These inputs are then processed to perform the various analyses and to create the RFG.

3.4.2. Prerequisites

3.4.2.1. System Requirements

Before setting up Axivion analysis for Rust, ensure your system meets the following requirements, in addition to installing the Axivion Suite and setting up the Axivion Dashboard Server:

  1. Rust Toolchain

    Cargo (Rust’s package manager and build tool) must be installed. The recommended way to install Rust and Cargo is through rustup.

    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.

  2. Rust Standard Library Source

    For complete analysis, the Rust standard library source code should be available. If not present, the tool will attempt to install it using:

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

3.4.2.2. Project Requirements

Your Rust project must meet these criteria:

  1. Cargo Project

    The project must be a Cargo project with a Cargo.toml manifest file in its root directory. This is essential because AxivionRustFrontend uses Cargo to resolve dependencies and build configuration.

  2. Command-Line Build

    The project must be buildable from the command line using:

    cargo build
    

    Verify that your project builds successfully before proceeding with the analysis setup.

3.4.3. Initial Setup

Note

The Axivion setup wizard does not currently support Rust projects. You must configure Rust analysis manually as described in this guide.

Step 1: Verify Your Build

Before configuring Axivion, ensure your project builds successfully from the command line:

cargo build

If the build fails, resolve all build issues before proceeding with the project setup.

Step 2: Create Configuration Directory And Copy Example Configuration

Create a dedicated directory for Axivion configuration files in your project repository and copy the example Rust configuration files from the Axivion Suite installation subdirectory example/projectconfig/rust to this directory.

Windows:

mkdir axivion
copy "C:\path\to\bauhaussuite\example\projectconfig\rust\*" axivion\

Linux/macOS:

mkdir -p axivion
cp /path/to/bauhaussuite/example/projectconfig/rust/* axivion/

Note

It is best practice to store all Axivion configuration files in a dedicated axivion folder within your version control system. This keeps the configuration organized and makes it easy to track changes.

These files serve as a starting point for your configuration and include settings for the Rust frontend and example analysis rules.

Step 3: Adapt The Analysis Script

Open one of the example analysis scripts (start_analysis.bat for Windows or start_analysis.sh for Linux/macOS or start_analysis.ps1 for PowerShell) and adapt it to set the required environment variables:

Name

Description

BAUHAUS_CONFIG

Should point to the directory containing your Axivion configuration files (the one you created in Step 2).

AXIVION_DASHBOARD_URL

Should point to the URL of your Axivion Dashboard instance.

AXIVION_PROJECT_NAME

Should be set to the name of your project, so that you can easily identify it in the dashboard. This can also be set in the configuration file using the /Project/name property.

Make the script executable on Linux/macOS:

chmod +x axivion/start_analysis.sh

For more information on the available built-in variables and their usage, see the Builtin Variables section of the configuration guide.

Step 4: Adapt Example Configuration for Your Project

Before configuring the Rust-specific build action, set the following global properties using axivion_config:

  1. Launch the configuration tool:

    axivion_config axivion\axivion_config.json
    
  2. Set the following properties:

    • Project Directory (/Project/directory):

      Set this to your repository root directory.

      Example: C:\projects\MyProject or /home/user/projects/MyProject

    • Project Name (/Project/name):

      Set a unique name for your project.

      Example: MyProject

      Alternatively, you can set the project name using the AXIVION_PROJECT_NAME environment variable.

  3. Configure Version Control System (VCS) integration:

    If your project is under version control, set the VCS type and repository URL to enable integration with the Axivion Dashboard.

    Go to /Project/VCSIntegration and enable the appropriate VCS (e.g., Git, Subversion). For many supported VCS, the necessary configuration will be automatically detected based on the project directory.

    In case of source code that is generated during the build and still relevant for analysis, you can enable Shadow in order to do automatic code versioning of generated code.

    For a description of the available VCS options, see VCSIntegration.

  4. Decide whether to configure the analysis as a managed (recommended) or unmanaged dashboard project:

    In a managed project the build artifacts are automatically uploaded to the dashboard and managed by the dashboard. An unmanaged project requires file-system access to the dashboard database. For more information see the Dashboard Project Configuration.

    • To configure a managed project, set the /Results/Dashboard/database_mode property to managed_upload. You should supply the necessary dashboard credentials by setting the environment variables AXIVION_USERNAME and AXIVION_PASSWORD. If the variables are not properly set, the axivion_ci tool will prompt you to provide the credentials when the script is run.

    • To configure an unmanaged project, set the /Results/Dashboard/database_mode property to shared_database and set the AXIVION_DATABASES_DIR environment variable to the path of the dashboard’s databases directory.

    Note

    You can also set the dashboard credentials and database directory directly in the configuration file using the properties in /Results/Dashboard/ci_mode/authentication and /Results/Dashboard/ci_mode/directory.

  5. Review the example defaults in /Analysis/GlobalOptions/global_excludes and add any paths that should be excluded from all analyses. For example, you may want to exclude generated code or third-party libraries. For more information on exclude options, see Exclude files from the Analysis.

  1. Configure the Rust build step to use the correct input files and build settings for your project: Navigate to BuildSystemIntegration and adapt the AxivionRustFrontend build action to build your project. The minimal required adaptation is:

    • Manifest Path (manifest_path, required):

      Path to the main Cargo.toml file for your Rust workspace or project.

      Example: Cargo.toml or crates/myproject/Cargo.toml

    For additional configuration options (toolchain settings, proc-macro settings, build settings, and feature settings), see Setup of AxivionRustFrontend.

Step 5: Run Initial Analysis

Execute your analysis script to perform the first analysis:

:: Windows
axivion\start_analysis.bat > build.log 2>&1
# Linux/macOS
./axivion/start_analysis.sh > build.log 2>&1

Monitor the output and check build.log for any errors or warnings.

3.4.4. Where To Go From Here

Once you have a working analysis build configuration, you can start customizing your analysis by enabling analysis rules:

  • For architecture verification follow the instructions in the architecture guide.

  • For clone detection follow the instructions in the clones guide.

  • For cycle detection follow the instructions in the cycles guide.

  • For dead code detection follow the instructions in the dead code guide.

  • For metrics configuration, see Metrics for available Rust metrics.

  • For cross-language analysis (e.g., Rust combined with other languages), see Cross-Language Analysis Setup Guide.

If you use Clippy for linting your Rust code, you can import its diagnostics into the Axivion Dashboard by enabling the RustClippyIntegration action. This allows you to have a unified view of all code issues in your project.

To configure Clippy integration:

  1. In the BuildSystemIntegration section, add and enable a RustClippyIntegration action.

  2. Set the manifest_path to point to your project’s Cargo.toml.

  3. Optionally configure additional Clippy arguments using the clippy_args property.

3.4.5. References

For more detailed information, refer to these resources: