Skip to content

Commit 00ed41f

Browse files
authored
Merge pull request #117 from TheBlueMatt/main
Update to 0.0.121
2 parents c14513f + dbca497 commit 00ed41f

Some content is hidden

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

61 files changed

+18148
-6513
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ jobs:
99
matrix:
1010
# Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
1111
# This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
12-
distro: [ "debian:bullseye", "fedora:39" ]
12+
distro: [ "debian:bookworm", "fedora:39" ]
1313
runs-on: ubuntu-latest
1414
container: ${{ matrix.distro }}
1515
env:
1616
TOOLCHAIN: stable
1717
steps:
1818
- name: Install native Rust toolchain, Valgrind, and build utilitis
19-
if: "matrix.distro == 'debian:bullseye'"
19+
if: "matrix.distro == 'debian:bookworm'"
2020
run: |
2121
apt-get update
2222
apt-get -y dist-upgrade
23-
apt-get -y install cargo libstd-rust-dev-wasm32 valgrind lld git g++ clang wget
23+
apt-get -y install cargo libstd-rust-dev-wasm32 wasi-libc valgrind lld git g++ clang wget
2424
- name: Install native Rust toolchain, Valgrind, and build utilitis
2525
if: "matrix.distro == 'fedora:39'"
2626
run: |
@@ -46,22 +46,14 @@ jobs:
4646
run: |
4747
git clone https://github.com/rust-bitcoin/rust-lightning
4848
cd rust-lightning
49-
git checkout 0.0.118-bindings
50-
- name: Pin memchr
51-
if: "matrix.distro == 'debian:bullseye'"
52-
run: |
53-
# Pin memchr until we can remove it
54-
cd rust-lightning
55-
cargo update -p memchr --precise "2.5.0" --verbose
49+
git checkout 0.0.121-bindings
5650
- name: Fix Github Actions to not be broken
5751
run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings
58-
- name: Pin proc-macro, quote and memchr to meet MSRV
52+
- name: Pin proc-macro and quote to meet MSRV
5953
run: |
6054
cd c-bindings-gen
6155
cargo update -p quote --precise "1.0.30" --verbose
6256
cargo update -p proc-macro2 --precise "1.0.65" --verbose
63-
cd ../lightning-c-bindings
64-
cargo update -p memchr --precise "2.5.0" --verbose
6557
- name: Rebuild bindings without std, and check the sample app builds + links
6658
run: ./genbindings.sh ./rust-lightning false
6759
- name: Rebuild bindings, and check the sample app builds + links
@@ -114,7 +106,7 @@ jobs:
114106
run: |
115107
git clone https://github.com/rust-bitcoin/rust-lightning
116108
cd rust-lightning
117-
git checkout 0.0.118-bindings
109+
git checkout 0.0.121-bindings
118110
- name: Fix Github Actions to not be broken
119111
run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings
120112
- name: Fetch MacOS SDK
@@ -161,7 +153,7 @@ jobs:
161153
run: |
162154
git clone https://github.com/rust-bitcoin/rust-lightning
163155
cd rust-lightning
164-
git checkout 0.0.118-bindings
156+
git checkout 0.0.121-bindings
165157
- name: Rebuild bindings using Apple clang, and check the sample app builds + links
166158
run: ./genbindings.sh ./rust-lightning true
167159
- name: Rebuild bindings using upstream clang, and check the sample app builds + links

