The daemon is written in Rust. Rust uses two cli tools for its build: rustup and cargo.
Rustup is rust's toolchain manager. Rust ships stable, beta, and nightly versions of the compiler and standard library. This project uses stable, but some of the tooling uses the nightly compiler. Rustup is used to update the compiler, and switch the active toolchain. You will use rustup infrequently.
To install rustup, visit https://www.rustup.rs and follow the instructions.
To install or update the compiler:
rustup update stable
The tooling also requires the nightly compiler:
rustup update nightly
sudo apt-get update
sudo apt-get install -y git cmake build-essential curl libcurl4-openssl-dev libssl-dev uuid-dev pkg-config
Cargo is the build tool for rust. You will use cargo frequently. It manages the build of the project, downloading dependencies, testing, etc. You can read more about cargo and it's capabilities in the cargo book.
To build the project, use:
cargo build --all
To test the project, use:
cargo test --all
Rust has a few tools that help in day to day development.
Cargo supports a formatting tool to automatically format the source code.
Install it with:
rustup component add rustfmt-preview
Run it with:
cargo fmt --all
By default, this will update the source files with newly formatted source files. Cargo fmt is also run as a checkin gate to prevent code from being checked in that doesn't meet the style guidelines.
Clippy is a linting tool for rust. It provides suggestions for more idiomatic rust code.
Install it with:
rustup component add clippy-preview --toolchain=nightly
Run it with:
cargo +nightly clippy --all
Clippy is also run as a checkin gate.
We use YAML for our swagger definitions. You can edit the definitions in VS code, but https://editor.swagger.io is also an invaluable tool for validation, converting YAML -> JSON for code-gen, etc.
We use a modified version of swagger-codegen
to generate code from our swagger definitions. To build the tool:
git clone -b support-rust-uds https://github.com/avranju/swagger-codegen.git
cd swagger-codegen
mvn clean package
To run the tool, for example to update our workload API:
java -jar swagger-codegen-cli.jar generate -i api/workload.yaml -l rust -o {root}/edgelet/workload
Note that
cargo fmt
andcargo clippy
will complain about the code produced by this tool. We like to keep all code in our repo clean, so you'll want to run clippy and fmt over the generated code, make the recommended changes, and carefully inspect the diffs of modified files before checking in.
VS Code has good support for rust. Consider installing the following extensions:
- Rust - Syntax highlighting and intellisense support
- Better TOML - Syntax highlighting for Cargo.toml
- C/C++ - Native debugger support
- Vim - For a more sophisticated editor experience :)
There is a launch.json
configuration in this repo to setup debugging on Windows. This should work out of the box.
- The Book - The Rust Programming Language
- RUST Api Guidelines - Guidelines on naming conventions, organization, etc.