Skip to content

Commit 052e679

Browse files
pks-tgitster
authored andcommitted
ci: check formatting of our Rust code
Introduce a CI check that verifies that our Rust code is well-formatted. This check uses rustfmt(1), which is the de-facto standard in the Rust world. The rustfmt(1) tool allows to tweak the final format in theory. In practice though, the Rust ecosystem has aligned on style "editions". These editions only exist to ensure that any potential changes to the style don't cause reformats to existing code bases. Other than that, most Rust projects out there accept this default style of a specific edition. Let's do the same and use that default style. It may not be anyone's favorite, but it is consistent and by making it part of our CI we also enforce it right from the start. Note that we don't have to pick a specific style edition here, as the edition is automatically derived from the edition we have specified in our "Cargo.toml" file. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bbb9efe commit 052e679

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

.github/workflows/main.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,21 @@ jobs:
458458
- run: ci/install-dependencies.sh
459459
- run: ci/run-static-analysis.sh
460460
- run: ci/check-directional-formatting.bash
461+
rust-analysis:
462+
needs: ci-config
463+
if: needs.ci-config.outputs.enabled == 'yes'
464+
env:
465+
jobname: RustAnalysis
466+
CI_JOB_IMAGE: ubuntu:rolling
467+
runs-on: ubuntu-latest
468+
container: ubuntu:rolling
469+
concurrency:
470+
group: rust-analysis-${{ github.ref }}
471+
cancel-in-progress: ${{ needs.ci-config.outputs.skip_concurrent == 'yes' }}
472+
steps:
473+
- uses: actions/checkout@v4
474+
- run: ci/install-dependencies.sh
475+
- run: ci/run-rust-checks.sh
461476
sparse:
462477
needs: ci-config
463478
if: needs.ci-config.outputs.enabled == 'yes'

.gitlab-ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@ static-analysis:
212212
- ./ci/run-static-analysis.sh
213213
- ./ci/check-directional-formatting.bash
214214

215+
rust-analysis:
216+
image: ubuntu:rolling
217+
stage: analyze
218+
needs: [ ]
219+
variables:
220+
jobname: RustAnalysis
221+
before_script:
222+
- ./ci/install-dependencies.sh
223+
script:
224+
- ./ci/run-rust-checks.sh
225+
215226
check-whitespace:
216227
image: ubuntu:latest
217228
stage: analyze

ci/install-dependencies.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ StaticAnalysis)
126126
sudo apt-get -q -y install coccinelle libcurl4-openssl-dev libssl-dev \
127127
libexpat-dev gettext make
128128
;;
129+
RustAnalysis)
130+
sudo apt-get -q -y install rustup
131+
rustup default stable
132+
rustup component add rustfmt
133+
;;
129134
sparse)
130135
sudo apt-get -q -y install libssl-dev libcurl4-openssl-dev \
131136
libexpat-dev gettext zlib1g-dev sparse

ci/run-rust-checks.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
. ${0%/*}/lib.sh
4+
5+
set +x
6+
7+
if ! group "Check Rust formatting" cargo fmt --all --check
8+
then
9+
RET=1
10+
fi
11+
12+
exit $RET

0 commit comments

Comments
 (0)