Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/check_diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 38 additions & 1 deletion check_diff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, Self::Err> {
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),
Expand Down Expand Up @@ -572,13 +603,16 @@ pub fn build_rustfmt_from_src<T: AsRef<str>>(
edition: Edition,
style_edition: StyleEdition,
config: Option<&[T]>,
release_channel: ReleaseChannel,
) -> Result<RustfmtRunner, CheckDiffError> {
// 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()
Expand Down Expand Up @@ -611,6 +645,7 @@ pub fn compile_rustfmt<T: AsRef<str>>(
style_edition: StyleEdition,
commit_hash: Option<String>,
config: Option<&[T]>,
release_channel: ReleaseChannel,
) -> Result<DiffChecker<RustfmtRunner, RustfmtRunner>, CheckDiffError> {
const RUSTFMT_REPO: &str = "https://github.com/rust-lang/rustfmt.git";
let checkout_ref = commit_hash.as_ref().unwrap_or(&feature_branch);
Expand All @@ -628,6 +663,7 @@ pub fn compile_rustfmt<T: AsRef<str>>(
edition,
style_edition,
config,
release_channel,
)?;
let should_detach = commit_hash.is_some();
git_switch(checkout_ref, should_detach)?;
Expand All @@ -638,6 +674,7 @@ pub fn compile_rustfmt<T: AsRef<str>>(
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();
Expand Down
6 changes: 5 additions & 1 deletion check_diff/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ExitCode, Error> {
Expand All @@ -85,6 +88,7 @@ fn main() -> Result<ExitCode, Error> {
args.style_edition,
args.commit_hash,
args.rustfmt_config.as_deref(),
args.release_channel,
);

let diff_checker = match compilation_result {
Expand Down