Building and Testing Rust projects on CircleCI

Configure CircleCI for Rust projects.


Building and Testing Rust projects on CircleCI

Steps

  • Setup build environment (Use docker(image: ubuntu 18.04) and rustup)
  • Check code format (Use rustfmt)
  • Check a collection of lints to catch common mistakes and improve your code (Use rust-clippy)
  • Build and Test
  • Code coverage measurement (Use kcov and Codecov)

Full CircleCI configuration

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
version: 2.1
jobs:
build:
machine: true

working_directory: ~/rust-demo

steps:
- checkout
- run:
name: Setup build environment
command: |
sudo apt-get update
sudo apt-get install -y cmake binutils-dev libcurl4-openssl-dev libiberty-dev libelf-dev libdw-dev
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path --default-toolchain none -y;
no_output_timeout: 1800s
- run:
name: Format
command: |
export PATH=~/.cargo/bin:$PATH
rustup component add rustfmt
cargo fmt --all -- --check
- run:
name: Clippy
command: |
export PATH=~/.cargo/bin:$PATH
rustup component add clippy
cargo clippy --all -- -D warnings
- run:
name: Test
command: |
export PATH=~/.cargo/bin:$PATH
export RUST_BACKTRACE=1
cargo test
- run:
name: Coverage
command: |
export PATH=~/.cargo/bin:$PATH
# install kcov
cargo install cargo-kcov
cargo kcov --print-install-kcov-sh | sh
echo "Install kcov successfully"
# coverage
cargo kcov --all -v
bash <(curl -s https://codecov.io/bash)
echo "Upload code coverage successfully"

workflows:
version: 2.1
build:
jobs:
- build

Update (2019-05-07)

The personality syscall required by kcov is DISABLED by Docker, so test coverage cannot be measured… (Not fix yet, may be you can use a Machine executor instead of a Docker executor)

kcov issue #151
circleci discuss link

Update (2019-09-11)

Using machine instead of docker to repair code coverage (kcov) failed.

Use cargo-kcov subcommand to measure code coverage.

Reference

Circle CI Document