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 {
@@ -220,6 +222,7 @@ impl RustType {
220
222
emit_from_struct : bool ,
221
223
method_name : & String ,
222
224
parameter_name : & String ,
225
+ forward_decls : & mut HashSet < String > ,
223
226
) -> String {
224
227
fn convert_type_name ( type_name : & str , options : & BindgenOptions ) -> String {
225
228
let temp_string: String ;
@@ -300,6 +303,7 @@ impl RustType {
300
303
emit_from_struct,
301
304
method_name,
302
305
parameter_name,
306
+ forward_decls,
303
307
)
304
308
} else {
305
309
convert_type_name ( use_type. type_name . as_str ( ) , options) . to_string ( )
@@ -339,6 +343,7 @@ impl RustType {
339
343
emit_from_struct,
340
344
method_name,
341
345
parameter_name,
346
+ forward_decls,
342
347
) ) ;
343
348
sb. push_str ( ", " ) ;
344
349
}
@@ -350,6 +355,7 @@ impl RustType {
350
355
emit_from_struct,
351
356
method_name,
352
357
parameter_name,
358
+ forward_decls,
353
359
) ) ;
354
360
}
355
361
None => {
@@ -358,7 +364,15 @@ impl RustType {
358
364
} ;
359
365
sb. push ( '>' ) ;
360
366
} else {
361
- sb. push_str ( build_method_delegate_name ( method_name, parameter_name) . as_str ( ) ) ;
367
+ let delegate_name = build_method_delegate_name ( method_name, parameter_name) ;
368
+
369
+ sb. push_str ( & delegate_name) ;
370
+
371
+ let decl = build_method_delegate_if_required ( self , options, alias_map, method_name, parameter_name, forward_decls) ;
372
+
373
+ if let Some ( decl) = decl {
374
+ forward_decls. insert ( format ! ( " [UnmanagedFunctionPointer(CallingConvention.Cdecl)]\n public {decl};" ) ) ;
375
+ }
362
376
}
363
377
}
364
378
TypeKind :: Option ( inner) => {
@@ -371,6 +385,7 @@ impl RustType {
371
385
emit_from_struct,
372
386
method_name,
373
387
parameter_name,
388
+ forward_decls,
374
389
)
375
390
. as_str ( ) ,
376
391
) ;
@@ -385,6 +400,7 @@ impl RustType {
385
400
method_name : & String ,
386
401
parameter_name : & String ,
387
402
emit_inner : bool ,
403
+ forward_decls : & mut HashSet < String > ,
388
404
) -> bool {
389
405
use PointerType :: * ;
390
406
if let TypeKind :: Pointer ( p, inner) = & rust_type. type_kind {
@@ -397,6 +413,7 @@ impl RustType {
397
413
emit_from_struct,
398
414
method_name,
399
415
parameter_name,
416
+ forward_decls,
400
417
)
401
418
. as_str ( ) ,
402
419
) ;
@@ -428,6 +445,7 @@ impl RustType {
428
445
method_name,
429
446
parameter_name,
430
447
emit_inner,
448
+ forward_decls,
431
449
) {
432
450
sb. push_str ( type_csharp_string. as_str ( ) ) ;
433
451
}
@@ -444,6 +462,7 @@ impl RustType {
444
462
method_name,
445
463
parameter_name,
446
464
emit_inner,
465
+ forward_decls,
447
466
) {
448
467
if emit_inner {
449
468
sb. push_str ( type_csharp_string. as_str ( ) ) ;
@@ -462,6 +481,7 @@ pub fn build_method_delegate_if_required(
462
481
alias_map : & AliasMap ,
463
482
method_name : & String ,
464
483
parameter_name : & String ,
484
+ forward_decls : & mut HashSet < String > ,
465
485
) -> Option < String > {
466
486
let emit_from_struct = false ;
467
487
@@ -479,6 +499,7 @@ pub fn build_method_delegate_if_required(
479
499
emit_from_struct,
480
500
method_name,
481
501
parameter_name,
502
+ forward_decls,
482
503
) ,
483
504
None => "void" . to_string ( ) ,
484
505
} ;
@@ -493,6 +514,7 @@ pub fn build_method_delegate_if_required(
493
514
emit_from_struct,
494
515
method_name,
495
516
parameter_name,
517
+ forward_decls,
496
518
) ;
497
519
let parameter_name = if p. name == "" {
498
520
format ! ( "arg{}" , index + 1 )
@@ -517,6 +539,7 @@ pub fn build_method_delegate_if_required(
517
539
alias_map,
518
540
method_name,
519
541
parameter_name,
542
+ forward_decls,
520
543
) ,
521
544
_ => None ,
522
545
}
0 commit comments