Rollup merge of #149764 - Zalathar:has-zstd, r=bjorn3

Make `--print=backend-has-zstd` work by default on any backend

Using a defaulted `CodegenBackend` method that querying for zstd support should automatically print a safe value of `false` on any backend that doesn't specifically indicate the presence or absence of zstd.

This should fix the compiletest failures reported in https://github.com/rust-lang/rust/pull/149666#discussion_r2597881482, which can occur when LLVM is not the default codegen backend.
This commit is contained in:
Matthias Krüger 2025-12-10 17:16:48 +01:00 committed by GitHub
commit d1e921e854
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 21 additions and 16 deletions

View file

@ -47,7 +47,7 @@ use rustc_codegen_ssa::{CodegenResults, TargetConfig};
use rustc_log::tracing::info;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_session::Session;
use rustc_session::config::{OutputFilenames, PrintKind, PrintRequest};
use rustc_session::config::OutputFilenames;
use rustc_span::{Symbol, sym};
use rustc_target::spec::{Abi, Arch, Env, Os};
@ -160,16 +160,6 @@ impl CodegenBackend for CraneliftCodegenBackend {
}
}
fn print(&self, req: &PrintRequest, out: &mut String, _sess: &Session) {
match req.kind {
// FIXME have a default impl that returns false
PrintKind::BackendHasZstd => {
out.push_str("false\n");
}
_ => {}
}
}
fn target_config(&self, sess: &Session) -> TargetConfig {
// FIXME return the actually used target features. this is necessary for #[cfg(target_feature)]
let target_features = match sess.target.arch {

View file

@ -257,10 +257,6 @@ impl CodegenBackend for LlvmCodegenBackend {
}
writeln!(out).unwrap();
}
PrintKind::BackendHasZstd => {
let has_zstd = llvm::LLVMRustLLVMHasZstdCompression();
writeln!(out, "{has_zstd}").unwrap();
}
PrintKind::CodeModels => {
writeln!(out, "Available code models:").unwrap();
for name in &["tiny", "small", "kernel", "medium", "large"] {
@ -314,6 +310,10 @@ impl CodegenBackend for LlvmCodegenBackend {
llvm_util::print_version();
}
fn has_zstd(&self) -> bool {
llvm::LLVMRustLLVMHasZstdCompression()
}
fn target_config(&self, sess: &Session) -> TargetConfig {
target_config(sess)
}

View file

@ -78,6 +78,14 @@ pub trait CodegenBackend {
fn print_version(&self) {}
/// Value printed by `--print=backend-has-zstd`.
///
/// Used by compiletest to determine whether tests involving zstd compression
/// (e.g. `-Zdebuginfo-compression=zstd`) should be executed or skipped.
fn has_zstd(&self) -> bool {
false
}
/// The metadata loader used to load rlib and dylib metadata.
///
/// Alternative codegen backends may want to use different rlib or dylib formats than the

View file

@ -798,8 +798,11 @@ fn print_crate_info(
let calling_conventions = rustc_abi::all_names();
println_info!("{}", calling_conventions.join("\n"));
}
BackendHasZstd => {
let has_zstd: bool = codegen_backend.has_zstd();
println_info!("{has_zstd}");
}
RelocationModels
| BackendHasZstd
| CodeModels
| TlsModels
| TargetCPUs

View file

@ -432,6 +432,10 @@ fn has_symlinks() -> bool {
}
fn llvm_has_zstd(config: &Config) -> bool {
// FIXME(#149764): This actually queries the compiler's _default_ backend,
// which is usually LLVM, but can be another backend depending on the value
// of `rust.codegen-backends` in bootstrap.toml.
// The compiler already knows whether LLVM was built with zstd or not,
// so compiletest can just ask the compiler.
let output = query_rustc_output(