Skip to content

Commit 5c91f2c

Browse files
committed
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.
1 parent 0b96731 commit 5c91f2c

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
lines changed

compiler/rustc_codegen_cranelift/src/lib.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use rustc_codegen_ssa::{CodegenResults, TargetConfig};
4747
use rustc_log::tracing::info;
4848
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
4949
use rustc_session::Session;
50-
use rustc_session::config::{OutputFilenames, PrintKind, PrintRequest};
50+
use rustc_session::config::OutputFilenames;
5151
use rustc_span::{Symbol, sym};
5252
use rustc_target::spec::{Abi, Arch, Env, Os};
5353

@@ -160,16 +160,6 @@ impl CodegenBackend for CraneliftCodegenBackend {
160160
}
161161
}
162162

163-
fn print(&self, req: &PrintRequest, out: &mut String, _sess: &Session) {
164-
match req.kind {
165-
// FIXME have a default impl that returns false
166-
PrintKind::BackendHasZstd => {
167-
out.push_str("false\n");
168-
}
169-
_ => {}
170-
}
171-
}
172-
173163
fn target_config(&self, sess: &Session) -> TargetConfig {
174164
// FIXME return the actually used target features. this is necessary for #[cfg(target_feature)]
175165
let target_features = match sess.target.arch {

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,6 @@ impl CodegenBackend for LlvmCodegenBackend {
257257
}
258258
writeln!(out).unwrap();
259259
}
260-
PrintKind::BackendHasZstd => {
261-
let has_zstd = llvm::LLVMRustLLVMHasZstdCompression();
262-
writeln!(out, "{has_zstd}").unwrap();
263-
}
264260
PrintKind::CodeModels => {
265261
writeln!(out, "Available code models:").unwrap();
266262
for name in &["tiny", "small", "kernel", "medium", "large"] {
@@ -314,6 +310,10 @@ impl CodegenBackend for LlvmCodegenBackend {
314310
llvm_util::print_version();
315311
}
316312

313+
fn has_zstd(&self) -> bool {
314+
llvm::LLVMRustLLVMHasZstdCompression()
315+
}
316+
317317
fn target_config(&self, sess: &Session) -> TargetConfig {
318318
target_config(sess)
319319
}

compiler/rustc_codegen_ssa/src/traits/backend.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ pub trait CodegenBackend {
7878

7979
fn print_version(&self) {}
8080

81+
/// Value printed by `--print=backend-has-zstd`.
82+
///
83+
/// Used by compiletest to determine whether tests involving zstd compression
84+
/// (e.g. `-Zdebuginfo-compression=zstd`) should be executed or skipped.
85+
fn has_zstd(&self) -> bool {
86+
false
87+
}
88+
8189
/// The metadata loader used to load rlib and dylib metadata.
8290
///
8391
/// Alternative codegen backends may want to use different rlib or dylib formats than the

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,11 @@ fn print_crate_info(
798798
let calling_conventions = rustc_abi::all_names();
799799
println_info!("{}", calling_conventions.join("\n"));
800800
}
801+
BackendHasZstd => {
802+
let has_zstd: bool = codegen_backend.has_zstd();
803+
println_info!("{has_zstd}");
804+
}
801805
RelocationModels
802-
| BackendHasZstd
803806
| CodeModels
804807
| TlsModels
805808
| TargetCPUs

src/tools/compiletest/src/directives/needs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ fn has_symlinks() -> bool {
432432
}
433433

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

0 commit comments

Comments
 (0)