Computes the callgraph of rust programs.
Works with Rustc nightly 1.82.0 (`nightly-2024-08-07`). Works with full Cargo projects.
export RUSTFLAGS="-L $RUSTUP_HOME/toolchains/nightly-2024-08-07-x86_64-unknown-linux-gnu/lib"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$RUSTUP_HOME/toolchains/nightly-2024-08-07-x86_64-unknown-linux-gnu/lib"
cargo install --debug --locked --path . --force
cd ./example_code
cargo callgraph # To run on a full Cargo project
callgraph src/main.rs # To run on a single file
Using the rustc interface, run the compiler until after analysis stage, walk the expanded syntax tree and remember function and method definitions and resolved calls.
Extracts all kinds of calls:
- function defs
- struct associated impl methods
- trait method declarations
- trait method default impl
- trait method implementations
- statically dispatched calls
- dynamically dispatched calls
Missing features:
- requires a nightly toolchain (this will not change since the rustc interface will not be stabilized)
- rudimentary debugging output, no real output