diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index d46c0ab7fefcf..f32d95fe8367d 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -31,8 +31,13 @@ pub struct Std { } impl Std { - pub fn new_with_build_kind(target: TargetSelection, kind: Option) -> Self { - Self { target, crates: vec![], override_build_kind: kind } + pub fn new(target: TargetSelection) -> Self { + Self { target, crates: vec![], override_build_kind: None } + } + + pub fn build_kind(mut self, kind: Option) -> Self { + self.override_build_kind = kind; + self } } @@ -167,20 +172,17 @@ pub struct Rustc { impl Rustc { pub fn new(target: TargetSelection, builder: &Builder<'_>) -> Self { - Self::new_with_build_kind(target, builder, None) - } - - pub fn new_with_build_kind( - target: TargetSelection, - builder: &Builder<'_>, - kind: Option, - ) -> Self { let crates = builder .in_tree_crates("rustc-main", Some(target)) .into_iter() .map(|krate| krate.name.to_string()) .collect(); - Self { target, crates, override_build_kind: kind } + Self { target, crates, override_build_kind: None } + } + + pub fn build_kind(mut self, build_kind: Option) -> Self { + self.override_build_kind = build_kind; + self } } @@ -216,7 +218,7 @@ impl Step for Rustc { builder.ensure(crate::core::build_steps::compile::Std::new(compiler, compiler.host)); builder.ensure(crate::core::build_steps::compile::Std::new(compiler, target)); } else { - builder.ensure(Std::new_with_build_kind(target, self.override_build_kind)); + builder.ensure(Std::new(target).build_kind(self.override_build_kind)); } let mut cargo = builder::Cargo::new( diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index 0884d86cc6d5f..518db156fea97 100644 --- a/src/bootstrap/src/core/build_steps/clippy.rs +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -215,7 +215,7 @@ impl Step for Rustc { builder.ensure(compile::Std::new(compiler, compiler.host)); builder.ensure(compile::Std::new(compiler, target)); } else { - builder.ensure(check::Std::new_with_build_kind(target, Some(Kind::Check))); + builder.ensure(check::Std::new(target).build_kind(Some(Kind::Check))); } let mut cargo = builder::Cargo::new( @@ -285,7 +285,7 @@ macro_rules! lint_any { let compiler = builder.compiler(builder.top_stage, builder.config.build); let target = self.target; - builder.ensure(check::Rustc::new_with_build_kind(target, builder, Some(Kind::Check))); + builder.ensure(check::Rustc::new(target, builder).build_kind(Some(Kind::Check))); let cargo = prepare_tool_cargo( builder, diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 6700f3ba680be..d30a0d028ff02 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -57,41 +57,20 @@ impl Std { } } - pub fn force_recompile(compiler: Compiler, target: TargetSelection) -> Self { - Self { - target, - compiler, - crates: Default::default(), - force_recompile: true, - extra_rust_args: &[], - is_for_mir_opt_tests: false, - } + pub fn force_recompile(mut self, force_recompile: bool) -> Self { + self.force_recompile = force_recompile; + self } - pub fn new_for_mir_opt_tests(compiler: Compiler, target: TargetSelection) -> Self { - Self { - target, - compiler, - crates: Default::default(), - force_recompile: false, - extra_rust_args: &[], - is_for_mir_opt_tests: true, - } + #[allow(clippy::wrong_self_convention)] + pub fn is_for_mir_opt_tests(mut self, is_for_mir_opt_tests: bool) -> Self { + self.is_for_mir_opt_tests = is_for_mir_opt_tests; + self } - pub fn new_with_extra_rust_args( - compiler: Compiler, - target: TargetSelection, - extra_rust_args: &'static [&'static str], - ) -> Self { - Self { - target, - compiler, - crates: Default::default(), - force_recompile: false, - extra_rust_args, - is_for_mir_opt_tests: false, - } + pub fn extra_rust_args(mut self, extra_rust_args: &'static [&'static str]) -> Self { + self.extra_rust_args = extra_rust_args; + self } fn copy_extra_objects( diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 8d9d2b6b6a138..636c88b099b48 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -1718,7 +1718,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the // ensure that `libproc_macro` is available on the host. if suite == "mir-opt" { - builder.ensure(compile::Std::new_for_mir_opt_tests(compiler, compiler.host)); + builder.ensure(compile::Std::new(compiler, compiler.host).is_for_mir_opt_tests(true)); } else { builder.ensure(compile::Std::new(compiler, compiler.host)); } @@ -1731,7 +1731,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the let mut cmd = builder.tool_cmd(Tool::Compiletest); if suite == "mir-opt" { - builder.ensure(compile::Std::new_for_mir_opt_tests(compiler, target)); + builder.ensure(compile::Std::new(compiler, target).is_for_mir_opt_tests(true)); } else { builder.ensure(compile::Std::new(compiler, target)); } @@ -2737,7 +2737,7 @@ impl Step for Crate { // Prepare sysroot // See [field@compile::Std::force_recompile]. - builder.ensure(compile::Std::force_recompile(compiler, compiler.host)); + builder.ensure(compile::Std::new(compiler, compiler.host).force_recompile(true)); // If we're not doing a full bootstrap but we're testing a stage2 // version of libstd, then what we're actually testing is the libstd @@ -2781,7 +2781,7 @@ impl Step for Crate { } else { // Also prepare a sysroot for the target. if builder.config.build != target { - builder.ensure(compile::Std::force_recompile(compiler, target)); + builder.ensure(compile::Std::new(compiler, target).force_recompile(true)); builder.ensure(RemoteCopyLibs { compiler, target }); } @@ -3557,10 +3557,10 @@ impl Step for CodegenGCC { let compiler = self.compiler; let target = self.target; - builder.ensure(compile::Std::new_with_extra_rust_args(compiler, target, &[ - "-Csymbol-mangling-version=v0", - "-Cpanic=abort", - ])); + builder.ensure( + compile::Std::new(compiler, target) + .extra_rust_args(&["-Csymbol-mangling-version=v0", "-Cpanic=abort"]), + ); // If we're not doing a full bootstrap but we're testing a stage2 // version of libstd, then what we're actually testing is the libstd