Skip to content

Commit 48e3445

Browse files
authored
Merge pull request #110 from TheBlueMatt/main
LDK 0.0.116
2 parents dabf0dc + 7ebc932 commit 48e3445

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+51512
-31900
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
run: |
3838
git clone https://github.com/rust-bitcoin/rust-lightning
3939
cd rust-lightning
40-
git checkout 0.0.115-bindings
40+
git checkout 0.0.116-bindings
4141
- name: Fix Github Actions to not be broken
4242
run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings
4343
- name: Pin proc-macro and quote to meet MSRV
@@ -97,7 +97,7 @@ jobs:
9797
run: |
9898
git clone https://github.com/rust-bitcoin/rust-lightning
9999
cd rust-lightning
100-
git checkout 0.0.115-bindings
100+
git checkout 0.0.116-bindings
101101
- name: Fix Github Actions to not be broken
102102
run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings
103103
- name: Fetch MacOS SDK
@@ -144,7 +144,7 @@ jobs:
144144
run: |
145145
git clone https://github.com/rust-bitcoin/rust-lightning
146146
cd rust-lightning
147-
git checkout 0.0.115-bindings
147+
git checkout 0.0.116-bindings
148148
- name: Rebuild bindings using Apple clang, and check the sample app builds + links
149149
run: ./genbindings.sh ./rust-lightning true
150150
- name: Rebuild bindings using upstream clang, and check the sample app builds + links

c-bindings-gen/src/main.rs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn maybe_convert_trait_impl<W: std::io::Write>(w: &mut W, trait_path: &syn::Path
7373
let mut for_obj_vec = Vec::new();
7474
types.write_c_type(&mut for_obj_vec, for_ty, Some(generics), false);
7575
full_obj_path = String::from_utf8(for_obj_vec).unwrap();
76-
assert!(full_obj_path.starts_with(TypeResolver::generated_container_path()));
76+
if !full_obj_path.starts_with(TypeResolver::generated_container_path()) { return; }
7777
for_obj = full_obj_path[TypeResolver::generated_container_path().len() + 2..].into();
7878
}
7979

@@ -366,9 +366,6 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
366366
writeln!(extra_headers, "struct LDK{};", trait_name).unwrap();
367367
continue;
368368
}
369-
// Sadly, this currently doesn't do what we want, but it should be easy to get
370-
// cbindgen to support it. See https://github.com/eqrion/cbindgen/issues/531
371-
writeln!(w, "\t#[must_use]").unwrap();
372369
}
373370

374371
let mut cpp_docs = Vec::new();
@@ -535,7 +532,12 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
535532
syn::TypeParamBound::Trait(tr) => {
536533
writeln!(w, "\ttype {} = crate::{};", t.ident, $type_resolver.resolve_path(&tr.path, Some(&gen_types))).unwrap();
537534
for bound in bounds_iter {
538-
if let syn::TypeParamBound::Trait(_) = bound { panic!("11"); }
535+
if let syn::TypeParamBound::Trait(t) = bound {
536+
// We only allow for `?Sized` here.
537+
if let syn::TraitBoundModifier::Maybe(_) = t.modifier {} else { panic!(); }
538+
assert_eq!(t.path.segments.len(), 1);
539+
assert_eq!(format!("{}", t.path.segments[0].ident), "Sized");
540+
}
539541
}
540542
break;
541543
},
@@ -803,7 +805,7 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
803805
define_field!(('a' as u8 + idx as u8) as char, ('0' as u8 + idx as u8) as char, field);
804806
}
805807
}
806-
_ => unimplemented!()
808+
syn::Fields::Unit => {},
807809
}
808810

