Skip to content

Commit f7105f5

Browse files
authored
Merge pull request #112 from TheBlueMatt/main
Upgrade to 0.0.117
2 parents 48e3445 + 73fe6e6 commit f7105f5

Some content is hidden

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

73 files changed

+18409
-7135
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,18 @@ jobs:
3737
run: |
3838
git clone https://github.com/rust-bitcoin/rust-lightning
3939
cd rust-lightning
40-
git checkout 0.0.116-bindings
40+
git checkout 0.0.117-bindings
41+
# Pin memchr until we can remove it
42+
cargo update -p memchr --precise "2.5.0" --verbose
4143
- name: Fix Github Actions to not be broken
4244
run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings
43-
- name: Pin proc-macro and quote to meet MSRV
45+
- name: Pin proc-macro, quote and memchr to meet MSRV
4446
run: |
4547
cd c-bindings-gen
4648
cargo update -p quote --precise "1.0.30" --verbose
4749
cargo update -p proc-macro2 --precise "1.0.65" --verbose
50+
cd ../lightning-c-bindings
51+
cargo update -p memchr --precise "2.5.0" --verbose
4852
- name: Rebuild bindings without std, and check the sample app builds + links
4953
run: ./genbindings.sh ./rust-lightning false
5054
- name: Rebuild bindings, and check the sample app builds + links
@@ -97,7 +101,7 @@ jobs:
97101
run: |
98102
git clone https://github.com/rust-bitcoin/rust-lightning
99103
cd rust-lightning
100-
git checkout 0.0.116-bindings
104+
git checkout 0.0.117-bindings
101105
- name: Fix Github Actions to not be broken
102106
run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings
103107
- name: Fetch MacOS SDK
@@ -144,7 +148,7 @@ jobs:
144148
run: |
145149
git clone https://github.com/rust-bitcoin/rust-lightning
146150
cd rust-lightning
147-
git checkout 0.0.116-bindings
151+
git checkout 0.0.117-bindings
148152
- name: Rebuild bindings using Apple clang, and check the sample app builds + links
149153
run: ./genbindings.sh ./rust-lightning true
150154
- name: Rebuild bindings using upstream clang, and check the sample app builds + links

c-bindings-gen/src/main.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use blocks::*;
3636

3737
const DEFAULT_IMPORTS: &'static str = "
3838
use alloc::str::FromStr;
39+
use alloc::string::String;
3940
use core::ffi::c_void;
4041
use core::convert::Infallible;
4142
use bitcoin::hashes::Hash;
@@ -533,8 +534,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
533534
writeln!(w, "\ttype {} = crate::{};", t.ident, $type_resolver.resolve_path(&tr.path, Some(&gen_types))).unwrap();
534535
for bound in bounds_iter {
535536
if let syn::TypeParamBound::Trait(t) = bound {
536-
// We only allow for `?Sized` here.
537-
if let syn::TraitBoundModifier::Maybe(_) = t.modifier {} else { panic!(); }
537+
// We only allow for `Sized` here.
538538
assert_eq!(t.path.segments.len(), 1);
539539
assert_eq!(format!("{}", t.path.segments[0].ident), "Sized");
540540
}
@@ -554,8 +554,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
554554
writeln!(w, "unsafe impl Send for {} {{}}", trait_name).unwrap();
555555
writeln!(w, "unsafe impl Sync for {} {{}}", trait_name).unwrap();
556556

557-
writeln!(w, "#[no_mangle]").unwrap();
558-
writeln!(w, "pub(crate) extern \"C\" fn {}_clone_fields(orig: &{}) -> {} {{", trait_name, trait_name, trait_name).unwrap();
557+
writeln!(w, "pub(crate) fn {}_clone_fields(orig: &{}) -> {} {{", trait_name, trait_name, trait_name).unwrap();
559558
writeln!(w, "\t{} {{", trait_name).unwrap();
560559
writeln!(w, "\t\tthis_arg: orig.this_arg,").unwrap();
561560
for (field, clone_fn, _) in generated_fields.iter() {
@@ -647,6 +646,8 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
647646
writeln!(w, "// directly as a Deref trait in higher-level structs:").unwrap();
648647
writeln!(w, "impl core::ops::Deref for {} {{\n\ttype Target = Self;", trait_name).unwrap();
649648
writeln!(w, "\tfn deref(&self) -> &Self {{\n\t\tself\n\t}}\n}}").unwrap();
649+
writeln!(w, "impl core::ops::DerefMut for {} {{", trait_name).unwrap();
650+
writeln!(w, "\tfn deref_mut(&mut self) -> &mut Self {{\n\t\tself\n\t}}\n}}").unwrap();
650651
}
651652

652653
writeln!(w, "/// Calls the free function if one is set").unwrap();
@@ -811,6 +812,19 @@ fn writeln_struct<'a, 'b, W: std::io::Write>(w: &mut W, s: &'a syn::ItemStruct,
811812
if all_fields_settable {
812813
// Build a constructor!
813814
writeln!(w, "/// Constructs a new {} given each field", struct_name).unwrap();
815+
match &s.fields {
816+
syn::Fields::Named(fields) => {
817+
writeln_arg_docs(w, &[], "", types, Some(&gen_types),
818+
fields.named.iter().map(|field| (format!("{}_arg", field.ident.as_ref().unwrap()), &field.ty)),
819+
None);
820+
},
821+
syn::Fields::Unnamed(fields) => {
822+
writeln_arg_docs(w, &[], "", types, Some(&gen_types),
823+
fields.unnamed.iter().enumerate().map(|(idx, field)| (format!("{}_arg", ('a' as u8 + idx as u8)), &field.ty)),
824+
None);
825+
},
826+
syn::Fields::Unit => {},
827+
}
814828
write!(w, "#[must_use]\n#[no_mangle]\npub extern \"C\" fn {}_new(", struct_name).unwrap();
815829

816830
match &s.fields {

0 commit comments

Comments
 (0)