@@ -1743,11 +1743,9 @@ impl TargetWarnings {
1743
1743
pub struct Target {
1744
1744
/// Target triple to pass to LLVM.
1745
1745
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 ,
1751
1749
/// Number of bits in a pointer. Influences the `target_pointer_width` `cfg` variable.
1752
1750
pub pointer_width : u32 ,
1753
1751
/// Architecture to use for ABI considerations. Valid options include: "x86",
@@ -1759,6 +1757,23 @@ pub struct Target {
1759
1757
pub options : TargetOptions ,
1760
1758
}
1761
1759
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
+
1762
1777
impl Target {
1763
1778
pub fn parse_data_layout ( & self ) -> Result < TargetDataLayout , TargetDataLayoutErrors < ' _ > > {
1764
1779
let mut dl = TargetDataLayout :: parse_from_llvm_datalayout_string ( & self . data_layout ) ?;
@@ -2549,7 +2564,7 @@ impl Target {
2549
2564
2550
2565
let mut base = Target {
2551
2566
llvm_target : get_req_field ( "llvm-target" ) ?. into ( ) ,
2552
- description : get_req_field ( "description" ) . ok ( ) . map ( Into :: into ) ,
2567
+ metadata : Default :: default ( ) ,
2553
2568
pointer_width : get_req_field ( "target-pointer-width" ) ?
2554
2569
. parse :: < u32 > ( )
2555
2570
. map_err ( |_| "target-pointer-width must be an integer" . to_string ( ) ) ?,
@@ -2558,6 +2573,22 @@ impl Target {
2558
2573
options : Default :: default ( ) ,
2559
2574
} ;
2560
2575
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
+
2561
2592
let mut incorrect_type = vec ! [ ] ;
2562
2593
2563
2594
macro_rules! key {
@@ -3253,7 +3284,7 @@ impl ToJson for Target {
3253
3284
}
3254
3285
3255
3286
target_val ! ( llvm_target) ;
3256
- target_val ! ( description ) ;
3287
+ target_val ! ( metadata ) ;
3257
3288
d. insert ( "target-pointer-width" . to_string ( ) , self . pointer_width . to_string ( ) . to_json ( ) ) ;
3258
3289
target_val ! ( arch) ;
3259
3290
target_val ! ( data_layout) ;
0 commit comments