809811
if all_fields_settable {
@@ -826,7 +828,7 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
826828
types.write_c_type(w, &field.ty, Some(&gen_types), false);
827829
}
828830
}
829-
_ => unreachable!()
831+
syn::Fields::Unit => {},
830832
}
831833
write!(w, ") -> {} {{\n\t", struct_name).unwrap();
832834
match &s.fields {
@@ -846,7 +848,7 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
846848
}
847849
}
848850
},
849-
_ => unreachable!()
851+
syn::Fields::Unit => {},
850852
}
851853
write!(w, "{} {{ inner: ObjOps::heap_alloc(", struct_name).unwrap();
852854
match &s.fields {
@@ -874,7 +876,7 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
874876
}
875877
write!(w, "\t)").unwrap();
876878
},
877-
_ => unreachable!()
879+
syn::Fields::Unit => write!(w, "{}::{} {{}}", types.module_path, struct_name).unwrap(),
878880
}
879881
writeln!(w, "), is_owned: true }}\n}}").unwrap();
880882
}
@@ -943,9 +945,11 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
943945
if i.defaultness.is_some() || i.unsafety.is_some() { unimplemented!(); }
944946
if let Some(trait_path) = i.trait_.as_ref() {
945947
if trait_path.0.is_some() { unimplemented!(); }
946-
if types.understood_c_path(&trait_path.1) {
947-
let full_trait_path = types.resolve_path(&trait_path.1, None);
948-
let trait_obj = *types.crate_types.traits.get(&full_trait_path).unwrap();
948+
let full_trait_path_opt = types.maybe_resolve_path(&trait_path.1, None);
949+
let trait_obj_opt = full_trait_path_opt.as_ref().and_then(|path| types.crate_types.traits.get(path));
950+
if types.understood_c_path(&trait_path.1) && trait_obj_opt.is_some() {
951+
let full_trait_path = full_trait_path_opt.unwrap();
952+
let trait_obj = *trait_obj_opt.unwrap();
949953

950954
let supertrait_name;
951955
let supertrait_resolver;
@@ -2198,9 +2202,13 @@ fn walk_private_mod<'a>(ast_storage: &'a FullLibraryAST, orig_crate: &str, modul
21982202
if let Some(trait_path) = i.trait_.as_ref() {
21992203
if let Some(tp) = import_resolver.maybe_resolve_path(&trait_path.1, None) {
22002204
if let Some(sp) = import_resolver.maybe_resolve_path(&p.path, None) {
2201-
match crate_types.trait_impls.entry(sp) {
2202-
hash_map::Entry::Occupied(mut e) => { e.get_mut().push(tp); },
2203-
hash_map::Entry::Vacant(e) => { e.insert(vec![tp]); },
2205+
match crate_types.trait_impls.entry(sp.clone()) {
2206+
hash_map::Entry::Occupied(mut e) => { e.get_mut().push(tp.clone()); },
2207+
hash_map::Entry::Vacant(e) => { e.insert(vec![tp.clone()]); },
2208+
}
2209+
match crate_types.traits_impld.entry(tp) {
2210+
hash_map::Entry::Occupied(mut e) => { e.get_mut().push(sp); },
2211+
hash_map::Entry::Vacant(e) => { e.insert(vec![sp]); },
22042212
}
22052213
}
22062214
}
@@ -2310,9 +2318,13 @@ fn walk_ast_first_pass<'a>(ast_storage: &'a FullLibraryAST, crate_types: &mut Cr
23102318
}
23112319
if let Some(tp) = import_resolver.maybe_resolve_path(&trait_path.1, None) {
23122320
if let Some(sp) = import_resolver.maybe_resolve_path(&p.path, None) {
2313-
match crate_types.trait_impls.entry(sp) {
2314-
hash_map::Entry::Occupied(mut e) => { e.get_mut().push(tp); },
2315-
hash_map::Entry::Vacant(e) => { e.insert(vec![tp]); },
2321+
match crate_types.trait_impls.entry(sp.clone()) {
2322+
hash_map::Entry::Occupied(mut e) => { e.get_mut().push(tp.clone()); },
2323+
hash_map::Entry::Vacant(e) => { e.insert(vec![tp.clone()]); },
2324+
}
2325+
match crate_types.traits_impld.entry(tp) {
2326+
hash_map::Entry::Occupied(mut e) => { e.get_mut().push(sp); },
2327+
hash_map::Entry::Vacant(e) => { e.insert(vec![sp]); },
23162328
}
23172329
}
23182330
}

0 commit comments

Comments
 (0)