c-bindings-gen/src/blocks.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,14 @@ pub fn write_method_call_params<W: std::io::Write>(w: &mut W, sig: &syn::Signatu
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.
750750
pub fn maybe_write_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generics, generics_impld: &syn::PathArguments, types: &TypeResolver, concrete_lifetimes: bool) {
751+
maybe_write_generics_intern(w, generics, generics_impld, types, concrete_lifetimes, false);
752+
}
753+
754+
pub fn maybe_write_non_lifetime_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generics, generics_impld: &syn::PathArguments, types: &TypeResolver) {
755+
maybe_write_generics_intern(w, generics, generics_impld, types, false, true);
756+
}
757+
758+
fn maybe_write_generics_intern<W: std::io::Write>(w: &mut W, generics: &syn::Generics, generics_impld: &syn::PathArguments, types: &TypeResolver, concrete_lifetimes: bool, dummy_lifetimes: bool) {
751759
let mut gen_types = GenericTypes::new(None);
752760
assert!(gen_types.learn_generics(generics, types));
753761
if generics.params.is_empty() { return; }
@@ -789,7 +797,9 @@ pub fn maybe_write_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generi
789797
}
790798
},
791799
syn::GenericParam::Lifetime(lt) => {
792-
if concrete_lifetimes {
800+
if dummy_lifetimes {
801+
write!(w, "'_").unwrap();
802+
} else if concrete_lifetimes {
793803
write!(w, "'static").unwrap();
794804
} else {
795805
write!(w, "{}'{}", if idx != 0 { ", " } else { "" }, lt.lifetime.ident).unwrap();

c-bindings-gen/src/main.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,9 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
11011101
},
11021102
("Sync", _, _) => {}, ("Send", _, _) => {},
11031103
("std::marker::Sync", _, _) => {}, ("std::marker::Send", _, _) => {},
1104-
("core::fmt::Debug", _, _) => {},
1104+
("core::fmt::Debug", _, _) => {
1105+
writeln!(w, "\t\tdebug_str: {}_debug_str_void,", ident).unwrap();
1106+
},
11051107
(s, t, _) => {
11061108
if let Some(supertrait_obj) = types.crate_types.traits.get(s) {
11071109
macro_rules! write_impl_fields {
@@ -1298,8 +1300,8 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
12981300
write!(w, "#[must_use]\n#[no_mangle]\npub extern \"C\" fn {}_default() -> {} {{\n", ident, ident).unwrap();
12991301
write!(w, "\t{} {{ inner: ObjOps::heap_alloc(Default::default()), is_owned: true }}\n", ident).unwrap();
13001302
write!(w, "}}\n").unwrap();
1301-
} else if path_matches_nongeneric(&trait_path.1, &["core", "cmp", "PartialEq"]) {
1302-
} else if path_matches_nongeneric(&trait_path.1, &["core", "cmp", "Eq"]) {
1303+
} else if full_trait_path_opt.as_ref().map(|s| s.as_str()) == Some("core::cmp::PartialEq") {
1304+
} else if full_trait_path_opt.as_ref().map(|s| s.as_str()) == Some("core::cmp::Eq") {
13031305
writeln!(w, "/// Checks if two {}s contain equal inner contents.", ident).unwrap();
13041306
writeln!(w, "/// This ignores pointers and is_owned flags and looks at the values in fields.").unwrap();
13051307
if types.c_type_has_inner_from_path(&resolved_path) {
@@ -1325,7 +1327,7 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
13251327
types.write_from_c_conversion_suffix(w, &ref_type, Some(&gen_types));
13261328

13271329
writeln!(w, " {{ true }} else {{ false }}\n}}").unwrap();
1328-
} else if path_matches_nongeneric(&trait_path.1, &["core", "hash", "Hash"]) {
1330+
} else if full_trait_path_opt.as_ref().map(|s| s.as_str()) == Some("core::hash::Hash") {
13291331
writeln!(w, "/// Generates a non-cryptographic 64-bit hash of the {}.", ident).unwrap();
13301332
write!(w, "#[no_mangle]\npub extern \"C\" fn {}_hash(o: &{}) -> u64 {{\n", ident, ident).unwrap();
13311333
if types.c_type_has_inner_from_path(&resolved_path) {
@@ -1345,8 +1347,8 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
13451347
types.write_from_c_conversion_suffix(w, &ref_type, Some(&gen_types));
13461348
writeln!(w, ", &mut hasher);").unwrap();
13471349
writeln!(w, "\tcore::hash::Hasher::finish(&hasher)\n}}").unwrap();
1348-
} else if (path_matches_nongeneric(&trait_path.1, &["core", "clone", "Clone"]) || path_matches_nongeneric(&trait_path.1, &["Clone"])) &&
1349-
types.c_type_has_inner_from_path(&resolved_path) {
1350+
} else if (full_trait_path_opt.as_ref().map(|s| s.as_str()) == Some("core::clone::Clone") || path_matches_nongeneric(&trait_path.1, &["Clone"])) &&
1351+
types.c_type_has_inner_from_path(&resolved_path) {
13501352
writeln!(w, "impl Clone for {} {{", ident).unwrap();
13511353
writeln!(w, "\tfn clone(&self) -> Self {{").unwrap();
13521354
writeln!(w, "\t\tSelf {{").unwrap();
@@ -1399,6 +1401,12 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
13991401

14001402
writeln!(w, "\t}}.into()\n}}").unwrap();
14011403
}
1404+
} else if full_trait_path_opt.as_ref().map(|s| s.as_str()) == Some("core::fmt::Debug") {
1405+
writeln!(w, "/// Get a string which allows debug introspection of a {} object", ident).unwrap();
1406+
writeln!(w, "pub extern \"C\" fn {}_debug_str_void(o: *const c_void) -> Str {{", ident).unwrap();
1407+
1408+
write!(w, "\talloc::format!(\"{{:?}}\", unsafe {{ o as *const crate::{} }}).into()", resolved_path).unwrap();
1409+
writeln!(w, "}}").unwrap();
14021410
} else if path_matches_nongeneric(&trait_path.1, &["Display"]) {
14031411
writeln!(w, "#[no_mangle]").unwrap();
14041412
writeln!(w, "/// Get the string representation of a {} object", ident).unwrap();
@@ -1809,7 +1817,11 @@ fn writeln_enum<'a, 'b, W: std::io::Write>(w: &mut W, e: &'a syn::ItemEnum, type
18091817

18101818
macro_rules! write_conv {
18111819
($fn_sig: expr, $to_c: expr, $ref: expr) => {
1812-
writeln!(w, "\t#[allow(unused)]\n\tpub(crate) fn {} {{\n\t\tmatch {} {{", $fn_sig, if $to_c { "native" } else { "self" }).unwrap();
1820+
writeln!(w, "\t#[allow(unused)]\n\tpub(crate) fn {} {{", $fn_sig).unwrap();
1821+
if $to_c && $ref {
1822+
writeln!(w, "\t\tlet native = unsafe {{ &*(native as *const _ as *const c_void as *const native{}) }};", e.ident).unwrap();
1823+
}
1824+
writeln!(w, "\t\tmatch {} {{", if $to_c { "native" } else { "self" }).unwrap();
18131825
for var in e.variants.iter() {
18141826
write!(w, "\t\t\t{}{}::{} ", if $to_c { "native" } else { "" }, e.ident, var.ident).unwrap();
18151827
let mut empty_tuple_variant = false;
@@ -1933,7 +1945,10 @@ fn writeln_enum<'a, 'b, W: std::io::Write>(w: &mut W, e: &'a syn::ItemEnum, type
19331945
}
19341946
write_conv!(format!("into_native(self) -> native{}", e.ident), false, false);
19351947
if is_clonable {
1936-
write_conv!(format!("from_native(native: &native{}) -> Self", e.ident), true, true);
1948+
let mut args = Vec::new();
1949+
maybe_write_non_lifetime_generics(&mut args, &e.generics, &syn::PathArguments::None, &types);
1950+
let fn_line = format!("from_native(native: &{}Import{}) -> Self", e.ident, String::from_utf8(args).unwrap());
1951+
write_conv!(fn_line, true, true);
19371952
}
19381953
write_conv!(format!("native_into(native: native{}) -> Self", e.ident), true, false);
19391954
writeln!(w, "}}").unwrap();

0 commit comments

Comments
 (0)