Skip to content

Fix empty target_config in apply_rust_config bootstrap #144126

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
68 changes: 48 additions & 20 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1631,31 +1631,59 @@ mod snapshot {
#[test]
fn doc_core_no_std_target() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("doc")
.path("core")
.override_target_no_std(&host_target())
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustdoc 0 <host>
[doc] std 1 <host> crates=[core]
");
if host_target() == "x86_64-unknown-linux-gnu" {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I don't like this. Let's figure out a different way to do this. Because the config hardcodes the name of a specific target, we'll have to generalize that somehow. For example, we can create a function that will return a list of targets for which we opt into LLD by default. Then in tests, we'll have a #[cfg(test)] version of that function, which will temporarily allow a test to override this set of targets.

Then we should implement explicit tests that will override the LLD opt in target list and check that bootstrap behaves correctly, i.e. disables the opt in if external LLVM config is provided and if LLD is disabled in the config.

insta::assert_snapshot!(
ctx.config("doc")
.path("core")
.override_target_no_std(&host_target())
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 0 <host> -> LldWrapper 1 <host>
[build] rustdoc 0 <host>
[doc] std 1 <host> crates=[core]
");
} else {
insta::assert_snapshot!(
ctx.config("doc")
.path("core")
.override_target_no_std(&host_target())
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustdoc 0 <host>
[doc] std 1 <host> crates=[core]
");
}
}

#[test]
fn doc_library_no_std_target() {
let ctx = TestCtx::new();
insta::assert_snapshot!(
ctx.config("doc")
.path("library")
.override_target_no_std(&host_target())
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustdoc 0 <host>
[doc] std 1 <host> crates=[alloc,core]
");
if host_target() == "x86_64-unknown-linux-gnu" {
insta::assert_snapshot!(
ctx.config("doc")
.path("library")
.override_target_no_std(&host_target())
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 0 <host> -> LldWrapper 1 <host>
[build] rustdoc 0 <host>
[doc] std 1 <host> crates=[alloc,core]
");
} else {
insta::assert_snapshot!(
ctx.config("doc")
.path("library")
.override_target_no_std(&host_target())
.render_steps(), @r"
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustdoc 0 <host>
[doc] std 1 <host> crates=[alloc,core]
");
}
}

#[test]
Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ impl Config {
config.rust_profile_use = flags_rust_profile_use;
config.rust_profile_generate = flags_rust_profile_generate;

config.apply_target_config(toml.target);
config.apply_rust_config(toml.rust, flags_warnings);

config.reproducible_artifacts = flags_reproducible_artifact;
Expand All @@ -967,8 +968,6 @@ impl Config {

config.apply_gcc_config(toml.gcc);

config.apply_target_config(toml.target);

match ccache {
Some(StringOrBool::String(ref s)) => config.ccache = Some(s.to_string()),
Some(StringOrBool::Bool(true)) => {
Expand Down
Loading