Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,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-2025-09-01
rustup component add rustfmt --toolchain nightly-2025-09-01
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this! One suggestion: could you use a variable for this so it's easier to update in a few months?

Cc @egithinji, could we use cargo xtask install-tools here? Not now, but in a later PR since this just refactors the existing install commands.


- name: Check formatting
uses: dprint/[email protected]
Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (`nightly-2025-09-01`) and add
the `rustfmt` component, so your local formatting will match the CI.

### Linux

Install `dprint` using their
Expand Down
2 changes: 1 addition & 1 deletion dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}]
},
Expand Down
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Please use a nightly rustfmt for these settings.
unstable_features = true
imports_granularity = "module"
wrap_comments = true

Expand Down
42 changes: 35 additions & 7 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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>,
},
Expand All @@ -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>,
},
Expand All @@ -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>,
},
Expand All @@ -91,6 +94,30 @@ fn execute_task() -> Result<()> {

fn install_tools() -> Result<()> {
println!("Installing project tools...");

const PINNED_NIGHTLY: &str = "nightly-2025-09-01";

let rustup_steps = [
// Installe la toolchain sans les composants inutiles
["toolchain", "install", "--profile", "minimal", PINNED_NIGHTLY],
// Ajoute rustfmt pour cette toolchain
["component", "add", "rustfmt", "--toolchain", PINNED_NIGHTLY],
];

for args in rustup_steps {
let status = std::process::Command::new("rustup")
.args(args)
.status()
.expect("Failed to execute rustup");
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 =
Expand Down Expand Up @@ -286,8 +313,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 {
Expand Down
Loading