@@ -244,7 +244,7 @@ fn maybe_print_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generics,
244
244
}
245
245
}
246
246
247
- fn println_trait < ' a , W : std:: io:: Write > ( w : & mut W , t : & ' a syn:: ItemTrait , module_path : & str , types : & mut TypeResolver < ' a > ) {
247
+ fn println_trait < ' a , W : std:: io:: Write > ( w : & mut W , t : & ' a syn:: ItemTrait , types : & mut TypeResolver < ' a > ) {
248
248
let trait_name = format ! ( "{}" , t. ident) ;
249
249
match export_status ( & t. attrs ) {
250
250
ExportStatus :: Export => { } ,
@@ -354,7 +354,7 @@ fn println_trait<'a, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, module
354
354
write!( w, "\t \t unimplemented!()\n \t }}\n }}\n " ) . unwrap( ) ;
355
355
}
356
356
) ;
357
- write ! ( w, "\n use {}::{} as ln{};\n " , module_path, t. ident, trait_name) . unwrap ( ) ;
357
+ write ! ( w, "\n use {}::{}::{} as ln{};\n " , types . orig_crate , types . module_path, t. ident, trait_name) . unwrap ( ) ;
358
358
write ! ( w, "impl ln{}" , t. ident) . unwrap ( ) ;
359
359
maybe_print_generics ( w, & t. generics , types) ;
360
360
write ! ( w, " for {} {{\n " , trait_name) . unwrap ( ) ;
@@ -444,11 +444,11 @@ fn println_trait<'a, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, module
444
444
types. trait_declared ( & t. ident , t) ;
445
445
}
446
446
447
- fn println_opaque < W : std:: io:: Write > ( w : & mut W , ident : & syn:: Ident , struct_name : & str , generics : & syn:: Generics , attrs : & [ syn:: Attribute ] , module_path : & str , types : & TypeResolver , extra_headers : & mut File ) {
447
+ fn println_opaque < W : std:: io:: Write > ( w : & mut W , ident : & syn:: Ident , struct_name : & str , generics : & syn:: Generics , attrs : & [ syn:: Attribute ] , types : & TypeResolver , extra_headers : & mut File ) {
448
448
// If we directly read the original type by its original name, cbindgen hits
449
449
// https://github.com/eqrion/cbindgen/issues/286 Thus, instead, we import it as a temporary
450
450
// name and then reference it by that name, which works around the issue.
451
- write ! ( w, "\n use {}::{} as ln{}Import;\n type ln{} = ln{}Import" , module_path, ident, ident, ident, ident) . unwrap ( ) ;
451
+ write ! ( w, "\n use {}::{}::{} as ln{}Import;\n type ln{} = ln{}Import" , types . orig_crate , types . module_path, ident, ident, ident, ident) . unwrap ( ) ;
452
452
maybe_print_generics ( w, & generics, & types) ;
453
453
write ! ( w, ";\n \n " ) . unwrap ( ) ;
454
454
write ! ( extra_headers, "struct ln{}Opaque;\n typedef struct ln{}Opaque LDKln{};\n " , ident, ident, ident) . unwrap ( ) ;
@@ -458,7 +458,7 @@ fn println_opaque<W: std::io::Write>(w: &mut W, ident: &syn::Ident, struct_name:
458
458
write ! ( w, "\t let _ = unsafe {{ Box::from_raw(this_ptr.inner as *mut ln{}) }};\n }}\n " , struct_name) . unwrap ( ) ;
459
459
}
460
460
461
- fn println_struct < W : std:: io:: Write > ( w : & mut W , s : & syn:: ItemStruct , module_path : & str , types : & mut TypeResolver , extra_headers : & mut File ) {
461
+ fn println_struct < W : std:: io:: Write > ( w : & mut W , s : & syn:: ItemStruct , types : & mut TypeResolver , extra_headers : & mut File ) {
462
462
let struct_name = & format ! ( "{}" , s. ident) ;
463
463
let export = export_status ( & s. attrs ) ;
464
464
match export {
@@ -472,7 +472,7 @@ fn println_struct<W: std::io::Write>(w: &mut W, s: &syn::ItemStruct, module_path
472
472
return ;
473
473
}
474
474
475
- println_opaque ( w, & s. ident , struct_name, & s. generics , & s. attrs , module_path , types, extra_headers) ;
475
+ println_opaque ( w, & s. ident , struct_name, & s. generics , & s. attrs , types, extra_headers) ;
476
476
477
477
eprintln ! ( "exporting fields for {}" , struct_name) ;
478
478
if let syn:: Fields :: Named ( fields) = & s. fields {
@@ -616,7 +616,7 @@ eprintln!("WIP: IMPL {:?} FOR {}", trait_path.1, ident);
616
616
}
617
617
}
618
618
619
- fn println_enum < W : std:: io:: Write > ( w : & mut W , e : & syn:: ItemEnum , module_path : & str , types : & mut TypeResolver , extra_headers : & mut File ) {
619
+ fn println_enum < W : std:: io:: Write > ( w : & mut W , e : & syn:: ItemEnum , types : & mut TypeResolver , extra_headers : & mut File ) {
620
620
match export_status ( & e. attrs ) {
621
621
ExportStatus :: Export => { } ,
622
622
ExportStatus :: NoExport |ExportStatus :: TestOnly => return ,
@@ -625,7 +625,7 @@ fn println_enum<W: std::io::Write>(w: &mut W, e: &syn::ItemEnum, module_path: &s
625
625
for var in e. variants . iter ( ) {
626
626
if let syn:: Fields :: Unit = var. fields { } else {
627
627
eprintln ! ( "Skipping enum {} as it contains non-unit fields" , e. ident) ;
628
- println_opaque ( w, & e. ident , & format ! ( "{}" , e. ident) , & e. generics , & e. attrs , module_path , types, extra_headers) ;
628
+ println_opaque ( w, & e. ident , & format ! ( "{}" , e. ident) , & e. generics , & e. attrs , types, extra_headers) ;
629
629
types. enum_ignored ( & e. ident ) ;
630
630
return ;
631
631
}
@@ -644,7 +644,7 @@ fn println_enum<W: std::io::Write>(w: &mut W, e: &syn::ItemEnum, module_path: &s
644
644
if var. discriminant . is_some ( ) { unimplemented ! ( ) ; }
645
645
write ! ( w, "\t {},\n " , var. ident) . unwrap ( ) ;
646
646
}
647
- write ! ( w, "}}\n use {}::{} as ln{};\n impl {} {{\n " , module_path, e. ident, e. ident, e. ident) . unwrap ( ) ;
647
+ write ! ( w, "}}\n use {}::{}::{} as ln{};\n impl {} {{\n " , types . orig_crate , types . module_path, e. ident, e. ident, e. ident) . unwrap ( ) ;
648
648
write ! ( w, "\t #[allow(unused)]\n \t pub(crate) fn to_ln(&self) -> ln{} {{\n \t \t match self {{\n " , e. ident) . unwrap ( ) ;
649
649
for var in e. variants . iter ( ) {
650
650
write ! ( w, "\t \t \t {}::{} => ln{}::{},\n " , e. ident, var. ident, e. ident, var. ident) . unwrap ( ) ;
@@ -695,8 +695,7 @@ fn convert_file(path: &str, out_path: &str, orig_crate: &str, module: &str, head
695
695
assert_eq ! ( export_status( & syntax. attrs) , ExportStatus :: Export ) ;
696
696
println_docs ( & mut out, & syntax. attrs , "" ) ;
697
697
698
- let mut type_resolver = TypeResolver :: new ( module) ;
699
- let orig_module = orig_crate. to_string ( ) + "::" + module;
698
+ let mut type_resolver = TypeResolver :: new ( orig_crate, module, crate_types) ;
700
699
701
700
if path. ends_with ( "lib.rs" ) {
702
701
write ! ( out, "#![allow(non_camel_case_types)]\n " ) . unwrap ( ) ;
@@ -715,20 +714,20 @@ fn convert_file(path: &str, out_path: &str, orig_crate: &str, module: &str, head
715
714
syn:: Item :: Static ( _) => { } ,
716
715
syn:: Item :: Enum ( e) => {
717
716
if let syn:: Visibility :: Public ( _) = e. vis {
718
- println_enum ( & mut out, & e, & orig_module , & mut type_resolver, header_file) ;
717
+ println_enum ( & mut out, & e, & mut type_resolver, header_file) ;
719
718
}
720
719
} ,
721
720
syn:: Item :: Impl ( i) => {
722
721
println_impl ( & mut out, & i, & type_resolver) ;
723
722
} ,
724
723
syn:: Item :: Struct ( s) => {
725
724
if let syn:: Visibility :: Public ( _) = s. vis {
726
- println_struct ( & mut out, & s, & orig_module , & mut type_resolver, header_file) ;
725
+ println_struct ( & mut out, & s, & mut type_resolver, header_file) ;
727
726
}
728
727
} ,
729
728
syn:: Item :: Trait ( t) => {
730
729
if let syn:: Visibility :: Public ( _) = t. vis {
731
- println_trait ( & mut out, & t, & orig_module , & mut type_resolver) ;
730
+ println_trait ( & mut out, & t, & mut type_resolver) ;
732
731
}
733
732
} ,
734
733
syn:: Item :: Mod ( m) => {
@@ -769,7 +768,7 @@ fn convert_file(path: &str, out_path: &str, orig_crate: &str, module: &str, head
769
768
ExportStatus :: NoExport |ExportStatus :: TestOnly => continue ,
770
769
}
771
770
if t. generics . lt_token . is_none ( ) {
772
- println_opaque ( & mut out, & t. ident , & format ! ( "{}" , t. ident) , & t. generics , & t. attrs , & orig_module , & type_resolver, header_file) ;
771
+ println_opaque ( & mut out, & t. ident , & format ! ( "{}" , t. ident) , & t. generics , & t. attrs , & type_resolver, header_file) ;
773
772
}
774
773
}
775
774
} ,
0 commit comments