@@ -12,6 +12,16 @@ pub fn impl_runtime_module(
1212 let origin_fields = input. fields . clone ( ) ;
1313
1414 if let syn:: Fields :: Named ( ref mut fields) = input. fields {
15+ fields. named . push (
16+ syn:: Field :: parse_named
17+ . parse2 ( quote ! { pub id: :: rspack_collections:: Identifier } )
18+ . expect ( "Failed to parse new field for id" ) ,
19+ ) ;
20+ fields. named . push (
21+ syn:: Field :: parse_named
22+ . parse2 ( quote ! { pub chunk: Option <:: rspack_core:: ChunkUkey > } )
23+ . expect ( "Failed to parse new field for chunk" ) ,
24+ ) ;
1525 fields. named . push (
1626 syn:: Field :: parse_named
1727 . parse2 ( quote ! { pub source_map_kind: :: rspack_util:: source_map:: SourceMapKind } )
@@ -41,23 +51,40 @@ pub fn impl_runtime_module(
4151 let field_tys: Vec < & syn:: Type > = origin_fields. iter ( ) . map ( |field| & field. ty ) . collect ( ) ;
4252 let with_default = quote ! {
4353 #[ allow( clippy:: too_many_arguments) ]
44- fn with_default( #( #field_names: #field_tys, ) * ) -> Self {
54+ fn with_default( runtime_template : & :: rspack_core :: RuntimeTemplate , #( #field_names: #field_tys, ) * ) -> Self {
4555 Self {
4656 source_map_kind: :: rspack_util:: source_map:: SourceMapKind :: empty( ) ,
4757 custom_source: None ,
4858 cached_generated_code: Default :: default ( ) ,
59+ chunk: None ,
60+ id: runtime_template. create_runtime_module_identifier( stringify!( #name) ) ,
4961 #( #field_names, ) *
5062 }
5163 }
5264 } ;
5365
66+ let with_name = quote ! {
67+ #[ allow( clippy:: too_many_arguments) ]
68+ fn with_name( runtime_template: & :: rspack_core:: RuntimeTemplate , name: & str , #( #field_names: #field_tys, ) * ) -> Self {
69+ Self {
70+ source_map_kind: :: rspack_util:: source_map:: SourceMapKind :: empty( ) ,
71+ custom_source: None ,
72+ cached_generated_code: Default :: default ( ) ,
73+ chunk: None ,
74+ id: runtime_template. create_custom_runtime_module_identifier( name) ,
75+ #( #field_names, ) *
76+ }
77+ }
78+ } ;
5479 quote ! {
5580 #[ rspack_cacheable:: cacheable]
5681 #input
5782
5883 impl #impl_generics #name #ty_generics #where_clause {
5984 #with_default
6085
86+ #with_name
87+
6188 async fn get_generated_code(
6289 & self ,
6390 compilation: & :: rspack_core:: Compilation ,
@@ -96,8 +123,21 @@ pub fn impl_runtime_module(
96123 }
97124 }
98125
126+ impl #impl_generics :: rspack_core:: AttachableRuntimeModule for #name #ty_generics #where_clause {
127+ fn attach( & mut self , chunk: :: rspack_core:: ChunkUkey ) -> ( ) {
128+ self . chunk = Some ( chunk) ;
129+ }
130+ }
131+
132+ impl #impl_generics :: rspack_core:: NamedRuntimeModule for #name #ty_generics #where_clause {
133+ fn name( & self ) -> :: rspack_collections:: Identifier {
134+ self . id
135+ }
136+ }
137+
99138 impl #impl_generics rspack_collections:: Identifiable for #name #ty_generics #where_clause {
100139 fn identifier( & self ) -> rspack_collections:: Identifier {
140+ use rspack_core:: NamedRuntimeModule ;
101141 self . name( )
102142 }
103143 }
@@ -150,6 +190,7 @@ pub fn impl_runtime_module(
150190 }
151191
152192 fn readable_identifier( & self , _context: & :: rspack_core:: Context ) -> std:: borrow:: Cow <str > {
193+ use rspack_core:: NamedRuntimeModule ;
153194 self . name( ) . as_str( ) . into( )
154195 }
155196
@@ -194,6 +235,7 @@ pub fn impl_runtime_module(
194235 runtime: Option <& :: rspack_core:: RuntimeSpec >,
195236 ) -> rspack_error:: Result <:: rspack_hash:: RspackHashDigest > {
196237 use rspack_util:: ext:: DynHash ;
238+ use rspack_core:: NamedRuntimeModule ;
197239 let mut hasher = rspack_hash:: RspackHash :: from( & compilation. options. output) ;
198240 self . name( ) . dyn_hash( & mut hasher) ;
199241 self . stage( ) . dyn_hash( & mut hasher) ;
0 commit comments