Skip to content

Commit dddb831

Browse files
committed
Horrible hack to make codegen backends "work" during check
1 parent f0aa2a8 commit dddb831

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

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

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,17 +1742,19 @@ fn copy_codegen_backends_to_sysroot(
17421742
}
17431743

17441744
let stamp = build_stamp::codegen_backend_stamp(builder, compiler, target, backend);
1745-
let dylib = t!(fs::read_to_string(stamp.path()));
1746-
let file = Path::new(&dylib);
1747-
let filename = file.file_name().unwrap().to_str().unwrap();
1748-
// change `librustc_codegen_cranelift-xxxxxx.so` to
1749-
// `librustc_codegen_cranelift-release.so`
1750-
let target_filename = {
1751-
let dash = filename.find('-').unwrap();
1752-
let dot = filename.find('.').unwrap();
1753-
format!("{}-{}{}", &filename[..dash], builder.rust_release(), &filename[dot..])
1754-
};
1755-
builder.copy_link(file, &dst.join(target_filename), FileType::NativeLibrary);
1745+
if stamp.path().exists() {
1746+
let dylib = t!(fs::read_to_string(stamp.path()));
1747+
let file = Path::new(&dylib);
1748+
let filename = file.file_name().unwrap().to_str().unwrap();
1749+
// change `librustc_codegen_cranelift-xxxxxx.so` to
1750+
// `librustc_codegen_cranelift-release.so`
1751+
let target_filename = {
1752+
let dash = filename.find('-').unwrap();
1753+
let dot = filename.find('.').unwrap();
1754+
format!("{}-{}{}", &filename[..dash], builder.rust_release(), &filename[dot..])
1755+
};
1756+
builder.copy_link(file, &dst.join(target_filename), FileType::NativeLibrary);
1757+
}
17561758
}
17571759
}
17581760

@@ -2163,6 +2165,25 @@ impl Step for Assemble {
21632165
continue; // Already built as part of rustc
21642166
}
21652167

2168+
// FIXME: this is a horrible hack used to make `x check` work when other codegen
2169+
// backends are enabled.
2170+
// `x check` will check stage 1 rustc, which copies its rmetas to the stage0 sysroot.
2171+
// Then it checks codegen backends, which correctly use these rmetas.
2172+
// Then it needs to check std, but for that it needs to build stage 1 rustc.
2173+
// This copies the build rmetas into the stage0 sysroot, effectively poisoning it,
2174+
// because we then have both check and build rmetas in the same sysroot.
2175+
// That would be fine on its own. However, when another codegen backend is enabled,
2176+
// then building stage 1 rustc implies also building stage 1 codegen backend (even if
2177+
// it isn't used for anything). And since that tries to use the poisoned
2178+
// rmetas, it fails to build.
2179+
// We don't actually need to build rustc-private codegen backends for checking std,
2180+
// so instead we skip that.
2181+
// Note: this would be also an issue for other rustc-private tools, but that is "solved"
2182+
// by check::Std being last in the list of checked things (see
2183+
// `Builder::get_step_descriptions`).
2184+
if builder.kind == Kind::Check && builder.top_stage == 1 {
2185+
continue;
2186+
}
21662187
builder.ensure(CodegenBackend {
21672188
compiler: build_compiler,
21682189
target: target_compiler.host,

0 commit comments

Comments
 (0)