-
Notifications
You must be signed in to change notification settings - Fork 6
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 runThis will build and run the executable.
To run tests:
$ cargo testAlternatively, you can build the executable like so
$ cargo buildIt 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 clippyIn 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 warningsThis 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.