-
Notifications
You must be signed in to change notification settings - Fork 5
Rust project
This document gives information on how to initialize a Rust based project and fill out parts of the secure template that are common to when using Rust programming language.
First, make sure you have Rust and Cargo installed. In the project root run:
$ cargo run
This will build and run the executable.
To run tests:
$ cargo test
Alternatively, you can build the executable like so
$ cargo build
It will be generated in target/debug/
External libraries are listed in cargo.toml.
Before accepting a PR that can affect build or unit tests, make sure the following sequence of commands succeeds:
$ cargo check
$ cargo fmt
$ cargo clippy
In a project root create .github/workflows/ci.yml
with the following content:
on: [push, pull_request]
name: ci
jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: check
test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
This is a good starting script which can evolve with the complexity of the project. The Github actions will be automatically triggered on a pull request, executing the build process, linter and tests.