Skip to content

Commit 18768f0

Browse files
committed
Horrible hack to make codegen backends "work" during check
1 parent 775c970 commit 18768f0

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
@@ -1741,17 +1741,19 @@ fn copy_codegen_backends_to_sysroot(
17411741
}
17421742

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

@@ -2162,6 +2164,25 @@ impl Step for Assemble {
21622164
continue; // Already built as part of rustc
21632165
}
21642166

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

0 commit comments

Comments
 (0)