Skip to content

Commit

Permalink
Merge pull request #112 from TheBlueMatt/main
Browse files Browse the repository at this point in the history
Upgrade to 0.0.117
  • Loading branch information
TheBlueMatt authored Oct 6, 2023
2 parents 48e3445 + 73fe6e6 commit f7105f5
Show file tree
Hide file tree
Showing 73 changed files with 18,409 additions and 7,135 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ jobs:
run: |
git clone https://github.com/rust-bitcoin/rust-lightning
cd rust-lightning
git checkout 0.0.116-bindings
git checkout 0.0.117-bindings
# Pin memchr until we can remove it
cargo update -p memchr --precise "2.5.0" --verbose
- name: Fix Github Actions to not be broken
run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings
- name: Pin proc-macro and quote to meet MSRV
- name: Pin proc-macro, quote and memchr to meet MSRV
run: |
cd c-bindings-gen
cargo update -p quote --precise "1.0.30" --verbose
cargo update -p proc-macro2 --precise "1.0.65" --verbose
cd ../lightning-c-bindings
cargo update -p memchr --precise "2.5.0" --verbose
- name: Rebuild bindings without std, and check the sample app builds + links
run: ./genbindings.sh ./rust-lightning false
- name: Rebuild bindings, and check the sample app builds + links
Expand Down Expand Up @@ -97,7 +101,7 @@ jobs:
run: |
git clone https://github.com/rust-bitcoin/rust-lightning
cd rust-lightning
git checkout 0.0.116-bindings
git checkout 0.0.117-bindings
- name: Fix Github Actions to not be broken
run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings
- name: Fetch MacOS SDK
Expand Down Expand Up @@ -144,7 +148,7 @@ jobs:
run: |
git clone https://github.com/rust-bitcoin/rust-lightning
cd rust-lightning
git checkout 0.0.116-bindings
git checkout 0.0.117-bindings
- name: Rebuild bindings using Apple clang, and check the sample app builds + links
run: ./genbindings.sh ./rust-lightning true
- name: Rebuild bindings using upstream clang, and check the sample app builds + links
Expand Down
22 changes: 18 additions & 4 deletions c-bindings-gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use blocks::*;

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

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

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

match &s.fields {
Expand Down
Loading

0 comments on commit f7105f5

Please sign in to comment.