@@ -94,19 +94,31 @@ fn make_class(class: &Class, ctx: &mut Context, view: &ApiView) -> GeneratedClas
9494 let api_level = class. api_level ;
9595 let init_level = api_level. to_init_level ( ) ;
9696
97+ // This is not strictly needed because the classes are included/excluded by codegen depending on that feature, however it helps the
98+ // docs pipeline which converts #[ cfg(...) ] to #[ doc(cfg(...)) ], resulting in "only available in ..." labels in the HTML output.
99+ // (The above has spaces because there's a primitive sed expression at work :) )
100+ let ( cfg_attributes, cfg_inner_attributes) ;
101+ if class. is_experimental {
102+ cfg_attributes = quote ! { #[ cfg( feature = "experimental-godot-api" ) ] } ;
103+ cfg_inner_attributes = quote ! { #![ cfg( feature = "experimental-godot-api" ) ] } ;
104+ } else {
105+ cfg_attributes = TokenStream :: new ( ) ;
106+ cfg_inner_attributes = TokenStream :: new ( ) ;
107+ } ;
108+
97109 let FnDefinitions {
98110 functions : methods,
99111 builders,
100- } = make_class_methods ( class, & class. methods , ctx) ;
112+ } = make_class_methods ( class, & class. methods , & cfg_attributes , ctx) ;
101113
102- let enums = enums:: make_enums ( & class. enums ) ;
114+ let enums = enums:: make_enums ( & class. enums , & cfg_attributes ) ;
103115 let constants = constants:: make_constants ( & class. constants ) ;
104116 let inherits_macro = format_ident ! ( "unsafe_inherits_transitive_{}" , class_name. rust_ty) ;
105117 let deref_impl = make_deref_impl ( class_name, & base_ty) ;
106118
107119 let all_bases = ctx. inheritance_tree ( ) . collect_all_bases ( class_name) ;
108120 let ( notification_enum, notification_enum_name) =
109- notifications:: make_notification_enum ( class_name, & all_bases, ctx) ;
121+ notifications:: make_notification_enum ( class_name, & all_bases, & cfg_attributes , ctx) ;
110122
111123 // Associated "sidecar" module is made public if there are other symbols related to the class, which are not
112124 // in top-level godot::engine module (notification enums are not in the sidecar, but in godot::engine::notify).
@@ -120,11 +132,13 @@ fn make_class(class: &Class, ctx: &mut Context, view: &ApiView) -> GeneratedClas
120132 has_sidecar_module,
121133 ) ;
122134 let module_doc = docs:: make_module_doc ( class_name) ;
135+
123136 let virtual_trait = virtual_traits:: make_virtual_methods_trait (
124137 class,
125138 & all_bases,
126139 & virtual_trait_str,
127140 & notification_enum_name,
141+ & cfg_attributes,
128142 view,
129143 ) ;
130144
@@ -156,6 +170,7 @@ fn make_class(class: &Class, ctx: &mut Context, view: &ApiView) -> GeneratedClas
156170 let imports = util:: make_imports ( ) ;
157171 let tokens = quote ! {
158172 #![ doc = #module_doc]
173+ #cfg_inner_attributes
159174
160175 #imports
161176 use crate :: engine:: notify:: * ;
@@ -166,6 +181,7 @@ fn make_class(class: &Class, ctx: &mut Context, view: &ApiView) -> GeneratedClas
166181
167182 #[ doc = #class_doc]
168183 #[ doc = #construct_doc]
184+ #cfg_attributes
169185 #[ derive( Debug ) ]
170186 #[ repr( C ) ]
171187 pub struct #class_name {
@@ -406,12 +422,17 @@ fn make_bounds(class: &Class) -> (Ident, Ident) {
406422 ( assoc_memory, assoc_dyn_memory)
407423}
408424
409- fn make_class_methods ( class : & Class , methods : & [ ClassMethod ] , ctx : & mut Context ) -> FnDefinitions {
425+ fn make_class_methods (
426+ class : & Class ,
427+ methods : & [ ClassMethod ] ,
428+ cfg_attributes : & TokenStream ,
429+ ctx : & mut Context ,
430+ ) -> FnDefinitions {
410431 let get_method_table = class. api_level . table_global_getter ( ) ;
411432
412- let definitions = methods
413- . iter ( )
414- . map ( |method| make_class_method_definition ( class , method , & get_method_table , ctx ) ) ;
433+ let definitions = methods. iter ( ) . map ( |method| {
434+ make_class_method_definition ( class , method , & get_method_table , cfg_attributes , ctx )
435+ } ) ;
415436
416437 FnDefinitions :: expand ( definitions)
417438}
@@ -420,6 +441,7 @@ fn make_class_method_definition(
420441 class : & Class ,
421442 method : & ClassMethod ,
422443 get_method_table : & Ident ,
444+ cfg_attributes : & TokenStream ,
423445 ctx : & mut Context ,
424446) -> FnDefinition {
425447 let FnDirection :: Outbound { hash } = method. direction ( ) else {
@@ -489,5 +511,6 @@ fn make_class_method_definition(
489511 ptrcall_invocation,
490512 } ,
491513 None ,
514+ cfg_attributes,
492515 )
493516}
0 commit comments