@@ -408,12 +408,12 @@ impl ToJson for Target {
408408 }
409409}
410410
411- #[ derive( serde_derive:: Deserialize ) ]
411+ #[ derive( serde_derive:: Deserialize , schemars :: JsonSchema ) ]
412412struct LinkSelfContainedComponentsWrapper {
413413 components : Vec < LinkSelfContainedComponents > ,
414414}
415415
416- #[ derive( serde_derive:: Deserialize ) ]
416+ #[ derive( serde_derive:: Deserialize , schemars :: JsonSchema ) ]
417417#[ serde( untagged) ]
418418enum TargetFamiliesJson {
419419 Array ( StaticCow < [ StaticCow < str > ] > ) ,
@@ -429,6 +429,18 @@ impl FromStr for EndianWrapper {
429429 }
430430}
431431crate :: json:: serde_deserialize_from_str!( EndianWrapper ) ;
432+ impl schemars:: JsonSchema for EndianWrapper {
433+ fn schema_name ( ) -> std:: borrow:: Cow < ' static , str > {
434+ "Endian" . into ( )
435+ }
436+ fn json_schema ( _: & mut schemars:: SchemaGenerator ) -> schemars:: Schema {
437+ schemars:: json_schema! ( {
438+ "type" : "string" ,
439+ "enum" : [ "big" , "little" ]
440+ } )
441+ . into ( )
442+ }
443+ }
432444
433445/// `ExternAbi` is in `rustc_abi`, which doesn't have access to the macro and serde.
434446struct ExternAbiWrapper ( rustc_abi:: ExternAbi ) ;
@@ -441,16 +453,30 @@ impl FromStr for ExternAbiWrapper {
441453 }
442454}
443455crate :: json:: serde_deserialize_from_str!( ExternAbiWrapper ) ;
456+ impl schemars:: JsonSchema for ExternAbiWrapper {
457+ fn schema_name ( ) -> std:: borrow:: Cow < ' static , str > {
458+ "ExternAbi" . into ( )
459+ }
460+ fn json_schema ( _: & mut schemars:: SchemaGenerator ) -> schemars:: Schema {
461+ let all =
462+ rustc_abi:: ExternAbi :: ALL_VARIANTS . iter ( ) . map ( |abi| abi. as_str ( ) ) . collect :: < Vec < _ > > ( ) ;
463+ schemars:: json_schema! ( {
464+ "type" : "string" ,
465+ "enum" : all,
466+ } )
467+ . into ( )
468+ }
469+ }
444470
445- #[ derive( serde_derive:: Deserialize ) ]
471+ #[ derive( serde_derive:: Deserialize , schemars :: JsonSchema ) ]
446472struct TargetSpecJsonMetadata {
447473 description : Option < StaticCow < str > > ,
448474 tier : Option < u64 > ,
449475 host_tools : Option < bool > ,
450476 std : Option < bool > ,
451477}
452478
453- #[ derive( serde_derive:: Deserialize ) ]
479+ #[ derive( serde_derive:: Deserialize , schemars :: JsonSchema ) ]
454480#[ serde( rename_all = "kebab-case" ) ]
455481// Ensure that all unexpected fields get turned into errors.
456482// This helps users stay up to date when the schema changes instead of silently
@@ -593,3 +619,7 @@ struct TargetSpecJson {
593619 supports_xray : Option < bool > ,
594620 entry_abi : Option < ExternAbiWrapper > ,
595621}
622+
623+ pub fn json_schema ( ) -> schemars:: Schema {
624+ schemars:: schema_for!( TargetSpecJson )
625+ }
0 commit comments