Skip to content

Commit d255c6a

Browse files
committed
Auto merge of rust-lang#122305 - Nilstrieb:target-tiers, r=davidtwco
Add metadata to targets follow up to rust-lang#121905 and rust-lang#122157 This adds four pieces of metadata to every target: - description - tier - host tools - std This information is currently scattered across target docs and both - not machine readable, making validation harder - sometimes subtly encoding by the table it's in, causing mistakes and making it harder to review changes to the properties By putting it in the compiler, we improve this. Later, we will use this canonical information to generate target documentation from it. I used find-replace for all the `description: None`. One thing I'm not sure about is the behavior for the JSON. It doesn't really make sense that custom targets supply this information, especially the tier. But for the roundtrip tests, we do need to print and parse it. Maybe emit a warning when a custom target provides the metadata key? Either way, I don't think that's important right now, this PR should get merged ASAP or it will conflict all over the place. r? davidtwco
2 parents e919669 + 5bcb66c commit d255c6a

File tree

232 files changed

+1422
-238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

232 files changed

+1422
-238
lines changed

compiler/rustc_target/src/json.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use std::borrow::Cow;
22
use std::collections::BTreeMap;
33

44
pub use serde_json::Value as Json;
5-
use serde_json::{Map, Number};
5+
use serde_json::{json, Map, Number};
6+
7+
use crate::spec::TargetMetadata;
68

79
pub trait ToJson {
810
fn to_json(&self) -> Json;
@@ -120,3 +122,14 @@ impl ToJson for crate::abi::call::Conv {
120122
Json::String(s.to_owned())
121123
}
122124
}
125+
126+
impl ToJson for TargetMetadata {
127+
fn to_json(&self) -> Json {
128+
json!({
129+
"description": self.description,
130+
"tier": self.tier,
131+
"host_tools": self.host_tools,
132+
"std": self.std,
133+
})
134+
}
135+
}

