This repository contains the code for "Building a Rust static analysis tool in a weekend", a blogpost that summarize what I learned while developping cargo-breaking.
More specifically, there are three "compilers" in this repository:
simple_rustc_wrapper
, which explains how Cargo interacts with Rustc,bundled_rustc_wrapper
, which explains how to use Rustc as a library,analysis_compiler
, which explains how to actually perform static analysis.
Both bundled_rustc_wrapper
and analysis_compiler
require the nightly
toolchain and a few other components to be installed. In order to guarantee
future compatibility, we will use nightly
toolchain:
$ rustup install nightly
$ rustup component add --toolchain nightly rust-src rustc-dev llvm-tools-preview
Everything can be built with the following command:
$ cargo build
In the following commands, substitute <COMPILER>
with one of the compilers
included in this repository.
First the compiler must be installed:
$ cargo install --path <COMPILER>
The compiler can then be called on any Rust project by setting the
RUSTC_WRAPPER
environment variable:
$ RUSTC_WRAPPER=<COMPILER> cargo +nightly check
Note that the analysis_compiler
also requires the TARGET_CRATE
environment
variable to be set to the crate on which cargo
is currently called. See the
blogpost itself for more information.