-
Notifications
You must be signed in to change notification settings - Fork 57
109 lines (105 loc) · 3.98 KB
/
_build-rust.yml
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Reusable GitHub CI workflow:
# More info: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_iduses
# Common Rust CI setup that checkout the repo, installs the common toolchain
# and set's up the cargo cache. It builds, tests, and lints the code, but is
# configurable. This way, the same workflow can be used to build, test, and lint
# all in different steps, but with the same cache.
on:
workflow_call:
inputs:
runs-on:
type: string
required: false
default: ubuntu-latest
description: |
The value for the "runs-on" property: e.g.
- ubuntu-latest
- windows-latest
rust-version:
type: string
required: false
default: stable
description: Rust version
rust-target:
type: string
required: false
default: x86_64-unknown-linux-gnu
description: Rust target for the build step. Clippy and tests are still executed with the default target.
features:
type: string
required: false
# Make sure we always an empty string to "--features <FEATURES>"
default: '""'
description: >
Comma-separated string with additional crate features. Empty string by
default. CAUTION: For Windows CI runners, this must be '""' as is,
i.e., the string itself must be "". This is a limitation of the
Windows power shell. This might be configured like this:
features: >
'""'
do-style-check:
type: boolean
required: false
default: true
description: Perform code and doc style checks.
do-test:
type: boolean
required: false
default: true
description: Execute tests.
do-miri:
type: boolean
required: false
default: false
description: Execute unit tests with miri.
jobs:
rust:
runs-on: ${{ inputs.runs-on }}
steps:
- name: Check out
uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ inputs.rust-version }}
targets: ${{ inputs.rust-target }}
components: clippy, rustfmt
- name: Set up cargo cache
uses: actions/cache@v4
continue-on-error: false
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
# Hash over Cargo.toml and Cargo.lock, as this might be copied to
# projects that do not have a Cargo.lock in their repository tree!
key: ${{ runner.os }}-rust-${{ inputs.rust-version }}-cargo-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
- run: cargo version
- name: Build (library)
run: cargo build --target ${{ inputs.rust-target }} --features ${{ inputs.features }} --no-default-features
- name: Build (all targets)
run: cargo build --all-targets --features ${{ inputs.features }} --no-default-features
- name: Code Formatting
if: inputs.do-style-check
run: cargo fmt --all -- --check
- name: "Code style: clippy"
if: inputs.do-style-check
run: cargo clippy --all-targets --features ${{ inputs.features }} --no-default-features
- name: "Code style: rustdoc"
if: inputs.do-style-check
run: cargo doc --no-deps --document-private-items --features ${{ inputs.features }} --no-default-features
- name: Unit Test
run: cargo test --verbose
- name: Unit Test with Miri
if: inputs.do-miri
run: |
rustup component add miri
# Run with stack-borrow model
# XXX Temporarily, just for multiboot2 crate.
cargo miri test -p multiboot2
# Run with tree-borrow model
# XXX Temporarily, just for multiboot2 crate.
MIRIFLAGS=-Zmiri-tree-borrows cargo +nightly miri test -p multiboot2