Skip to content

Commit 9773a4a

Browse files
committed
implement x run rustfmt
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent 16fc26c commit 9773a4a

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/bootstrap/src/core/build_steps/run.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,48 @@ impl Step for CyclicStep {
392392
builder.ensure(CyclicStep { n: self.n.saturating_sub(1) })
393393
}
394394
}
395+
396+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
397+
pub struct Rustfmt;
398+
399+
impl Step for Rustfmt {
400+
type Output = ();
401+
const ONLY_HOSTS: bool = true;
402+
403+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
404+
run.path("src/tools/rustfmt")
405+
}
406+
407+
fn make_run(run: RunConfig<'_>) {
408+
run.builder.ensure(Rustfmt);
409+
}
410+
411+
fn run(self, builder: &Builder<'_>) {
412+
let host = builder.build.build;
413+
let stage = builder.top_stage;
414+
415+
if stage == 0 {
416+
eprintln!("rustfmt cannot be run at stage 0");
417+
std::process::exit(1);
418+
}
419+
420+
let compiler = builder.compiler(stage, host);
421+
let rustfmt_build = builder.ensure(tool::Rustfmt { compiler, target: host });
422+
423+
let mut rustfmt = tool::prepare_tool_cargo(
424+
builder,
425+
rustfmt_build.build_compiler,
426+
Mode::ToolRustc,
427+
host,
428+
Kind::Run,
429+
"src/tools/rustfmt",
430+
SourceType::InTree,
431+
&[],
432+
);
433+
434+
rustfmt.args(["--bin", "rustfmt", "--"]);
435+
rustfmt.args(builder.config.args());
436+
437+
rustfmt.into_cmd().run(builder);
438+
}
439+
}

src/bootstrap/src/core/builder/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,7 @@ impl<'a> Builder<'a> {
11141114
run::UnicodeTableGenerator,
11151115
run::FeaturesStatusDump,
11161116
run::CyclicStep,
1117+
run::Rustfmt,
11171118
),
11181119
Kind::Setup => {
11191120
describe!(setup::Profile, setup::Hook, setup::Link, setup::Editor)

0 commit comments

Comments
 (0)