Skip to content

Commit c809fde

Browse files
authored
Merge pull request #94 from TheBlueMatt/main
Update for 0.0.112
2 parents 7d8ba67 + 20219a1 commit c809fde

Some content is hidden

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

42 files changed

+3477
-1057
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 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.111-bindings
40+
git checkout 0.0.112-bindings
4141
- name: Rebuild bindings without std, and check the sample app builds + links
4242
run: ./genbindings.sh ./rust-lightning false
4343
- name: Rebuild bindings, and check the sample app builds + links
@@ -88,7 +88,7 @@ jobs:
8888
run: |
8989
git clone https://github.com/rust-bitcoin/rust-lightning
9090
cd rust-lightning
91-
git checkout 0.0.111-bindings
91+
git checkout 0.0.112-bindings
9292
- name: Rebuild bindings using Apple clang, and check the sample app builds + links
9393
run: ./genbindings.sh ./rust-lightning true
9494
- name: Rebuild bindings using upstream clang, and check the sample app builds + links

c-bindings-gen/src/blocks.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ pub fn write_method_call_params<W: std::io::Write>(w: &mut W, sig: &syn::Signatu
747747

748748
/// Prints concrete generic parameters for a struct/trait/function, including the less-than and
749749
/// greater-than symbols, if any generic parameters are defined.
750-
pub fn maybe_write_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generics, types: &TypeResolver, concrete_lifetimes: bool) {
750+
pub fn maybe_write_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generics, generics_impld: &syn::PathArguments, types: &TypeResolver, concrete_lifetimes: bool) {
751751
let mut gen_types = GenericTypes::new(None);
752752
assert!(gen_types.learn_generics(generics, types));
753753
if generics.params.is_empty() { return; }
@@ -778,7 +778,15 @@ pub fn maybe_write_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generi
778778
syn::GenericParam::Type(type_param) => {
779779
write!(w, "{}", if idx != 0 { ", " } else { "" }).unwrap();
780780
let type_ident = &type_param.ident;
781-
types.write_c_type_in_generic_param(w, &syn::parse_quote!(#type_ident), Some(&gen_types), false);
781+
if types.understood_c_type(&syn::parse_quote!(#type_ident), Some(&gen_types)) {
782+
types.write_c_type_in_generic_param(w, &syn::parse_quote!(#type_ident), Some(&gen_types), false);
783+
} else {
784+
if let syn::PathArguments::AngleBracketed(args) = generics_impld {
785+
if let syn::GenericArgument::Type(ty) = &args.args[idx] {
786+
types.write_c_type_in_generic_param(w, &ty, Some(&gen_types), false);
787+
}
788+
}
789+
}
782790
},
783791
syn::GenericParam::Lifetime(lt) => {
784792
if concrete_lifetimes {

c-bindings-gen/src/main.rs

Lines changed: 54 additions & 46 deletions
Large diffs are not rendered by default.

c-bindings-gen/src/types.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
205205
}
206206

207207
/// Learn the generics in generics in the current context, given a TypeResolver.
208-
pub fn learn_generics<'b, 'c>(&mut self, generics: &'a syn::Generics, types: &'b TypeResolver<'a, 'c>) -> bool {
208+
pub fn learn_generics_with_impls<'b, 'c>(&mut self, generics: &'a syn::Generics, impld_generics: &'a syn::PathArguments, types: &'b TypeResolver<'a, 'c>) -> bool {
209209
let mut new_typed_generics = HashMap::new();
210210
// First learn simple generics...
211-
for generic in generics.params.iter() {
211+
for (idx, generic) in generics.params.iter().enumerate() {
212212
match generic {
213213
syn::GenericParam::Type(type_param) => {
214214
let mut non_lifetimes_processed = false;
@@ -260,6 +260,15 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
260260
if let Some(default) = type_param.default.as_ref() {
261261
assert!(type_param.bounds.is_empty());
262262
self.default_generics.insert(&type_param.ident, (default.clone(), parse_quote!(&#default), parse_quote!(&mut #default)));
263+
} else if type_param.bounds.is_empty() {
264+
if let syn::PathArguments::AngleBracketed(args) = impld_generics {
265+
match &args.args[idx] {
266+
syn::GenericArgument::Type(ty) => {
267+
self.default_generics.insert(&type_param.ident, (ty.clone(), parse_quote!(&#ty), parse_quote!(&mut #ty)));
268+
}
269+
_ => unimplemented!(),
270+
}
271+
}
263272
}
264273
},
265274
_ => {},
@@ -270,6 +279,7 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
270279
for pred in wh.predicates.iter() {
271280
if let syn::WherePredicate::Type(t) = pred {
272281
if let syn::Type::Path(p) = &t.bounded_ty {
282+
if first_seg_self(&t.bounded_ty).is_some() && p.path.segments.len() == 1 { continue; }
273283
if p.qself.is_some() { return false; }
274284
if p.path.leading_colon.is_some() { return false; }
275285
let mut p_iter = p.path.segments.iter();
@@ -315,6 +325,11 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> {
315325
true
316326
}
317327

328+
/// Learn the generics in generics in the current context, given a TypeResolver.
329+
pub fn learn_generics<'b, 'c>(&mut self, generics: &'a syn::Generics, types: &'b TypeResolver<'a, 'c>) -> bool {
330+
self.learn_generics_with_impls(generics, &syn::PathArguments::None, types)
331+
}
332+
318333
/// Learn the associated types from the trait in the current context.
319334
pub fn learn_associated_types<'b, 'c>(&mut self, t: &'a syn::ItemTrait, types: &'b TypeResolver<'a, 'c>) {
320335
for item in t.items.iter() {
@@ -635,6 +650,8 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
635650
Some(format!("{}::{}{}", self.module_path, first_seg.ident, remaining))
636651
} else if first_seg_is_stdlib(&first_seg_str) || self.dependencies.contains(&first_seg.ident) {
637652
Some(first_seg_str + &remaining)
653+
} else if first_seg_str == "crate" {
654+
Some(self.crate_name.to_owned() + &remaining)
638655
} else { None }
639656
}
640657
}
@@ -915,7 +932,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
915932

916933
"std::time::Duration"|"core::time::Duration" => Some("u64"),
917934
"std::time::SystemTime" => Some("u64"),
918-
"std::io::Error"|"lightning::io::Error" => Some("crate::c_types::IOError"),
935+
"std::io::Error"|"lightning::io::Error"|"lightning::io::ErrorKind" => Some("crate::c_types::IOError"),
919936
"core::fmt::Arguments" if is_ref => Some("crate::c_types::Str"),
920937

921938
"core::convert::Infallible" => Some("crate::c_types::NotConstructable"),
@@ -1000,7 +1017,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
10001017

10011018
"str" if is_ref => Some(""),
10021019
"alloc::string::String"|"String" => Some(""),
1003-
"std::io::Error"|"lightning::io::Error" => Some(""),
1020+
"std::io::Error"|"lightning::io::Error"|"lightning::io::ErrorKind" => Some(""),
10041021
// Note that we'll panic for String if is_ref, as we only have non-owned memory, we
10051022
// cannot create a &String.
10061023

@@ -1091,6 +1108,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
10911108
"str" if is_ref => Some(".into_str()"),
10921109
"alloc::string::String"|"String" => Some(".into_string()"),
10931110
"std::io::Error"|"lightning::io::Error" => Some(".to_rust()"),
1111+
"lightning::io::ErrorKind" => Some(".to_rust_kind()"),
10941112

10951113
"core::convert::Infallible" => Some("\")"),
10961114

@@ -1187,6 +1205,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11871205
"std::time::Duration"|"core::time::Duration" => Some(""),
11881206
"std::time::SystemTime" => Some(""),
11891207
"std::io::Error"|"lightning::io::Error" => Some("crate::c_types::IOError::from_rust("),
1208+
"lightning::io::ErrorKind" => Some("crate::c_types::IOError::from_rust_kind("),
11901209
"core::fmt::Arguments" => Some("alloc::format!(\"{}\", "),
11911210

11921211
"core::convert::Infallible" => Some("panic!(\"Cannot construct an Infallible: "),
@@ -1266,7 +1285,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
12661285

12671286
"std::time::Duration"|"core::time::Duration" => Some(".as_secs()"),
12681287
"std::time::SystemTime" => Some(".duration_since(::std::time::SystemTime::UNIX_EPOCH).expect(\"Times must be post-1970\").as_secs()"),
1269-
"std::io::Error"|"lightning::io::Error" => Some(")"),
1288+
"std::io::Error"|"lightning::io::Error"|"lightning::io::ErrorKind" => Some(")"),
12701289
"core::fmt::Arguments" => Some(").into()"),
12711290

12721291
"core::convert::Infallible" => Some("\")"),

genbindings.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ while read LINE; do
272272
echo "Unable to find method declaration for $LINE"
273273
exit 1
274274
fi
275-
RETVAL="$(echo "$METHOD" | sed 's/[ ]*\([A-Za-z0-9 _]*\)(\*\(.*\)).*/\1/' | sed 's/^struct LDK/LDK::/g' | tr -d ' ')"
275+
RETVAL="$(echo "$METHOD" | sed 's/[ ]*\([A-Za-z0-9 _]*\)(\*\(.*\)).*/\1/' | sed -E 's/^(struct|enum) LDK/LDK::/g' | tr -d ' ')"
276276
[ "$RETVAL" = "LDK::SecretKey" ] && RETVAL="LDKSecretKey"
277277
[ "$RETVAL" = "LDK::PublicKey" ] && RETVAL="LDKPublicKey"
278278
[ "$RETVAL" = "LDK::ThirtyTwoBytes" ] && RETVAL="LDKThirtyTwoBytes"

lightning-c-bindings/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ std = ["bitcoin/std", "lightning/std", "lightning-invoice/std"]
2222
bitcoin = { version = "0.29", default-features = false }
2323
secp256k1 = { version = "0.24", features = ["global-context", "recovery"] }
2424
# Note that the following line is matched by genbindings to update the path
25-
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.111-bindings", default-features = false }
26-
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.111-bindings", default-features = false }
27-
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.111-bindings", default-features = false }
28-
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.111-bindings", default-features = false }
29-
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.111-bindings", default-features = false }
25+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.112-bindings", default-features = false }
26+
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.112-bindings", default-features = false }
27+
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.112-bindings", default-features = false }
28+
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.112-bindings", default-features = false }
29+
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "0.0.112-bindings", default-features = false }
3030

3131
core2 = { version = "0.3.0", optional = true, default-features = false }
3232

lightning-c-bindings/demo.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ void broadcast_tx(const void *this_arg, LDKTransaction tx) {
2525
Transaction_free(tx);
2626
}
2727

28-
LDKCResult_NoneChannelMonitorUpdateErrZ add_channel_monitor(const void *this_arg, LDKOutPoint funding_txo, LDKChannelMonitor monitor) {
29-
return CResult_NoneChannelMonitorUpdateErrZ_ok();
28+
LDKChannelMonitorUpdateStatus add_channel_monitor(const void *this_arg, LDKOutPoint funding_txo, LDKChannelMonitor monitor) {
29+
return ChannelMonitorUpdateStatus_completed();
3030
}
31-
LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_monitor(const void *this_arg, LDKOutPoint funding_txo, LDKChannelMonitorUpdate monitor) {
32-
return CResult_NoneChannelMonitorUpdateErrZ_ok();
31+
LDKChannelMonitorUpdateStatus update_channel_monitor(const void *this_arg, LDKOutPoint funding_txo, LDKChannelMonitorUpdate monitor) {
32+
return ChannelMonitorUpdateStatus_completed();
3333
}
3434
LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ monitors_pending_monitor_events(const void *this_arg) {
3535
LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ empty_htlc_vec = {

0 commit comments

Comments
 (0)