From e2891c0fb9060f80e6aa24e0dc0a9c43b0861b8f Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Mon, 7 Jul 2025 14:54:50 -0400 Subject: configure.py: Write last key in each section The loop that writes the keys in each section of bootstrap.toml accumulates all the commented lines before a given key and emits them when it reaches the next key in the section. This ends up dropping lines accumulated for the last key --- src/bootstrap/configure.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index c077555b906..bec7a1c41b4 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -752,6 +752,10 @@ def write_uncommented(target, f): is_comment = True continue is_comment = is_comment and line.startswith("#") + # Write the last accumulated block + if len(block) > 0 and not is_comment: + for ln in block: + f.write(ln + "\n") return f -- cgit 1.4.1-3-g733a5 From b6d21308672c9a0aa5c73beeb1d528aab3d347ed Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Mon, 7 Jul 2025 15:45:18 -0400 Subject: Add docstring --- src/bootstrap/configure.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index bec7a1c41b4..94e02f942dc 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -739,6 +739,10 @@ def configure_file(sections, top_level_keys, targets, config): def write_uncommented(target, f): + """Writes each block in 'target' that is not composed entirely of comments to 'f'. + + A block is a sequence of non-empty lines separated by empty lines. + """ block = [] is_comment = True -- cgit 1.4.1-3-g733a5 From 754d46e33a2a01fef9732b4bb7c2bb479f744195 Mon Sep 17 00:00:00 2001 From: Jakub Beránek Date: Tue, 10 Jun 2025 20:15:36 +0200 Subject: Remove `extra_features` from `LlvmBitcodeLinker` It wasn't used anywhere. --- src/bootstrap/src/core/build_steps/compile.rs | 1 - src/bootstrap/src/core/build_steps/dist.rs | 3 +-- src/bootstrap/src/core/build_steps/tool.rs | 4 +--- 3 files changed, 2 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 3e2bdc2d6b5..c84f451bbb2 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -2061,7 +2061,6 @@ impl Step for Assemble { builder.ensure(crate::core::build_steps::tool::LlvmBitcodeLinker { compiler, target: target_compiler.host, - extra_features: vec![], }); let tool_exe = exe("llvm-bitcode-linker", target_compiler.host); builder.copy_link( diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index 25b7e5a1b5d..f2aace76896 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -2374,8 +2374,7 @@ impl Step for LlvmBitcodeLinker { builder.ensure(compile::Rustc::new(compiler, target)); - let llbc_linker = - builder.ensure(tool::LlvmBitcodeLinker { compiler, target, extra_features: vec![] }); + let llbc_linker = builder.ensure(tool::LlvmBitcodeLinker { compiler, target }); let self_contained_bin_dir = format!("lib/rustlib/{}/bin/self-contained", target.triple); diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index b05b34b9b22..b906409aedd 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -1016,7 +1016,6 @@ impl Step for RustAnalyzerProcMacroSrv { pub struct LlvmBitcodeLinker { pub compiler: Compiler, pub target: TargetSelection, - pub extra_features: Vec, } impl Step for LlvmBitcodeLinker { @@ -1033,7 +1032,6 @@ impl Step for LlvmBitcodeLinker { fn make_run(run: RunConfig<'_>) { run.builder.ensure(LlvmBitcodeLinker { compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.host_target), - extra_features: Vec::new(), target: run.target, }); } @@ -1050,7 +1048,7 @@ impl Step for LlvmBitcodeLinker { mode: Mode::ToolRustc, path: "src/tools/llvm-bitcode-linker", source_type: SourceType::InTree, - extra_features: self.extra_features, + extra_features: vec![], allow_features: "", cargo_args: Vec::new(), artifact_kind: ToolArtifactKind::Binary, -- cgit 1.4.1-3-g733a5 From c33f908f57cf1f3ea1a1261440062d2757909dc4 Mon Sep 17 00:00:00 2001 From: Jakub Beránek Date: Wed, 11 Jun 2025 08:50:09 +0200 Subject: Remove sysroot copy from `LlvmBitcodeLinker` step That step should be responsible for building the tool, not performing side-effects. Also, only copy the tool to the `self-contained` directory, not to the `rustlib//bin` directory. --- src/bootstrap/src/core/build_steps/compile.rs | 9 ++++++++- src/bootstrap/src/core/build_steps/tool.rs | 21 ++------------------- 2 files changed, 10 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index c84f451bbb2..1d095cfc58e 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -2062,10 +2062,17 @@ impl Step for Assemble { compiler, target: target_compiler.host, }); + + // Copy the llvm-bitcode-linker to the self-contained binary directory + let bindir_self_contained = builder + .sysroot(compiler) + .join(format!("lib/rustlib/{}/bin/self-contained", compiler.host)); let tool_exe = exe("llvm-bitcode-linker", target_compiler.host); + + t!(fs::create_dir_all(&bindir_self_contained)); builder.copy_link( &llvm_bitcode_linker.tool_path, - &libdir_bin.join(tool_exe), + &bindir_self_contained.join(tool_exe), FileType::Executable, ); } diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index b906409aedd..8396099d380 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -1041,7 +1041,7 @@ impl Step for LlvmBitcodeLinker { instrument(level = "debug", name = "LlvmBitcodeLinker::run", skip_all) )] fn run(self, builder: &Builder<'_>) -> ToolBuildResult { - let tool_result = builder.ensure(ToolBuild { + builder.ensure(ToolBuild { compiler: self.compiler, target: self.target, tool: "llvm-bitcode-linker", @@ -1052,24 +1052,7 @@ impl Step for LlvmBitcodeLinker { allow_features: "", cargo_args: Vec::new(), artifact_kind: ToolArtifactKind::Binary, - }); - - if tool_result.target_compiler.stage > 0 { - let bindir_self_contained = builder - .sysroot(tool_result.target_compiler) - .join(format!("lib/rustlib/{}/bin/self-contained", self.target.triple)); - t!(fs::create_dir_all(&bindir_self_contained)); - let bin_destination = bindir_self_contained - .join(exe("llvm-bitcode-linker", tool_result.target_compiler.host)); - builder.copy_link(&tool_result.tool_path, &bin_destination, FileType::Executable); - ToolBuildResult { - tool_path: bin_destination, - build_compiler: tool_result.build_compiler, - target_compiler: tool_result.target_compiler, - } - } else { - tool_result - } + }) } } -- cgit 1.4.1-3-g733a5 From fd3772200140b82324a7af8b4153c2a1a2ac1e89 Mon Sep 17 00:00:00 2001 From: Jakub Beránek Date: Tue, 8 Jul 2025 11:47:57 +0200 Subject: Update llvm-bitcode-linker tests --- src/bootstrap/src/core/build_steps/compile.rs | 2 +- src/bootstrap/src/core/build_steps/dist.rs | 3 ++- src/bootstrap/src/core/build_steps/tool.rs | 12 +++++++++--- src/bootstrap/src/core/builder/tests.rs | 23 +++++++++++++++++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 1d095cfc58e..29300ff56f5 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -2059,7 +2059,7 @@ impl Step for Assemble { trace!("llvm-bitcode-linker enabled, installing"); let llvm_bitcode_linker = builder.ensure(crate::core::build_steps::tool::LlvmBitcodeLinker { - compiler, + build_compiler: compiler, target: target_compiler.host, }); diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index f2aace76896..8b2d65ace50 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -2374,7 +2374,8 @@ impl Step for LlvmBitcodeLinker { builder.ensure(compile::Rustc::new(compiler, target)); - let llbc_linker = builder.ensure(tool::LlvmBitcodeLinker { compiler, target }); + let llbc_linker = + builder.ensure(tool::LlvmBitcodeLinker { build_compiler: compiler, target }); let self_contained_bin_dir = format!("lib/rustlib/{}/bin/self-contained", target.triple); diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index 8396099d380..a7f6a2c7bae 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -1014,7 +1014,7 @@ impl Step for RustAnalyzerProcMacroSrv { #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct LlvmBitcodeLinker { - pub compiler: Compiler, + pub build_compiler: Compiler, pub target: TargetSelection, } @@ -1031,7 +1031,9 @@ impl Step for LlvmBitcodeLinker { fn make_run(run: RunConfig<'_>) { run.builder.ensure(LlvmBitcodeLinker { - compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.host_target), + build_compiler: run + .builder + .compiler(run.builder.top_stage, run.builder.config.host_target), target: run.target, }); } @@ -1042,7 +1044,7 @@ impl Step for LlvmBitcodeLinker { )] fn run(self, builder: &Builder<'_>) -> ToolBuildResult { builder.ensure(ToolBuild { - compiler: self.compiler, + compiler: self.build_compiler, target: self.target, tool: "llvm-bitcode-linker", mode: Mode::ToolRustc, @@ -1054,6 +1056,10 @@ impl Step for LlvmBitcodeLinker { artifact_kind: ToolArtifactKind::Binary, }) } + + fn metadata(&self) -> Option { + Some(StepMetadata::build("LlvmBitcodeLinker", self.target).built_by(self.build_compiler)) + } } #[derive(Debug, Clone, Hash, PartialEq, Eq)] diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 1d5690a8197..131394f2a65 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -757,6 +757,27 @@ mod snapshot { "); } + #[test] + fn build_compiler_tools() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx + .config("build") + .stage(2) + .args(&["--set", "rust.llvm-bitcode-linker=true"]) + .render_steps(), @r" + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 1 -> LlvmBitcodeLinker 2 + [build] rustc 1 -> std 1 + [build] rustc 1 -> rustc 2 + [build] rustc 2 -> LlvmBitcodeLinker 3 + [build] rustc 2 -> std 2 + [build] rustdoc 1 + " + ); + } + #[test] fn build_library_no_explicit_stage() { let ctx = TestCtx::new(); @@ -1040,6 +1061,7 @@ mod snapshot { [build] rustc 0 -> cargo-clippy 1 [build] rustc 0 -> miri 1 [build] rustc 0 -> cargo-miri 1 + [build] rustc 1 -> LlvmBitcodeLinker 2 "); } @@ -1230,6 +1252,7 @@ mod snapshot { [build] rustc 0 -> cargo-clippy 1 [build] rustc 0 -> miri 1 [build] rustc 0 -> cargo-miri 1 + [build] rustc 1 -> LlvmBitcodeLinker 2 "); } -- cgit 1.4.1-3-g733a5 From b14323aedcfef75bde97aff4f2562dcab8e9a3cd Mon Sep 17 00:00:00 2001 From: Jakub Beránek Date: Tue, 8 Jul 2025 11:49:08 +0200 Subject: Also test `LldWrapper` and remove `llvm-config` override from tests --- src/bootstrap/src/core/build_steps/tool.rs | 7 +++++++ src/bootstrap/src/core/builder/tests.rs | 4 +++- src/bootstrap/src/utils/tests/mod.rs | 2 -- 3 files changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index a7f6a2c7bae..5de1b472d79 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -910,6 +910,13 @@ impl Step for LldWrapper { tool_result } + + fn metadata(&self) -> Option { + Some( + StepMetadata::build("LldWrapper", self.target_compiler.host) + .built_by(self.build_compiler), + ) + } } #[derive(Debug, Clone, Hash, PartialEq, Eq)] diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 131394f2a65..b240d670b6b 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -764,13 +764,15 @@ mod snapshot { ctx .config("build") .stage(2) - .args(&["--set", "rust.llvm-bitcode-linker=true"]) + .args(&["--set", "rust.lld=true", "--set", "rust.llvm-bitcode-linker=true"]) .render_steps(), @r" [build] llvm [build] rustc 0 -> rustc 1 + [build] rustc 0 -> LldWrapper 1 [build] rustc 1 -> LlvmBitcodeLinker 2 [build] rustc 1 -> std 1 [build] rustc 1 -> rustc 2 + [build] rustc 1 -> LldWrapper 2 [build] rustc 2 -> LlvmBitcodeLinker 3 [build] rustc 2 -> std 2 [build] rustdoc 1 diff --git a/src/bootstrap/src/utils/tests/mod.rs b/src/bootstrap/src/utils/tests/mod.rs index 59c169b0f2b..5b568c1df5b 100644 --- a/src/bootstrap/src/utils/tests/mod.rs +++ b/src/bootstrap/src/utils/tests/mod.rs @@ -96,8 +96,6 @@ impl ConfigBuilder { // in-tree LLVM from sources. self.args.push("--set".to_string()); self.args.push("llvm.download-ci-llvm=false".to_string()); - self.args.push("--set".to_string()); - self.args.push(format!("target.'{}'.llvm-config=false", get_host_target())); // Do not mess with the local rustc checkout build directory self.args.push("--build-dir".to_string()); -- cgit 1.4.1-3-g733a5 From 3ba8e330f9960a52b2c8ca10c8cba425514919f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 8 Jul 2025 07:34:51 -0400 Subject: Rewrite for clarity move common code to a helper function Co-Authored-By: Kobzol --- src/bootstrap/configure.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 94e02f942dc..86208b94261 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -744,22 +744,24 @@ def write_uncommented(target, f): A block is a sequence of non-empty lines separated by empty lines. """ block = [] - is_comment = True + + def flush(last): + # If the block is entiry made of comments, ignore it + entire_block_comments = all(ln.startswith("#") or ln == "" for ln in block) + if not entire_block_comments and len(block) > 0: + for line in block: + f.write(line + "\n") + # Required to output a newline before the start of a new section + if last: + f.write("\n") + block.clear() for line in target: block.append(line) if len(line) == 0: - if not is_comment: - for ln in block: - f.write(ln + "\n") - block = [] - is_comment = True - continue - is_comment = is_comment and line.startswith("#") - # Write the last accumulated block - if len(block) > 0 and not is_comment: - for ln in block: - f.write(ln + "\n") + flush(last=False) + + flush(last=True) return f -- cgit 1.4.1-3-g733a5 From 961bac0b197bf5ded0da8faf1395c96598923b20 Mon Sep 17 00:00:00 2001 From: Jakub Beránek Date: Tue, 8 Jul 2025 15:06:27 +0200 Subject: Add cross-compilation tool test --- src/bootstrap/src/core/builder/tests.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src') diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index b240d670b6b..bbcb58fca14 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -780,6 +780,35 @@ mod snapshot { ); } + #[test] + fn build_compiler_tools_cross() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx + .config("build") + .stage(2) + .args(&["--set", "rust.lld=true", "--set", "rust.llvm-bitcode-linker=true"]) + .hosts(&[TEST_TRIPLE_1]) + .render_steps(), @r" + [build] llvm + [build] rustc 0 -> rustc 1 + [build] rustc 0 -> LldWrapper 1 + [build] rustc 1 -> LlvmBitcodeLinker 2 + [build] rustc 1 -> std 1 + [build] rustc 1 -> rustc 2 + [build] rustc 1 -> LldWrapper 2 + [build] rustc 2 -> LlvmBitcodeLinker 3 + [build] rustc 1 -> std 1 + [build] rustc 2 -> std 2 + [build] llvm + [build] rustc 1 -> rustc 2 + [build] rustc 1 -> LldWrapper 2 + [build] rustc 2 -> LlvmBitcodeLinker 3 + [build] rustdoc 1 + " + ); + } + #[test] fn build_library_no_explicit_stage() { let ctx = TestCtx::new(); -- cgit 1.4.1-3-g733a5 From e5f7d4d783c1567ddc16e02091bae8bacfca1418 Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 8 Jul 2025 15:37:01 +0200 Subject: Implement enter_trace_span() in MiriMachine --- src/tools/miri/src/machine.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index 693b8916d89..35399dbf4cb 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -1014,8 +1014,6 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { const PANIC_ON_ALLOC_FAIL: bool = false; - const TRACING_ENABLED: bool = cfg!(feature = "tracing"); - #[inline(always)] fn enforce_alignment(ecx: &MiriInterpCx<'tcx>) -> bool { ecx.machine.check_alignment != AlignmentCheck::None @@ -1827,6 +1825,16 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { #[cfg(not(target_os = "linux"))] MiriAllocParams::Global } + + fn enter_trace_span(span: impl FnOnce() -> tracing::Span) -> impl EnteredTraceSpan { + #[cfg(feature = "tracing")] + { span().entered() } + #[cfg(not(feature = "tracing"))] + { + let _ = span; // so we avoid the "unused variable" warning + () + } + } } /// Trait for callbacks handling asynchronous machine operations. -- cgit 1.4.1-3-g733a5 From 7c8a6d978bb47827eeef15448ca95f82af32c381 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 8 Jul 2025 14:18:07 -0400 Subject: Spelling --- src/bootstrap/configure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 86208b94261..b05a5cc8b81 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -746,7 +746,7 @@ def write_uncommented(target, f): block = [] def flush(last): - # If the block is entiry made of comments, ignore it + # If the block is entirely made of comments, ignore it entire_block_comments = all(ln.startswith("#") or ln == "" for ln in block) if not entire_block_comments and len(block) > 0: for line in block: -- cgit 1.4.1-3-g733a5