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¶
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:
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.
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:
Cargo Project
The project must be a Cargo project with a
Cargo.tomlmanifest file in its root directory. This is essential because AxivionRustFrontend uses Cargo to resolve dependencies and build configuration.Command-Line Build
The project must be buildable from the command line using:
cargo buildVerify 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 |
|---|---|
|
Should point to the directory containing your Axivion configuration files (the one you created in Step 2). |
|
Should point to the URL of your Axivion Dashboard instance. |
|
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 |
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:
Launch the configuration tool:
axivion_config axivion\axivion_config.json
Set the following properties:
Project Directory (
/Project/directory):Set this to your repository root directory.
Example:
C:\projects\MyProjector/home/user/projects/MyProjectProject Name (
/Project/name):Set a unique name for your project.
Example:
MyProjectAlternatively, you can set the project name using the
AXIVION_PROJECT_NAMEenvironment variable.
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/VCSIntegrationand 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.
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_modeproperty tomanaged_upload. You should supply the necessary dashboard credentials by setting the environment variablesAXIVION_USERNAMEandAXIVION_PASSWORD. If the variables are not properly set, theaxivion_citool will prompt you to provide the credentials when the script is run.To configure an unmanaged project, set the
/Results/Dashboard/database_modeproperty toshared_databaseand set theAXIVION_DATABASES_DIRenvironment 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/authenticationand/Results/Dashboard/ci_mode/directory.Review the example defaults in
/Analysis/GlobalOptions/global_excludesand 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.
Configure the Rust build step to use the correct input files and build settings for your project: Navigate to BuildSystemIntegration and adapt the
AxivionRustFrontendbuild action to build your project. The minimal required adaptation is:Manifest Path (
manifest_path, required):Path to the main
Cargo.tomlfile for your Rust workspace or project.Example:
Cargo.tomlorcrates/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:
In the
BuildSystemIntegrationsection, add and enable aRustClippyIntegrationaction.Set the
manifest_pathto point to your project’sCargo.toml.Optionally configure additional Clippy arguments using the
clippy_argsproperty.
3.4.5. References¶
For more detailed information, refer to these resources:
Rust Tool Reference: Source Code Analysis for Rust
Running Analyses with :tool:`axivion_ci`: axivion_ci
Cross-Language Analysis: Cross-Language Analysis Setup Guide
Analysis Configuration Reference: Analysis Configuration Reference