Skip to content

Commit

Permalink
refactor(ci): improve rustfmt perf and cleanup (#2779)
Browse files Browse the repository at this point in the history
- Install nightly through moonrepo, so it'll be cached.
- Always run rustfmt on --all for both push/pull.
It doesn't compile anything and runs on `--all` in a few seconds.

Benchmark: seems to reduce time from ~15 seconds to ~5 seconds, and
logs indeed show that nothing is installed, only rustfmt is run.

Unrelated: remove clippy/rustfmt from the components in
rust-toolchain.toml, when using the `default` profile they are already
included.

Co-Authored-By: Gilad Chase <[email protected]>
  • Loading branch information
giladchase and Gilad Chase authored Dec 20, 2024
1 parent 95f04ef commit 4ccbf3a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 25 deletions.
10 changes: 10 additions & 0 deletions .github/actions/bootstrap/action.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
name: Bootstrap
description: Install dependencies.

inputs:
extra_rust_toolchains:
description: "Extra toolchains to install, but aren't used by default"
required: false

runs:
using: "composite"
steps:
Expand All @@ -7,5 +15,7 @@ runs:
shell: bash
- name: Install rust.
uses: ./.github/actions/install_rust
with:
extra_rust_toolchains: ${{ inputs.extra_rust_toolchains }}
- name: Install cairo native.
uses: ./.github/actions/setup_native_deps
9 changes: 8 additions & 1 deletion .github/actions/install_rust/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: Bootsrap rust installation
name: Bootstrap rust installation
description: Setup rust environment and its components, also caching the build results.

inputs:
extra_rust_toolchains:
description: "Extra toolchains to install, but aren't used by default"
required: false

runs:
using: "composite"
steps:
Expand All @@ -9,5 +14,7 @@ runs:
cache-base: main(-v[0-9].*)?
inherit-toolchain: true
bins: [email protected], cargo-machete
# Install additional non-default toolchains (for rustfmt for example), NOP if input omitted.
channel: ${{ inputs.extra_rust_toolchains }}
env:
RUSTFLAGS: "-C link-arg=-fuse-ld=lld"
14 changes: 8 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ on:
env:
CI: 1
RUSTFLAGS: "-D warnings -C link-arg=-fuse-ld=lld"
EXTRA_RUST_TOOLCHAINS: nightly-2024-04-29

# On PR events, cancel existing CI runs on this same PR for this workflow.
concurrency:
Expand Down Expand Up @@ -49,6 +50,8 @@ jobs:

# Install rust components.
- uses: ./.github/actions/bootstrap
with:
extra_rust_toolchains: ${{ env.EXTRA_RUST_TOOLCHAINS }}

- name: Setup Python venv
run: |
Expand All @@ -62,9 +65,6 @@ jobs:
git diff --exit-code Cargo.lock
# Run code style on PR.
- name: "Run rustfmt pull request"
if: github.event_name == 'pull_request'
run: ci/bin/python scripts/run_tests.py --command rustfmt --changes_only --commit_id ${{ github.event.pull_request.base.sha }}
- name: "Run clippy pull request"
if: github.event_name == 'pull_request'
run: ci/bin/python scripts/run_tests.py --command clippy --changes_only --commit_id ${{ github.event.pull_request.base.sha }}
Expand All @@ -73,9 +73,11 @@ jobs:
run: ci/bin/python scripts/run_tests.py --command doc --changes_only --commit_id ${{ github.event.pull_request.base.sha }}

# Run code style on push.
- name: "Run rustfmt on push"
if: github.event_name == 'push'
run: ci/bin/python scripts/run_tests.py --command rustfmt
- name: "Run rustfmt"
# The nightly here is coupled with the one in install_rust/action.yml.
# If we move the install here we can use a const.
run: cargo +"$EXTRA_RUST_TOOLCHAINS" fmt --all -- --check

- name: "Run clippy on push"
if: github.event_name == 'push'
run: ci/bin/python scripts/run_tests.py --command clippy
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "1.83"
components = ["clippy", "rustc-dev", "rustfmt"]
components = ["rustc-dev"]
profile = "default"
targets = ["x86_64-unknown-linux-gnu"]
4 changes: 0 additions & 4 deletions scripts/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
class BaseCommand(Enum):
TEST = "test"
CODECOV = "codecov"
RUSTFMT = "rustfmt"
CLIPPY = "clippy"
DOC = "doc"

Expand All @@ -39,9 +38,6 @@ def cmd(self, crates: Set[str]) -> List[str]:
"--output-path",
"codecov.json",
] + package_args
elif self == BaseCommand.RUSTFMT:
fmt_args = package_args if len(package_args) > 0 else ["--all"]
return ["scripts/rust_fmt.sh"] + fmt_args + ["--", "--check"]
elif self == BaseCommand.CLIPPY:
clippy_args = package_args if len(package_args) > 0 else ["--workspace"]
return ["cargo", "clippy"] + clippy_args + ["--all-targets"]
Expand Down
13 changes: 0 additions & 13 deletions scripts/rust_fmt.sh

This file was deleted.

0 comments on commit 4ccbf3a

Please sign in to comment.