Skip to content

Commit 657158a

Browse files
committed
Run Miri and mir-opt tests without a target linker
1 parent 3cdd004 commit 657158a

File tree

6 files changed

+59
-15
lines changed

6 files changed

+59
-15
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,9 @@ fn link_natively<'a>(
733733
codegen_results: &CodegenResults,
734734
tmpdir: &Path,
735735
) -> Result<(), ErrorGuaranteed> {
736+
if std::env::var_os("RUSTC_SKIP_LINKER").is_some() {
737+
return Ok(());
738+
}
736739
info!("preparing {:?} to {:?}", crate_type, out_filename);
737740
let (linker_path, flavor) = linker_and_flavor(sess);
738741
let self_contained_components = self_contained_components(sess, crate_type);

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

Lines changed: 23 additions & 0 deletions
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,22 @@ 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: INTERNER.intern_list(vec![
80+
"core".to_string(),
81+
"alloc".to_string(),
82+
"std".to_string(),
83+
]),
84+
force_recompile: false,
85+
extra_rust_args: &[],
86+
is_for_mir_opt_tests: true,
6987
}
7088
}
7189

@@ -80,6 +98,7 @@ impl Std {
8098
crates: Default::default(),
8199
force_recompile: false,
82100
extra_rust_args,
101+
is_for_mir_opt_tests: false,
83102
}
84103
}
85104
}
@@ -109,6 +128,7 @@ impl Step for Std {
109128
crates,
110129
force_recompile: false,
111130
extra_rust_args: &[],
131+
is_for_mir_opt_tests: false,
112132
});
113133
}
114134

@@ -219,6 +239,9 @@ impl Step for Std {
219239
for rustflag in self.extra_rust_args.into_iter() {
220240
cargo.rustflag(rustflag);
221241
}
242+
if self.is_for_mir_opt_tests {
243+
cargo.env("RUSTC_SKIP_LINKER", "1");
244+
}
222245

223246
let _guard = builder.msg(
224247
Kind::Build,

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,16 +1611,23 @@ 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

1621-
// As well as the target, except for plain wasm32, which can't build it
1622-
if !target.contains("wasm") || target.contains("emscripten") {
1623-
builder.ensure(TestHelpers { target });
1626+
if suite != "mir-opt" {
1627+
// As well as the target, except for plain wasm32, which can't build it
1628+
if !target.contains("wasm") || target.contains("emscripten") {
1629+
builder.ensure(TestHelpers { target });
1630+
}
16241631
}
16251632

16261633
builder.ensure(RemoteCopyLibs { compiler, target });
@@ -1749,11 +1756,13 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17491756
cmd.arg("--host-rustcflags").arg(flag);
17501757
}
17511758

1752-
let mut targetflags = flags;
1753-
targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
1754-
targetflags.extend(linker_flags(builder, compiler.host, LldThreads::No));
1755-
for flag in targetflags {
1756-
cmd.arg("--target-rustcflags").arg(flag);
1759+
if mode != "mir-opt" {
1760+
let mut targetflags = flags;
1761+
targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
1762+
targetflags.extend(linker_flags(builder, compiler.host, LldThreads::No));
1763+
for flag in targetflags {
1764+
cmd.arg("--target-rustcflags").arg(flag);
1765+
}
17571766
}
17581767

17591768
cmd.arg("--python").arg(builder.python());

src/bootstrap/src/core/sanity.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,23 @@ 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+
let skipped_paths = [OsStr::new("mir-opt"), OsStr::new("miri")];
69+
70+
// Skip target sanity checks when we are doing anything with mir-opt tests or Miri
71+
for path in &build.config.paths {
72+
if path.components.any(|component| skipped_paths.contains(&component.as_os_str())) {
73+
skip_target_sanity = true;
74+
break;
75+
76+
}
77+
}
78+
if [std::path::PathBuf::from("mir-opt")].as_slice() == build.config.paths {
79+
skip_target_sanity = true;
80+
}
81+
6882
let path = env::var_os("PATH").unwrap_or_default();
6983
// On Windows, quotes are invalid characters for filename paths, and if
7084
// 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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 3 deletions
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)