You've already forked comprehensive-rust
							
							
				mirror of
				https://github.com/google/comprehensive-rust.git
				synced 2025-10-31 08:37:45 +02:00 
			
		
		
		
	ci: use pinned nightly rustfmt to make unstable features take effect (#2896)
				
					
				
			## What does this PR do? This PR extends the existing `format` job in `.github/workflows/build.yml` to **check Rust formatting with nightly `rustfmt`**: **Closes #2794**
This commit is contained in:
		
							
								
								
									
										8
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
								
							| @@ -13,6 +13,8 @@ env: | ||||
| jobs: | ||||
|   format: | ||||
|     runs-on: ubuntu-latest | ||||
|     env: | ||||
|       NIGHTLY_VERSION: nightly-2025-09-01 | ||||
|     steps: | ||||
|       - name: Checkout | ||||
|         uses: actions/checkout@v5 | ||||
| @@ -22,10 +24,10 @@ jobs: | ||||
|           sudo apt update | ||||
|           sudo apt install gettext yapf3 | ||||
|  | ||||
|       - name: Install nightly rustfmt | ||||
|       - name: Install pinned nightly for rustfmt | ||||
|         run: | | ||||
|           rustup default nightly | ||||
|           rustup component add rustfmt | ||||
|           rustup toolchain install --profile minimal "$NIGHTLY_VERSION" | ||||
|           rustup component add rustfmt --toolchain "$NIGHTLY_VERSION" | ||||
|  | ||||
|       - name: Check formatting | ||||
|         uses: dprint/check@v2.3 | ||||
|   | ||||
| @@ -53,6 +53,16 @@ this: | ||||
|  | ||||
| Run `dprint fmt` to automatically format all files. | ||||
|  | ||||
| **Note:** To make sure you have the correct version of `rustfmt` installed, | ||||
| please run: | ||||
|  | ||||
| ```bash | ||||
| cargo xtask install-tools | ||||
| ``` | ||||
|  | ||||
| This will install the pinned nightly toolchain and add the `rustfmt` component, | ||||
| so your local formatting will match the CI. | ||||
|  | ||||
| ### Linux | ||||
|  | ||||
| Install `dprint` using their | ||||
|   | ||||
| @@ -9,7 +9,7 @@ | ||||
|       "command": "yapf3", | ||||
|       "exts": ["py"] | ||||
|     }, { | ||||
|       "command": "rustup run stable rustfmt --edition 2024", | ||||
|       "command": "rustup run nightly-2025-09-01 rustfmt --edition 2024", | ||||
|       "exts": ["rs"] | ||||
|     }] | ||||
|   }, | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
| # Please use a nightly rustfmt for these settings. | ||||
| unstable_features = true | ||||
| imports_granularity = "module" | ||||
| wrap_comments = true | ||||
|  | ||||
|   | ||||
| @@ -21,9 +21,9 @@ | ||||
|  | ||||
| use anyhow::{Ok, Result, anyhow}; | ||||
| use clap::{Parser, Subcommand}; | ||||
| use std::env; | ||||
| use std::path::{Path, PathBuf}; | ||||
| use std::process::Stdio; | ||||
| use std::{env, process::Command}; | ||||
| use std::process::{Command, Stdio}; | ||||
|  | ||||
| fn main() -> Result<()> { | ||||
|     if let Err(e) = execute_task() { | ||||
| @@ -49,7 +49,8 @@ enum Task { | ||||
|     InstallTools, | ||||
|     /// Runs the web driver tests in the tests directory. | ||||
|     WebTests { | ||||
|         /// Optional 'book html' directory - if set, will also refresh the list of slides used by slide size test. | ||||
|         /// Optional 'book html' directory - if set, will also refresh the list | ||||
|         /// of slides used by slide size test. | ||||
|         #[arg(short, long)] | ||||
|         dir: Option<PathBuf>, | ||||
|     }, | ||||
| @@ -61,7 +62,8 @@ enum Task { | ||||
|         #[arg(short, long)] | ||||
|         language: Option<String>, | ||||
|  | ||||
|         /// Directory to place the build. If not provided, defaults to the book/ directory (or the book/xx directory if a language is provided). | ||||
|         /// Directory to place the build. If not provided, defaults to the book/ | ||||
|         /// directory (or the book/xx directory if a language is provided). | ||||
|         #[arg(short, long)] | ||||
|         output: Option<PathBuf>, | ||||
|     }, | ||||
| @@ -71,7 +73,8 @@ enum Task { | ||||
|         #[arg(short, long)] | ||||
|         language: Option<String>, | ||||
|  | ||||
|         /// Directory to place the build. If not provided, defaults to the book/ directory (or the book/xx directory if a language is provided). | ||||
|         /// Directory to place the build. If not provided, defaults to the book/ | ||||
|         /// directory (or the book/xx directory if a language is provided). | ||||
|         #[arg(short, long)] | ||||
|         output: Option<PathBuf>, | ||||
|     }, | ||||
| @@ -91,6 +94,25 @@ fn execute_task() -> Result<()> { | ||||
|  | ||||
| fn install_tools() -> Result<()> { | ||||
|     println!("Installing project tools..."); | ||||
|  | ||||
|     const PINNED_NIGHTLY: &str = "nightly-2025-09-01"; | ||||
|  | ||||
|     let rustup_steps = [ | ||||
|         ["toolchain", "install", "--profile", "minimal", PINNED_NIGHTLY], | ||||
|         ["component", "add", "rustfmt", "--toolchain", PINNED_NIGHTLY], | ||||
|     ]; | ||||
|  | ||||
|     for args in rustup_steps { | ||||
|         let status = std::process::Command::new("rustup").args(args).status()?; | ||||
|         if !status.success() { | ||||
|             return Err(anyhow!( | ||||
|                 "Command 'rustup {}' failed with status {:?}", | ||||
|                 args.join(" "), | ||||
|                 status.code() | ||||
|             )); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     let path_to_mdbook_exerciser = | ||||
|         Path::new(env!("CARGO_WORKSPACE_DIR")).join("mdbook-exerciser"); | ||||
|     let path_to_mdbook_course = | ||||
| @@ -286,8 +308,9 @@ fn build(language: Option<String>, output_arg: Option<PathBuf>) -> Result<()> { | ||||
| } | ||||
|  | ||||
| fn get_output_dir(language: Option<String>, output_arg: Option<PathBuf>) -> PathBuf { | ||||
|     // If the 'output' arg is specified by the caller, use that, otherwise output to the 'book/' directory | ||||
|     // (or the 'book/xx' directory if a language was specified). | ||||
|     // If the 'output' arg is specified by the caller, use that, otherwise output to | ||||
|     // the 'book/' directory (or the 'book/xx' directory if a language was | ||||
|     // specified). | ||||
|     if let Some(d) = output_arg { | ||||
|         d | ||||
|     } else { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user