From 9062982937c9d7564c90660b6ecebee41c9b3cf9 Mon Sep 17 00:00:00 2001 From: Yacin Tmimi Date: Mon, 19 Jan 2026 00:19:23 -0500 Subject: [PATCH 1/3] remove `ci/check_diff.sh ` No longer needed since we're moving to the rust version. --- ci/check_diff.sh | 250 ----------------------------------------------- 1 file changed, 250 deletions(-) delete mode 100755 ci/check_diff.sh diff --git a/ci/check_diff.sh b/ci/check_diff.sh deleted file mode 100755 index 5155ec1f0be..00000000000 --- a/ci/check_diff.sh +++ /dev/null @@ -1,250 +0,0 @@ -#!/bin/bash - -set -e - -function print_usage() { - echo "usage check_diff REMOTE_REPO FEATURE_BRANCH [COMMIT_HASH] [OPTIONAL_RUSTFMT_CONFIGS]" -} - -if [ $# -le 1 ]; then - print_usage - exit 1 -fi - -REMOTE_REPO=$1 -FEATURE_BRANCH=$2 -OPTIONAL_COMMIT_HASH=$3 -OPTIONAL_RUSTFMT_CONFIGS=$4 - -# OUTPUT array used to collect all the status of running diffs on various repos -STATUSES=() - -# Clone a git repository and cd into it. -# -# Parameters: -# $1: git clone url -# $2: directory where the repo should be cloned -function clone_repo() { - GIT_TERMINAL_PROMPT=0 git clone --quiet $1 --depth 1 $2 && cd $2 -} - -# Initialize Git submodules for the repo. -# -# Parameters -# $1: list of directories to initialize -function init_submodules() { - git submodule update --init $1 -} - -# Run rusfmt with the --check flag to see if a diff is produced. -# -# Parameters: -# $1: Path to a rustfmt binary -# $2: Output file path for the diff -# $3: Any additional configuration options to pass to rustfmt -# -# Globals: -# $OPTIONAL_RUSTFMT_CONFIGS: Optional configs passed to the script from $4 -function create_diff() { - local config; - if [ -z "$3" ]; then - config="--config=error_on_line_overflow=false,error_on_unformatted=false" - else - config="--config=error_on_line_overflow=false,error_on_unformatted=false,$OPTIONAL_RUSTFMT_CONFIGS" - fi - - for i in `find . | grep "\.rs$"` - do - $1 --unstable-features --skip-children --check --color=always $config $i >> $2 2>/dev/null - done -} - -# Run the main rustfmt binary and the feature branch binary in the current directory and compare the diffs -# -# Parameters -# $1: Name of the repository (used for logging) -# -# Globals: -# $RUSFMT_BIN: Path to the rustfmt main binary. Created when running `compile_rustfmt` -# $FEATURE_BIN: Path to the rustfmt feature binary. Created when running `compile_rustfmt` -# $OPTIONAL_RUSTFMT_CONFIGS: Optional configs passed to the script from $4 -function check_diff() { - echo "running rustfmt (main) on $1" - create_diff $RUSFMT_BIN rustfmt_diff.txt - - echo "running rustfmt (feature) on $1" - create_diff $FEATURE_BIN feature_diff.txt $OPTIONAL_RUSTFMT_CONFIGS - - echo "checking diff" - local diff; - # we don't add color to the diff since we added color when running rustfmt --check. - # tail -n + 6 removes the git diff header info - # cut -c 2- removes the leading diff characters("+","-"," ") from running git diff. - # Again, the diff output we care about was already added when we ran rustfmt --check - diff=$( - git --no-pager diff --color=never \ - --unified=0 --no-index rustfmt_diff.txt feature_diff.txt 2>&1 | tail -n +6 | cut -c 2- - ) - - if [ -z "$diff" ]; then - echo "no diff detected between rustfmt and the feature branch" - return 0 - else - echo "$diff" - return 1 - fi -} - -# Compiles and produces two rustfmt binaries. -# One for the current main branch, and another for the feature branch -# -# Parameters: -# $1: Directory where rustfmt will be cloned -# -# Globals: -# $REMOTE_REPO: Clone URL to the rustfmt fork that we want to test -# $FEATURE_BRANCH: Name of the feature branch -# $OPTIONAL_COMMIT_HASH: Optional commit hash that will be checked out if provided -function compile_rustfmt() { - RUSTFMT_REPO="https://github.com/rust-lang/rustfmt.git" - clone_repo $RUSTFMT_REPO $1 - git remote add feature $REMOTE_REPO - git fetch feature $FEATURE_BRANCH - - CARGO_VERSION=$(cargo --version) - echo -e "\ncompiling with $CARGO_VERSION\n" - - # Because we're building standalone binaries we need to set `LD_LIBRARY_PATH` so each - # binary can find it's runtime dependencies. See https://github.com/rust-lang/rustfmt/issues/5675 - # This will prepend the `LD_LIBRARY_PATH` for the main rustfmt binary - export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH - - echo "Building rustfmt from src" - cargo build -q --release --bin rustfmt && cp target/release/rustfmt $1/rustfmt - - if [ -z "$OPTIONAL_COMMIT_HASH" ] || [ "$FEATURE_BRANCH" = "$OPTIONAL_COMMIT_HASH" ]; then - git switch $FEATURE_BRANCH - else - git switch $OPTIONAL_COMMIT_HASH --detach - fi - - # This will prepend the `LD_LIBRARY_PATH` for the feature branch rustfmt binary. - # In most cases the `LD_LIBRARY_PATH` should be the same for both rustfmt binaries that we build - # in `compile_rustfmt`, however, there are scenarios where each binary has different runtime - # dependencies. For example, during subtree syncs we bump the nightly toolchain required to build - # rustfmt, and therefore the feature branch relies on a newer set of runtime dependencies. - export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH - - echo "Building feature rustfmt from src" - cargo build -q --release --bin rustfmt && cp target/release/rustfmt $1/feature_rustfmt - - echo -e "\nRuntime dependencies for rustfmt -- LD_LIBRARY_PATH: $LD_LIBRARY_PATH" - - RUSFMT_BIN=$1/rustfmt - RUSTFMT_VERSION=$($RUSFMT_BIN --version) - echo -e "\nRUSFMT_BIN $RUSTFMT_VERSION\n" - - FEATURE_BIN=$1/feature_rustfmt - FEATURE_VERSION=$($FEATURE_BIN --version) - echo -e "FEATURE_BIN $FEATURE_VERSION\n" -} - -# Check the diff for running rustfmt and the feature branch on all the .rs files in the repo. -# -# Parameters -# $1: Clone URL for the repo -# $2: Name of the repo (mostly used for logging) -# $3: Path to any submodules that should be initialized -function check_repo() { - WORKDIR=$(pwd) - REPO_URL=$1 - REPO_NAME=$2 - SUBMODULES=$3 - - local tmp_dir; - tmp_dir=$(mktemp -d -t $REPO_NAME-XXXXXXXX) - clone_repo $REPO_URL $tmp_dir - - if [ ! -z "$SUBMODULES" ]; then - init_submodules $SUBMODULES - fi - - - # rustfmt --check returns 1 if a diff was found - # Also check_diff returns 1 if there was a diff between main rustfmt and the feature branch - # so we want to ignore the exit status check - set +e - check_diff $REPO_NAME - # append the status of running `check_diff` to the STATUSES array - STATUSES+=($?) - set -e - - echo -e "removing tmp_dir $tmp_dir\n\n" - rm -rf $tmp_dir - cd $WORKDIR -} - -# Log the inputs the script was invoked with in CI to aid diagnosing Diff Check failures. -function log_inputs() { - echo "::group::Diff Check inputs" - echo "Remote repo:" - echo "$REMOTE_REPO" - echo "Feature branch:" - echo "$FEATURE_BRANCH" - echo "(Optional) Commit hash:" - echo "$OPTIONAL_COMMIT_HASH" - echo "(Optional) Rustfmt configs:" - echo "$OPTIONAL_RUSTFMT_CONFIGS" - echo "::endgroup::" -} - -function main() { - log_inputs - - tmp_dir=$(mktemp -d -t rustfmt-XXXXXXXX) - echo Created tmp_dir $tmp_dir - - compile_rustfmt $tmp_dir - - # run checks - check_repo "https://github.com/rust-lang/rust.git" rust-lang-rust - check_repo "https://github.com/rust-lang/cargo.git" cargo - check_repo "https://github.com/rust-lang/miri.git" miri - check_repo "https://github.com/rust-lang/rust-analyzer.git" rust-analyzer - check_repo "https://github.com/bitflags/bitflags.git" bitflags - check_repo "https://github.com/rust-lang/log.git" log - check_repo "https://github.com/rust-lang/mdBook.git" mdBook - check_repo "https://github.com/rust-lang/packed_simd.git" packed_simd - check_repo "https://github.com/rust-lang/rust-semverver.git" check_repo - check_repo "https://github.com/Stebalien/tempfile.git" tempfile - check_repo "https://github.com/rust-lang/futures-rs.git" futures-rs - check_repo "https://github.com/dtolnay/anyhow.git" anyhow - check_repo "https://github.com/dtolnay/thiserror.git" thiserror - check_repo "https://github.com/dtolnay/syn.git" syn - check_repo "https://github.com/serde-rs/serde.git" serde - check_repo "https://github.com/rust-lang/rustlings.git" rustlings - check_repo "https://github.com/rust-lang/rustup.git" rustup - check_repo "https://github.com/SergioBenitez/Rocket.git" Rocket - check_repo "https://github.com/rustls/rustls.git" rustls - check_repo "https://github.com/rust-lang/rust-bindgen.git" rust-bindgen - check_repo "https://github.com/hyperium/hyper.git" hyper - check_repo "https://github.com/actix/actix.git" actix - check_repo "https://github.com/denoland/deno.git" denoland_deno - - # cleanup temp dir - echo removing tmp_dir $tmp_dir - rm -rf $tmp_dir - - # figure out the exit code - for status in ${STATUSES[@]} - do - if [ $status -eq 1 ]; then - echo "formatting diff found 💔" - return 1 - fi - done - - echo "no diff found 😊" -} - -main From 1c7559d5f08c449a53c67a787936220f184b9d36 Mon Sep 17 00:00:00 2001 From: Yacin Tmimi Date: Mon, 19 Jan 2026 00:20:15 -0500 Subject: [PATCH 2/3] call the rust check_diff binary from `.github/workflows/check_diff.yml` Now we're calling our rust binary instead of our old shell script. --- .github/workflows/check_diff.yml | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/check_diff.yml b/.github/workflows/check_diff.yml index 6f139a4ace2..436e878a43c 100644 --- a/.github/workflows/check_diff.yml +++ b/.github/workflows/check_diff.yml @@ -23,11 +23,25 @@ jobs: - name: checkout uses: actions/checkout@v4 - - name: install rustup + - name: Build check_diff binary + working-directory: ./check_diff + run: cargo build --release + + - name: Run Diff Check + working-directory: ./check_diff + env: + CHECK_DIFF_LOG: info + shell: bash run: | - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup-init.sh - sh rustup-init.sh -y --default-toolchain none - rustup target add x86_64-unknown-linux-gnu + OPTIONS="" + + if [[ -n "${{ github.event.inputs.commit_hash }}" ]]; then + OPTIONS+="--commit-hash ${{ github.event.inputs.commit_hash }} " + fi + + if [[ -n "${{ github.event.inputs.rustfmt_configs }}" ]]; then + OPTIONS+="--rustfmt-config ${{ github.event.inputs.rustfmt_configs }} " + fi - - name: check diff - run: bash ${GITHUB_WORKSPACE}/ci/check_diff.sh ${{ github.event.inputs.clone_url }} ${{ github.event.inputs.branch_name }} ${{ github.event.inputs.commit_hash || github.event.inputs.branch_name }} ${{ github.event.inputs.rustfmt_configs }} + target/release/check_diff ${{ github.event.inputs.clone_url }} ${{ github.event.inputs.branch_name }} \ + $OPTIONS From 0a56037b89d530c289edd18508c17032b2c0ab25 Mon Sep 17 00:00:00 2001 From: Yacin Tmimi Date: Mon, 19 Jan 2026 01:03:03 -0500 Subject: [PATCH 3/3] add `language_edition` and `style_edition` to `check_diff.yml` CI This will let us test the `check_diff` binary with different combinations of Rust language edition and rustfmt style_edition. --- .github/workflows/check_diff.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/check_diff.yml b/.github/workflows/check_diff.yml index 436e878a43c..58425fa0c86 100644 --- a/.github/workflows/check_diff.yml +++ b/.github/workflows/check_diff.yml @@ -8,6 +8,24 @@ on: branch_name: description: 'Name of the feature branch on the forked repo' required: true + language_edition: + description: 'Rust language `edition` used to parse code' + required: true + default: 2015 + type: choice + options: + - 2015 + - 2018 + - 2021 + - 2024 + style_edition: + description: 'rustfmt `style_edition` used when formatting code.' + required: true + default: 2021 + type: choice + options: + - 2021 # 2015, 2018, and 2021 are all formatted the same since `style_edition` was added between 2021 and 2024 + - 2024 commit_hash: description: 'Optional commit hash from the feature branch' required: false @@ -44,4 +62,6 @@ jobs: fi target/release/check_diff ${{ github.event.inputs.clone_url }} ${{ github.event.inputs.branch_name }} \ + --edition ${{ github.event.inputs.language_edition }} \ + --style-edition ${{ github.event.inputs.style_edition }} \ $OPTIONS