diff --git a/.github/actions/bootstrap/action.yml b/.github/actions/bootstrap/action.yml index 61e542a163..c4b8a49c9f 100644 --- a/.github/actions/bootstrap/action.yml +++ b/.github/actions/bootstrap/action.yml @@ -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: @@ -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 diff --git a/.github/actions/install_rust/action.yml b/.github/actions/install_rust/action.yml index 0879a631b4..f140e6a3b2 100644 --- a/.github/actions/install_rust/action.yml +++ b/.github/actions/install_rust/action.yml @@ -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: @@ -9,5 +14,7 @@ runs: cache-base: main(-v[0-9].*)? inherit-toolchain: true bins: taplo-cli@0.9.0, 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" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dc047166b4..929b413a22 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: @@ -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: | @@ -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 }} @@ -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 diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 69c659ad89..54b889c61b 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] channel = "1.83" -components = ["clippy", "rustc-dev", "rustfmt"] +components = ["rustc-dev"] profile = "default" targets = ["x86_64-unknown-linux-gnu"] diff --git a/scripts/run_tests.py b/scripts/run_tests.py index 8f604a8d27..574adf1520 100755 --- a/scripts/run_tests.py +++ b/scripts/run_tests.py @@ -19,7 +19,6 @@ class BaseCommand(Enum): TEST = "test" CODECOV = "codecov" - RUSTFMT = "rustfmt" CLIPPY = "clippy" DOC = "doc" @@ -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"] diff --git a/scripts/rust_fmt.sh b/scripts/rust_fmt.sh deleted file mode 100755 index 4478e594e9..0000000000 --- a/scripts/rust_fmt.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# Install toolchain if missing (local run). -TOOLCHAIN="nightly-2024-04-29" - -function install_rustfmt() { - rustup toolchain install ${TOOLCHAIN} - rustup component add --toolchain ${TOOLCHAIN} rustfmt -} - -rustup toolchain list | grep -q ${TOOLCHAIN} || install_rustfmt - -cargo +${TOOLCHAIN} fmt $@