From 37064d38059353fa6e203335d2d56562cdd34a04 Mon Sep 17 00:00:00 2001 From: Yacin Tmimi Date: Thu, 27 Aug 2026 23:48:33 -0400 Subject: [PATCH 1/2] feature (Diff Check): add CLI option to configure the release channel Now we can configure which release channel the compiled rustfmt should target. Because `CFG_RELEASE_CHANNEL` wasn't getting set before we'd default to the `nightly` channel. For the most part that's not really an issue, but because we're using the diff check to ensure that we're not changing stable formatting it's more appropriate to default builds to the `stable` release channel. --- check_diff/src/lib.rs | 39 ++++++++++++++++++++++++++++++++++++++- check_diff/src/main.rs | 6 +++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/check_diff/src/lib.rs b/check_diff/src/lib.rs index 4d3933257dc..9578a2e19c0 100644 --- a/check_diff/src/lib.rs +++ b/check_diff/src/lib.rs @@ -79,6 +79,37 @@ impl FromStr for StyleEdition { } } +/// Configure which release channel to use when compiling rustfmt +#[derive(Debug, Clone, Copy)] +pub enum ReleaseChannel { + Stable, + Beta, + Nightly, +} + +impl ReleaseChannel { + fn as_str(&self) -> &str { + match self { + Self::Stable => "stable", + Self::Beta => "beta", + Self::Nightly => "nightly", + } + } +} + +impl FromStr for ReleaseChannel { + type Err = String; + + fn from_str(s: &str) -> Result { + match s { + "stable" => Ok(Self::Stable), + "beta" => Ok(Self::Beta), + "nightly" => Ok(Self::Nightly), + _ => Err(format!("Invalid release channel {s}")), + } + } +} + pub enum FormatCodeError { // IO Error when running code formatter Io(std::io::Error), @@ -572,13 +603,16 @@ pub fn build_rustfmt_from_src>( edition: Edition, style_edition: StyleEdition, config: Option<&[T]>, + release_channel: ReleaseChannel, ) -> Result { // Because we're building standalone binaries we need to set the dynamic library path // so each rustfmt binary can find it's runtime dependencies. let dynamic_library_path = get_dynamic_library_path(dir)?; + let release_channel = release_channel.as_str(); - info!("Building rustfmt from source"); + info!("Building {} rustfmt from source", release_channel); let Ok(_) = Command::new("cargo") + .env("CFG_RELEASE_CHANNEL", release_channel) .current_dir(dir) .args(["build", "-q", "--release", "--bin", "rustfmt"]) .output() @@ -611,6 +645,7 @@ pub fn compile_rustfmt>( style_edition: StyleEdition, commit_hash: Option, config: Option<&[T]>, + release_channel: ReleaseChannel, ) -> Result, CheckDiffError> { const RUSTFMT_REPO: &str = "https://github.com/rust-lang/rustfmt.git"; let checkout_ref = commit_hash.as_ref().unwrap_or(&feature_branch); @@ -628,6 +663,7 @@ pub fn compile_rustfmt>( edition, style_edition, config, + release_channel, )?; let should_detach = commit_hash.is_some(); git_switch(checkout_ref, should_detach)?; @@ -638,6 +674,7 @@ pub fn compile_rustfmt>( edition, style_edition, config, + release_channel, )?; info!("SOURCE_BIN {}", source_runner.get_binary_version()?); let dynamic_library_path_env_var = dynamic_library_path_env_var_name(); diff --git a/check_diff/src/main.rs b/check_diff/src/main.rs index 812179d3417..c48280f254d 100644 --- a/check_diff/src/main.rs +++ b/check_diff/src/main.rs @@ -2,7 +2,8 @@ use std::io::Error; use std::process::ExitCode; use check_diff::{ - Edition, StyleEdition, check_diff, clone_repositories_for_diff_check, compile_rustfmt, + Edition, ReleaseChannel, StyleEdition, check_diff, clone_repositories_for_diff_check, + compile_rustfmt, }; use clap::Parser; use tempfile::tempdir; @@ -67,6 +68,8 @@ struct CliInputs { // Choosing 16 as the default since that's a common multiple of available CPU cores. #[arg(short, long, default_value_t = std::num::NonZeroU8::new(16).unwrap())] worker_threads: std::num::NonZeroU8, + #[arg(long, default_value = "stable")] + release_channel: ReleaseChannel, } fn main() -> Result { @@ -85,6 +88,7 @@ fn main() -> Result { args.style_edition, args.commit_hash, args.rustfmt_config.as_deref(), + args.release_channel, ); let diff_checker = match compilation_result { From 7376a6ad5e63aa807834ed02cda138c6ed3c57b1 Mon Sep 17 00:00:00 2001 From: Yacin Tmimi Date: Thu, 27 Aug 2026 23:55:01 -0400 Subject: [PATCH 2/2] feature (Diff Check): allow user's to set `release_channel` for check_diff.yml The `release_channel` defaults to `stable`, but it might be nice in some cases to test different release channels. --- .github/workflows/check_diff.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/check_diff.yml b/.github/workflows/check_diff.yml index 41b138acb63..38aac68b94c 100644 --- a/.github/workflows/check_diff.yml +++ b/.github/workflows/check_diff.yml @@ -32,6 +32,14 @@ on: rustfmt_configs: description: 'Optional comma separated list of rustfmt config options to pass when running the feature branch' required: false + release_channel: + description: 'Configure which release channel to use when compiling rustfmt' + default: stable + type: choice + options: + - stable + - beta + - nightly permissions: contents: read