compiler/rustc_target/src/spec/base/avr_gnu.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ use object::elf;
88
pub fn target(target_cpu: &'static str, mmcu: &'static str) -> Target {
99
Target {
1010
arch: "avr".into(),
11-
description: None,
11+
metadata: crate::spec::TargetMetadata {
12+
description: None,
13+
tier: None,
14+
host_tools: None,
15+
std: None,
16+
},
1217
data_layout: "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8".into(),
1318
llvm_target: "avr-unknown-unknown".into(),
1419
pointer_width: 16,

compiler/rustc_target/src/spec/mod.rs

+38-7
Original file line numberDiff line numberDiff line change
@@ -1743,11 +1743,9 @@ impl TargetWarnings {
17431743
pub struct Target {
17441744
/// Target triple to pass to LLVM.
17451745
pub llvm_target: StaticCow<str>,
1746-
/// A short description of the target including platform requirements,
1747-
/// for example "64-bit Linux (kernel 3.2+, glibc 2.17+)".
1748-
/// Optional for now, intended to be required in the future.
1749-
/// Part of #120745.
1750-
pub description: Option<StaticCow<str>>,
1746+
/// Metadata about a target, for example the description or tier.
1747+
/// Used for generating target documentation.
1748+
pub metadata: TargetMetadata,
17511749
/// Number of bits in a pointer. Influences the `target_pointer_width` `cfg` variable.
17521750
pub pointer_width: u32,
17531751
/// Architecture to use for ABI considerations. Valid options include: "x86",
@@ -1759,6 +1757,23 @@ pub struct Target {
17591757
pub options: TargetOptions,
17601758
}
17611759

1760+
/// Metadata about a target like the description or tier.
1761+
/// Part of #120745.
1762+
/// All fields are optional for now, but intended to be required in the future.
1763+
#[derive(Default, PartialEq, Clone, Debug)]
1764+
pub struct TargetMetadata {
1765+
/// A short description of the target including platform requirements,
1766+
/// for example "64-bit Linux (kernel 3.2+, glibc 2.17+)".
1767+
pub description: Option<StaticCow<str>>,
1768+
/// The tier of the target. 1, 2 or 3.
1769+
pub tier: Option<u64>,
1770+
/// Whether the Rust project ships host tools for a target.
1771+
pub host_tools: Option<bool>,
1772+
/// Whether a target has the `std` library. This is usually true for targets running
1773+
/// on an operating system.
1774+
pub std: Option<bool>,
1775+
}
1776+
17621777
impl Target {
17631778
pub fn parse_data_layout(&self) -> Result<TargetDataLayout, TargetDataLayoutErrors<'_>> {
17641779
let mut dl = TargetDataLayout::parse_from_llvm_datalayout_string(&self.data_layout)?;
@@ -2549,7 +2564,7 @@ impl Target {
25492564

25502565
let mut base = Target {
25512566
llvm_target: get_req_field("llvm-target")?.into(),
2552-
description: get_req_field("description").ok().map(Into::into),
2567+
metadata: Default::default(),
25532568
pointer_width: get_req_field("target-pointer-width")?
25542569
.parse::<u32>()
25552570
.map_err(|_| "target-pointer-width must be an integer".to_string())?,
@@ -2558,6 +2573,22 @@ impl Target {
25582573
options: Default::default(),
25592574
};
25602575

2576+
// FIXME: This doesn't properly validate anything and just ignores the data if it's invalid.
2577+
// That's okay for now, the only use of this is when generating docs, which we don't do for
2578+
// custom targets.
2579+
if let Some(Json::Object(mut metadata)) = obj.remove("metadata") {
2580+
base.metadata.description = metadata
2581+
.remove("description")
2582+
.and_then(|desc| desc.as_str().map(|desc| desc.to_owned().into()));
2583+
base.metadata.tier = metadata
2584+
.remove("tier")
2585+
.and_then(|tier| tier.as_u64())
2586+
.filter(|tier| (1..=3).contains(tier));
2587+
base.metadata.host_tools =
2588+
metadata.remove("host_tools").and_then(|host| host.as_bool());
2589+
base.metadata.std = metadata.remove("std").and_then(|host| host.as_bool());
2590+
}
2591+
25612592
let mut incorrect_type = vec![];
25622593

25632594
macro_rules! key {
@@ -3253,7 +3284,7 @@ impl ToJson for Target {
32533284
}
32543285

32553286
target_val!(llvm_target);
3256-
target_val!(description);
3287+
target_val!(metadata);
32573288
d.insert("target-pointer-width".to_string(), self.pointer_width.to_string().to_json());
32583289
target_val!(arch);
32593290
target_val!(data_layout);

compiler/rustc_target/src/spec/targets/aarch64_apple_darwin.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ pub fn target() -> Target {
1515
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
1616
// correctly, we do too.
1717
llvm_target: macos_llvm_target(arch).into(),
18-
description: None,
18+
metadata: crate::spec::TargetMetadata {
19+
description: None,
20+
tier: None,
21+
host_tools: None,
22+
std: None,
23+
},
1924
pointer_width: 64,
2025
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
2126
arch: arch.target_arch(),

compiler/rustc_target/src/spec/targets/aarch64_apple_ios.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ pub fn target() -> Target {
1212
// This is required for the target to pick the right
1313
// MACH-O commands, so we do too.
1414
llvm_target: ios_llvm_target(arch).into(),
15-
description: None,
15+
metadata: crate::spec::TargetMetadata {
16+
description: None,
17+
tier: None,
18+
host_tools: None,
19+
std: None,
20+
},
1621
pointer_width: 64,
1722
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
1823
arch: arch.target_arch(),

compiler/rustc_target/src/spec/targets/aarch64_apple_ios_macabi.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ pub fn target() -> Target {
88

99
Target {
1010
llvm_target: mac_catalyst_llvm_target(arch).into(),
11-
description: None,
11+
metadata: crate::spec::TargetMetadata {
12+
description: None,
13+
tier: None,
14+
host_tools: None,
15+
std: None,
16+
},
1217
pointer_width: 64,
1318
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
1419
arch: arch.target_arch(),

compiler/rustc_target/src/spec/targets/aarch64_apple_ios_sim.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ pub fn target() -> Target {
1212
// This is required for the simulator target to pick the right
1313
// MACH-O commands, so we do too.
1414
llvm_target: ios_sim_llvm_target(arch).into(),
15-
description: None,
15+
metadata: crate::spec::TargetMetadata {
16+
description: None,
17+
tier: None,
18+
host_tools: None,
19+
std: None,
20+
},
1621
pointer_width: 64,
1722
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
1823
arch: arch.target_arch(),

compiler/rustc_target/src/spec/targets/aarch64_apple_tvos.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ pub fn target() -> Target {
55
let arch = Arch::Arm64;
66
Target {
77
llvm_target: tvos_llvm_target(arch).into(),
8-
description: None,
8+
metadata: crate::spec::TargetMetadata {
9+
description: None,
10+
tier: None,
11+
host_tools: None,
12+
std: None,
13+
},
914
pointer_width: 64,
1015
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
1116
arch: arch.target_arch(),

compiler/rustc_target/src/spec/targets/aarch64_apple_tvos_sim.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ pub fn target() -> Target {
55
let arch = Arch::Arm64_sim;
66
Target {
77
llvm_target: tvos_sim_llvm_target(arch).into(),
8-
description: None,
8+
metadata: crate::spec::TargetMetadata {
9+
description: None,
10+
tier: None,
11+
host_tools: None,
12+
std: None,
13+
},
914
pointer_width: 64,
1015
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
1116
arch: arch.target_arch(),

compiler/rustc_target/src/spec/targets/aarch64_apple_watchos.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ pub fn target() -> Target {
55
let base = opts("watchos", Arch::Arm64);
66
Target {
77
llvm_target: "aarch64-apple-watchos".into(),
8-
description: None,
8+
metadata: crate::spec::TargetMetadata {
9+
description: None,
10+
tier: None,
11+
host_tools: None,
12+
std: None,
13+
},
914
pointer_width: 64,
1015
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
1116
arch: "aarch64".into(),

compiler/rustc_target/src/spec/targets/aarch64_apple_watchos_sim.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ pub fn target() -> Target {
99
// This is required for the simulator target to pick the right
1010
// MACH-O commands, so we do too.
1111
llvm_target: watchos_sim_llvm_target(arch).into(),
12-
description: None,
12+
metadata: crate::spec::TargetMetadata {
13+
description: None,
14+
tier: None,
15+
host_tools: None,
16+
std: None,
17+
},
1318
pointer_width: 64,
1419
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
1520
arch: arch.target_arch(),

compiler/rustc_target/src/spec/targets/aarch64_be_unknown_linux_gnu.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ use crate::spec::{base, StackProbeType, Target, TargetOptions};
44
pub fn target() -> Target {
55
Target {
66
llvm_target: "aarch64_be-unknown-linux-gnu".into(),
7-
description: None,
7+
metadata: crate::spec::TargetMetadata {
8+
description: None,
9+
tier: None,
10+
host_tools: None,
11+
std: None,
12+
},
813
pointer_width: 64,
914
data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
1015
arch: "aarch64".into(),

compiler/rustc_target/src/spec/targets/aarch64_be_unknown_linux_gnu_ilp32.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ pub fn target() -> Target {
77

88
Target {
99
llvm_target: "aarch64_be-unknown-linux-gnu_ilp32".into(),
10-
description: None,
10+
metadata: crate::spec::TargetMetadata {
11+
description: None,
12+
tier: None,
13+
host_tools: None,
14+
std: None,
15+
},
1116
pointer_width: 32,
1217
data_layout: "E-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
1318
arch: "aarch64".into(),

compiler/rustc_target/src/spec/targets/aarch64_be_unknown_netbsd.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ use crate::spec::{base, StackProbeType, Target, TargetOptions};
44
pub fn target() -> Target {
55
Target {
66
llvm_target: "aarch64_be-unknown-netbsd".into(),
7-
description: None,
7+
metadata: crate::spec::TargetMetadata {
8+
description: None,
9+
tier: None,
10+
host_tools: None,
11+
std: None,
12+
},
813
pointer_width: 64,
914
data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
1015
arch: "aarch64".into(),

compiler/rustc_target/src/spec/targets/aarch64_kmc_solid_asp3.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ pub fn target() -> Target {
44
let base = base::solid::opts("asp3");
55
Target {
66
llvm_target: "aarch64-unknown-none".into(),
7-
description: None,
7+
metadata: crate::spec::TargetMetadata {
8+
description: None,
9+
tier: None,
10+
host_tools: None,
11+
std: None,
12+
},
813
pointer_width: 64,
914
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
1015
arch: "aarch64".into(),

compiler/rustc_target/src/spec/targets/aarch64_linux_android.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ use crate::spec::{base, SanitizerSet, StackProbeType, Target, TargetOptions};
66
pub fn target() -> Target {
77
Target {
88
llvm_target: "aarch64-linux-android".into(),
9-
description: None,
9+
metadata: crate::spec::TargetMetadata {
10+
description: None,
11+
tier: None,
12+
host_tools: None,
13+
std: None,
14+
},
1015
pointer_width: 64,
1116
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
1217
arch: "aarch64".into(),

compiler/rustc_target/src/spec/targets/aarch64_nintendo_switch_freestanding.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ const LINKER_SCRIPT: &str = include_str!("./aarch64_nintendo_switch_freestanding
88
pub fn target() -> Target {
99
Target {
1010
llvm_target: "aarch64-unknown-none".into(),
11-
description: None,
11+
metadata: crate::spec::TargetMetadata {
12+
description: None,
13+
tier: None,
14+
host_tools: None,
15+
std: None,
16+
},
1217
pointer_width: 64,
1318
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
1419
arch: "aarch64".into(),

compiler/rustc_target/src/spec/targets/aarch64_pc_windows_gnullvm.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ pub fn target() -> Target {
88

99
Target {
1010
llvm_target: "aarch64-pc-windows-gnu".into(),
11-
description: None,
11+
metadata: crate::spec::TargetMetadata {
12+
description: None,
13+
tier: None,
14+
host_tools: None,
15+
std: None,
16+
},
1217
pointer_width: 64,
1318
data_layout: "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128".into(),
1419
arch: "aarch64".into(),

compiler/rustc_target/src/spec/targets/aarch64_pc_windows_msvc.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ pub fn target() -> Target {
77

88
Target {
99
llvm_target: "aarch64-pc-windows-msvc".into(),
10-
description: Some("ARM64 Windows MSVC".into()),
10+
metadata: crate::spec::TargetMetadata {
11+
description: None,
12+
tier: None,
13+
host_tools: None,
14+
std: None,
15+
},
1116
pointer_width: 64,
1217
data_layout: "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128".into(),
1318
arch: "aarch64".into(),

compiler/rustc_target/src/spec/targets/aarch64_unknown_freebsd.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ use crate::spec::{base, SanitizerSet, StackProbeType, Target, TargetOptions};
33
pub fn target() -> Target {
44
Target {
55
llvm_target: "aarch64-unknown-freebsd".into(),
6-
description: None,
6+
metadata: crate::spec::TargetMetadata {
7+
description: None,
8+
tier: None,
9+
host_tools: None,
10+
std: None,
11+
},
712
pointer_width: 64,
813
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
914
arch: "aarch64".into(),

compiler/rustc_target/src/spec/targets/aarch64_unknown_fuchsia.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ use crate::spec::{base, SanitizerSet, StackProbeType, Target, TargetOptions};
33
pub fn target() -> Target {
44
Target {
55
llvm_target: "aarch64-unknown-fuchsia".into(),
6-
description: None,
6+
metadata: crate::spec::TargetMetadata {
7+
description: None,
8+
tier: None,
9+
host_tools: None,
10+
std: None,
11+
},
712
pointer_width: 64,
813
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
914
arch: "aarch64".into(),

compiler/rustc_target/src/spec/targets/aarch64_unknown_hermit.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ use crate::spec::{base, StackProbeType, Target, TargetOptions};
33
pub fn target() -> Target {
44
Target {
55
llvm_target: "aarch64-unknown-hermit".into(),
6-
description: None,
6+
metadata: crate::spec::TargetMetadata {
7+
description: None,
8+
tier: None,
9+
host_tools: None,
10+
std: None,
11+
},
712
pointer_width: 64,
813
arch: "aarch64".into(),
914
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),

compiler/rustc_target/src/spec/targets/aarch64_unknown_illumos.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ pub fn target() -> Target {
1111
// LLVM does not currently have a separate illumos target,
1212
// so we still pass Solaris to it
1313
llvm_target: "aarch64-unknown-solaris2.11".into(),
14-
description: None,
14+
metadata: crate::spec::TargetMetadata {
15+
description: None,
16+
tier: None,
17+
host_tools: None,
18+
std: None,
19+
},
1520
pointer_width: 64,
1621
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
1722
arch: "aarch64".into(),

0 commit comments

Comments
 (0)