Native implementation of source code analysis tool for Enterprise Rust Applications.
Before you begin, ensure you have met the following requirements:
- You have a Linux/MacOS/WSL machine.
- You have installed the latest version of Rustup
-
Install Rustup by running the following command:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Follow the on-screen instructions to complete the installation.
-
Open a new terminal or source the Rust environment:
source $HOME/.cargo/env
-
Ensure you have Rust installed:
rustc --version
If Rust is not installed, install it using Rustup:
rustup install stable
-
Set Rust stable as the default version:
rustup default stable
Clone the repository (if you haven't already) and navigate into the cloned directory.
Run the Cargo build command to compile the project:
cargo build --release
The binary will be built at target/release/codeanalyzer
. It may be used as follows:
Usage: ./codeanalyzer [-hvV] [--no-build] [-a=<analysisLevel>] [-i=<input>] [-o=<output>] [-s=<sourceAnalysis>]
Convert Rust binary into a comprehensive system dependency graph.
-i, --input=<input> Path to the project root directory.
-s, --source-analysis=<sourceAnalysis>
Analyze a single Rust source file instead of the project.
-o, --output=<output> Destination directory to save the output graphs. By default, the SDG formatted as JSON will be printed to the console.
-a, --analysis-level=<analysisLevel>
Level of analysis to perform. Options: 1 (for just symbol table) or 2 (for call graph). Default: 1
-v, --verbose Print logs to console.
-h, --help Show this help message and exit.
-V, --version Print version information and exit.
To generate and view the documentation for this project:
-
Generate the documentation:
cargo doc --no-deps
-
Open the generated documentation in your default web browser:
cargo doc --no-deps --open
The documentation includes detailed API reference, examples, and implementation details of the codeanalyzer library.
To install codeanalyzer
, follow these steps:
Clone the repository (if you haven't already) and navigate into the cloned directory.
Run Cargo to build and install the project:
cargo install --path . --root $HOME/.local
Assuming $HOME/.local/bin
is in your $PATH
, after installation, you can use codeanalyzer
by following the below format:
Usage: codeanalyzer [-hqV] [-i=<input>] -o=<outDir>
Convert Rust binary (*.rlib, *.so) to a dependency graph.
-h, --help Show this help message and exit.
-i, --input=<input> Path to the input Rust project or binary.
-o, --output=<outDir> Destination directory to save the output graphs.
-q, --quiet Don't print logs to console.
-V, --version Print version information and exit.
-
After making a few code changes, my native binary gives random exceptions. But, my code works perfectly in debug mode.
The dependency graph may be out of sync. Please follow the below instructions:
a. Build the release version using
cargo build --release
b. Run the following command:
RUST_BACKTRACE=1 ./target/release/codeanalyzer -i ./test_project -a 2 -v
c. Then rebuild using the installation instructions in §3.1.
The problem should be resolved.
Copyright IBM Corporation 2023, 2024, 2025
Licensed under the Apache Public License 2.0, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.