Use JSON "binary-format" to decide //@ only-elf and //@ ignore-elf

This commit is contained in:
Zalathar
2025-11-18 13:28:43 +11:00
parent d835b7c009
commit 7560717231
2 changed files with 13 additions and 5 deletions
+12
View File
@@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::collections::{BTreeSet, HashMap, HashSet};
use std::iter;
use std::process::Command;
@@ -1011,6 +1012,13 @@ pub struct TargetCfg {
// target spec).
pub(crate) rustc_abi: Option<String>,
/// ELF is the "default" binary format, so the compiler typically doesn't
/// emit a `"binary-format"` field for ELF targets.
///
/// See `impl ToJson for Target` in `compiler/rustc_target/src/spec/json.rs`.
#[serde(default = "default_binary_format_elf")]
pub(crate) binary_format: Cow<'static, str>,
// Not present in target cfg json output, additional derived information.
#[serde(skip)]
/// Supported target atomic widths: e.g. `8` to `128` or `ptr`. This is derived from the builtin
@@ -1032,6 +1040,10 @@ fn default_reloc_model() -> String {
"pic".into()
}
fn default_binary_format_elf() -> Cow<'static, str> {
Cow::Borrowed("elf")
}
#[derive(Eq, PartialEq, Clone, Debug, Default, serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum Endian {
+1 -5
View File
@@ -169,11 +169,7 @@ macro_rules! condition {
condition! {
name: "elf",
condition: !config.target.contains("windows")
&& !config.target.contains("wasm")
&& !config.target.contains("apple")
&& !config.target.contains("aix")
&& !config.target.contains("uefi"),
condition: target_cfg.binary_format == "elf",
message: "when the target binary format is ELF"
}