Change:
} } <ins> #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct LlvmBitcodeLinker { pub compiler: Compiler, pub target: TargetSelection, pub extra_features: Vec<String>, } impl Step for LlvmBitcodeLinker { type Output = PathBuf; const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { let builder = run.builder; run.path("src/tools/llvm-bitcode-linker").default_condition( builder.config.extended && builder .config .tools .as_ref() .map_or(builder.build.unstable_features(), |tools| { tools.iter().any(|tool| tool == "llvm-bitcode-linker") }), ) } fn make_run(run: RunConfig<'_>) { run.builder.ensure(LlvmBitcodeLinker { compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build), extra_features: Vec::new(), target: run.target, }); } fn run(self, builder: &Builder<'_>) -> PathBuf { let bin_name = "llvm-bitcode-linker"; builder.ensure(compile::Std::new(self.compiler, self.compiler.host)); builder.ensure(compile::Rustc::new(self.compiler, self.target)); let mut cargo = prepare_tool_cargo( builder, self.compiler, Mode::ToolRustc, self.target, "build", "src/tools/llvm-bitcode-linker", SourceType::InTree, &self.extra_features, ); if builder.config.rustc_parallel { cargo.rustflag("--cfg=parallel_compiler"); } builder.run(&mut cargo.into()); let tool_out = builder .cargo_out(self.compiler, Mode::ToolRustc, self.target) .join(exe(bin_name, self.compiler.host)); if self.compiler.stage > 0 { let bindir = builder.sysroot(self.compiler).join("bin"); t!(fs::create_dir_all(&bindir)); let bin_destination = bindir.join(exe(bin_name, self.compiler.host)); builder.copy_link(&tool_out, &bin_destination); bin_destination } else { tool_out } } } </ins> macro_rules! tool_extended { (($sel:ident, $builder:ident), $($name:ident,

Discussion:
The , which is enabled by default in the config, is recompiled everytime I try to run tests: The recompilation also causes further recompilation of (if I disable the bitcode linker, rustdoc is not recompiled).
cc
Oh, that's not good. Thanks for reporting. I will look at it tomorrow.
I have tracked it down to this . If I comment out that code it wont trigger the recompilation. From the documentation of ensure it say Also the definition of is done with the macro. That makes me think that it's related to something like the invalidating the caching. I'm currently exploring that a bit further.
The stuff above seems to work fine as building the (without rustdoc) works fine. The problem seems to be that and breaks the cache for each other. I suspect that means something is off in feature resolution between those modules.
I now know what the problem is. I will need some help to figure out the correct way to solve it. uses a very specifc cargo invocation which manually sets if a parallell compilation can be used. This causes common dependencies between the LLVM bitcode linker and Rustdoc to be rebuilt when one is called after the other. Since Rustdoc builds the bitcode linker (presumably through the step) this will always happen when is built. Is it correct/ethical of rustdoc to set like this? Or should rustflags be handled more centrally so every cargo invocation will end up with the same set of rustflags and this cache invalidation cannot occur? If it is important for rustdoc to use its own set of rustflags, should it then use a different build directory to other tools/steps using cargo?
I see that this in . Maybe she knows more about this?
We can't have same set of rustflags for every , in most cases we want the opposite; setting step specific rustflags. What about adding to tool?
That seems to work well in the scenario described above and in other scenarios I tested for. I think I just imagined that this was more frequently occurring problem if all tools share build folder and are able to set rustflags separately and adding this to would cause a conflict with something else (which it doesn't seem to do). Anyway, as this at least is fixing the apparent issue I'm creating a MR with this solution now