Skip to content

Commit 78c988f

Browse files
committed
Auto merge of #119035 - saethlin:remove-linker-requirement, r=onur-ozkan
Run Miri and mir-opt tests without a target linker Normally, we need a linker for the target to build the standard library. That's only because `std` declares crate-type lib and dylib; building the dylib is what creates a need for the linker. But for mir-opt tests (and for Miri) we do not need to build a `libstd.so`. So with this PR, when we build the standard library for mir-opt tests, instead of `cargo build` we run `cargo rustc --crate-type=lib` which overrides the configured crate types in `std`'s manifest. I've also swapped in what seems to me a better hack than `BOOTSTRAP_SKIP_TARGET_SANITY` to prevent cross-interpreting with Miri from checking for a target linker and expanded it to mir-opt tests too. Whether it's actually better is up to a reviewer.
2 parents fde0e98 + 735a6a4 commit 78c988f

File tree

5 files changed

+43
-13
lines changed

5 files changed

+43
-13
lines changed

src/bootstrap/src/core/build_steps/compile.rs

+29-5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub struct Std {
4646
/// but we need to use the downloaded copy of std for linking to rustdoc. Allow this to be overriden by `builder.ensure` from other steps.
4747
force_recompile: bool,
4848
extra_rust_args: &'static [&'static str],
49+
is_for_mir_opt_tests: bool,
4950
}
5051

5152
impl Std {
@@ -56,6 +57,7 @@ impl Std {
5657
crates: Default::default(),
5758
force_recompile: false,
5859
extra_rust_args: &[],
60+
is_for_mir_opt_tests: false,
5961
}
6062
}
6163

@@ -66,6 +68,18 @@ impl Std {
6668
crates: Default::default(),
6769
force_recompile: true,
6870
extra_rust_args: &[],
71+
is_for_mir_opt_tests: false,
72+
}
73+
}
74+
75+
pub fn new_for_mir_opt_tests(compiler: Compiler, target: TargetSelection) -> Self {
76+
Self {
77+
target,
78+
compiler,
79+
crates: Default::default(),
80+
force_recompile: false,
81+
extra_rust_args: &[],
82+
is_for_mir_opt_tests: true,
6983
}
7084
}
7185

@@ -80,6 +94,7 @@ impl Std {
8094
crates: Default::default(),
8195
force_recompile: false,
8296
extra_rust_args,
97+
is_for_mir_opt_tests: false,
8398
}
8499
}
85100
}
@@ -109,6 +124,7 @@ impl Step for Std {
109124
crates,
110125
force_recompile: false,
111126
extra_rust_args: &[],
127+
is_for_mir_opt_tests: false,
112128
});
113129
}
114130

@@ -206,11 +222,19 @@ impl Step for Std {
206222
}
207223
}
208224

209-
let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "build");
210-
std_cargo(builder, target, compiler.stage, &mut cargo);
211-
for krate in &*self.crates {
212-
cargo.arg("-p").arg(krate);
213-
}
225+
let mut cargo = if self.is_for_mir_opt_tests {
226+
let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "rustc");
227+
cargo.arg("-p").arg("std").arg("--crate-type=lib");
228+
std_cargo(builder, target, compiler.stage, &mut cargo);
229+
cargo
230+
} else {
231+
let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "build");
232+
std_cargo(builder, target, compiler.stage, &mut cargo);
233+
for krate in &*self.crates {
234+
cargo.arg("-p").arg(krate);
235+
}
236+
cargo
237+
};
214238

215239
// See src/bootstrap/synthetic_targets.rs
216240
if target.is_synthetic() {

src/bootstrap/src/core/build_steps/test.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1611,15 +1611,20 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
16111611
.ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target });
16121612
}
16131613

1614-
builder.ensure(compile::Std::new(compiler, target));
1614+
if suite == "mir-opt" {
1615+
builder.ensure(compile::Std::new_for_mir_opt_tests(compiler, target));
1616+
} else {
1617+
builder.ensure(compile::Std::new(compiler, target));
1618+
}
1619+
16151620
// ensure that `libproc_macro` is available on the host.
16161621
builder.ensure(compile::Std::new(compiler, compiler.host));
16171622

16181623
// Also provide `rust_test_helpers` for the host.
16191624
builder.ensure(TestHelpers { target: compiler.host });
16201625

16211626
// As well as the target, except for plain wasm32, which can't build it
1622-
if !target.contains("wasm") || target.contains("emscripten") {
1627+
if suite != "mir-opt" && !target.contains("wasm") && !target.contains("emscripten") {
16231628
builder.ensure(TestHelpers { target });
16241629
}
16251630

src/bootstrap/src/core/sanity.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,15 @@ impl Finder {
6262
}
6363

6464
pub fn check(build: &mut Build) {
65-
let skip_target_sanity =
65+
let mut skip_target_sanity =
6666
env::var_os("BOOTSTRAP_SKIP_TARGET_SANITY").is_some_and(|s| s == "1" || s == "true");
6767

68+
// Skip target sanity checks when we are doing anything with mir-opt tests or Miri
69+
let skipped_paths = [OsStr::new("mir-opt"), OsStr::new("miri")];
70+
skip_target_sanity |= build.config.paths.iter().any(|path| {
71+
path.components().any(|component| skipped_paths.contains(&component.as_os_str()))
72+
});
73+
6874
let path = env::var_os("PATH").unwrap_or_default();
6975
// On Windows, quotes are invalid characters for filename paths, and if
7076
// one is present as part of the PATH then that can lead to the system

src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh

-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ else
3737
fi
3838
# We natively run this script on x86_64-unknown-linux-gnu and x86_64-pc-windows-msvc.
3939
# Also cover some other targets via cross-testing, in particular all tier 1 targets.
40-
export BOOTSTRAP_SKIP_TARGET_SANITY=1 # we don't need `cc` for these targets
4140
case $HOST_TARGET in
4241
x86_64-unknown-linux-gnu)
4342
# Only this branch runs in PR CI.
@@ -62,4 +61,3 @@ case $HOST_TARGET in
6261
exit 1
6362
;;
6463
esac
65-
unset BOOTSTRAP_SKIP_TARGET_SANITY

tests/mir-opt/remove_never_const.rs

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
// consts in codegen. We also have tests for this that catches the error, see
44
// tests/ui/consts/const-eval/index-out-of-bounds-never-type.rs.
55

6-
// Force generation of optimized mir for functions that do not reach codegen.
7-
// compile-flags: --emit mir,link
8-
96
#![feature(never_type)]
107

118
struct PrintName<T>(T);

0 commit comments

Comments
 (0)