Skip to content

Simplify LLVM bitcode linker in bootstrap #142357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ impl Step for RustAnalyzerProcMacroSrv {
/// Compile the `llvm-bitcode-linker` tool for `target`.
/// It is a compiler host tool used to link specific targets using LLVM.
/// It is used by `rustc` at runtime.
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct LlvmBitcodeLinker {
pub target: TargetSelection,
}
Expand Down
27 changes: 27 additions & 0 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use llvm::prebuilt_llvm_config;
use super::*;
use crate::Flags;
use crate::core::build_steps::doc::DocumentationFormat;
use crate::core::build_steps::tool::LlvmBitcodeLinker;
use crate::core::config::Config;
use crate::utils::tests::git::{GitCtx, git_test};

Expand Down Expand Up @@ -1233,3 +1234,29 @@ fn any_debug() {
// Downcasting to the underlying type should succeed.
assert_eq!(x.downcast_ref::<MyStruct>(), Some(&MyStruct { x: 7 }));
}

/// Check that during a non-cross-compiling stage 2 build, we only compile rustc host tools
/// (such as llvm-bitcode-linker) only once.
#[test]
fn llvm_bitcode_linker_compile_once() {
Comment on lines +1238 to +1241
Copy link
Member

Choose a reason for hiding this comment

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

Question: should we have another test that does check the cross-compiling case, that we do build a stage 1 (rustc, std) pair that can produce artifacts for target, and that llvm-bitcode-linker is produced by that pair for the target?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, happy to add it. Although from my local experiments, I'm almost sure that bootstrap is actually broken for these situations somehow. Like, ./x build --host i686-unknown-linux-gnu, which is like the simplest cross-compilation scenario on x64 Linux, fails for me on master.

Copy link
Member

Choose a reason for hiding this comment

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

And you would be right 🎡

let mut cache = run_build(
&[],
configure_with_args(
&[
"build".to_string(),
"--stage".to_string(),
"2".to_string(),
"--set".to_string(),
"rust.llvm-bitcode-linker=true".to_string(),
],
&[TEST_TRIPLE_1],
&[TEST_TRIPLE_2],
),
);

// Check that llvm-bitcode-linker was built only once, and for host, not target
assert_eq!(
first(cache.all::<LlvmBitcodeLinker>()),
&[LlvmBitcodeLinker { target: TargetSelection::from_user(TEST_TRIPLE_1) }]
);
}
Loading