RustQL is a prototype of Niko Matsakis' idea to use Datalog for understanding how Rust programmers write code. The initial version was developed by Nicolas Winkler. The project is currently maintained by the Programming Methodology group at ETH Zurich.
The tool consists of three parts:
- Extractor – a Rust compiler plugin that extracts the information about the crate during compilation.
- Linker – a program that merges the information about different crates into a single database.
- Query Engine – a program that takes a Datalog like query and evaluates it on the database. The engine is based on the Datafrog.
Build the extractor and prepare the environment:
cd rustql-extractor
cargo build --release
source prepare_env.shExtract information about the crate and its dependencies by compiling it:
cd <some-crate>
cargo clean
cargo buildThis will emit information about the compiled crates at ~/.rustql/crates/.
To create the database, compile the linker and run it:
cd rustql-linker
cargo run --releaseThis will create a file database.db in the current directory.
When you run a query engine, it will enter a loop in which you can provide paths to queries to you want to execute:
cd ../rustql-query/
env RUST_BACKTRACE=1 cargo run --releaseExample queries to try out:
samples/same_type.rql
samples/thief.rql
samples/unsafe.rql
This tutorial will show how to download most popular 500 crates and run a simple query over them.
git submodule update --initNote: If you are running on a server, you probably want to allocate a
larger VM by editing Vagrantfile.
Install Vagrant and start the VM:
vagrant up
vagrant sshAll remaining steps should be done inside the VM from the directory
/vagrant that is mapped to the directory on the host in which the
repository was cloned.
cd top-crates/
cargo run
cd ..cd rustql-extractor/
cargo build --release
cd ..
mkdir -p data/cache
python3 bin/run_extractor.py
rm -f /vagrant/data/crates/rustql_dummy_*
cd rustql-linker
export EXTRACTOR_TARGET_DIR=/vagrant/data/crates/
cargo run --release
cd ..cd rustql-query/
RUST_BACKTRACE=1 cargo run --release
cd ..