1
+ use std:: collections:: HashSet ;
2
+
1
3
use crate :: { alias_map:: AliasMap , builder:: BindgenOptions } ;
2
4
3
5
pub fn escape_csharp_name ( str : & str ) -> String {
@@ -228,6 +230,7 @@ impl RustType {
228
230
emit_from_struct : bool ,
229
231
method_name : & String ,
230
232
parameter_name : & String ,
233
+ forward_decls : & mut HashSet < String > ,
231
234
) -> String {
232
235
fn convert_type_name ( type_name : & str , options : & BindgenOptions ) -> String {
233
236
let temp_string: String ;
@@ -308,6 +311,7 @@ impl RustType {
308
311
emit_from_struct,
309
312
method_name,
310
313
parameter_name,
314
+ forward_decls,
311
315
)
312
316
} else {
313
317
convert_type_name ( use_type. type_name . as_str ( ) , options) . to_string ( )
@@ -347,6 +351,7 @@ impl RustType {
347
351
emit_from_struct,
348
352
method_name,
349
353
parameter_name,
354
+ forward_decls,
350
355
) ) ;
351
356
sb. push_str ( ", " ) ;
352
357
}
@@ -358,6 +363,7 @@ impl RustType {
358
363
emit_from_struct,
359
364
method_name,
360
365
parameter_name,
366
+ forward_decls,
361
367
) ) ;
362
368
}
363
369
None => {
@@ -366,7 +372,15 @@ impl RustType {
366
372
} ;
367
373
sb. push ( '>' ) ;
368
374
} else {
369
- sb. push_str ( build_method_delegate_name ( method_name, parameter_name) . as_str ( ) ) ;
375
+ let delegate_name = build_method_delegate_name ( method_name, parameter_name) ;
376
+
377
+ sb. push_str ( & delegate_name) ;
378
+
379
+ let decl = build_method_delegate_if_required ( self , options, alias_map, method_name, parameter_name, forward_decls) ;
380
+
381
+ if let Some ( decl) = decl {
382
+ forward_decls. insert ( format ! ( " [UnmanagedFunctionPointer(CallingConvention.Cdecl)]\n public {decl};" ) ) ;
383
+ }
370
384
}
371
385
}
372
386
TypeKind :: Option ( inner) => {
@@ -379,6 +393,7 @@ impl RustType {
379
393
emit_from_struct,
380
394
method_name,
381
395
parameter_name,
396
+ forward_decls,
382
397
)
383
398
. as_str ( ) ,
384
399
) ;
@@ -393,6 +408,7 @@ impl RustType {
393
408
method_name : & String ,
394
409
parameter_name : & String ,
395
410
emit_inner : bool ,
411
+ forward_decls : & mut HashSet < String > ,
396
412
) -> bool {
397
413
use PointerType :: * ;
398
414
if let TypeKind :: Pointer ( p, inner) = & rust_type. type_kind {
@@ -405,6 +421,7 @@ impl RustType {
405
421
emit_from_struct,
406
422
method_name,
407
423
parameter_name,
424
+ forward_decls,
408
425
)
409
426
. as_str ( ) ,
410
427
) ;
@@ -436,6 +453,7 @@ impl RustType {
436
453
method_name,
437
454
parameter_name,
438
455
emit_inner,
456
+ forward_decls,
439
457
) {
440
458
sb. push_str ( type_csharp_string. as_str ( ) ) ;
441
459
}
@@ -452,6 +470,7 @@ impl RustType {
452
470
method_name,
453
471
parameter_name,
454
472
emit_inner,
473
+ forward_decls,
455
474
) {
456
475
if emit_inner {
457
476
sb. push_str ( type_csharp_string. as_str ( ) ) ;
@@ -470,6 +489,7 @@ pub fn build_method_delegate_if_required(
470
489
alias_map : & AliasMap ,
471
490
method_name : & String ,
472
491
parameter_name : & String ,
492
+ forward_decls : & mut HashSet < String > ,
473
493
) -> Option < String > {
474
494
let emit_from_struct = false ;
475
495
@@ -487,6 +507,7 @@ pub fn build_method_delegate_if_required(
487
507
emit_from_struct,
488
508
method_name,
489
509
parameter_name,
510
+ forward_decls,
490
511
) ,
491
512
None => "void" . to_string ( ) ,
492
513
} ;
@@ -501,6 +522,7 @@ pub fn build_method_delegate_if_required(
501
522
emit_from_struct,
502
523
method_name,
503
524
parameter_name,
525
+ forward_decls,
504
526
) ;
505
527
let parameter_name = if p. name == "" {
506
528
format ! ( "arg{}" , index + 1 )
@@ -525,6 +547,7 @@ pub fn build_method_delegate_if_required(
525
547
alias_map,
526
548
method_name,
527
549
parameter_name,
550
+ forward_decls,
528
551
) ,
529
552
_ => None ,
530
553
}
0 commit comments