Skip to content

Commit

Permalink
Merge pull request #117 from TheBlueMatt/main
Browse files Browse the repository at this point in the history
Update to 0.0.121
  • Loading branch information
TheBlueMatt authored Jan 25, 2024
2 parents c14513f + dbca497 commit 00ed41f
Show file tree
Hide file tree
Showing 61 changed files with 18,148 additions and 6,513 deletions.
22 changes: 7 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ jobs:
matrix:
# Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
# This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
distro: [ "debian:bullseye", "fedora:39" ]
distro: [ "debian:bookworm", "fedora:39" ]
runs-on: ubuntu-latest
container: ${{ matrix.distro }}
env:
TOOLCHAIN: stable
steps:
- name: Install native Rust toolchain, Valgrind, and build utilitis
if: "matrix.distro == 'debian:bullseye'"
if: "matrix.distro == 'debian:bookworm'"
run: |
apt-get update
apt-get -y dist-upgrade
apt-get -y install cargo libstd-rust-dev-wasm32 valgrind lld git g++ clang wget
apt-get -y install cargo libstd-rust-dev-wasm32 wasi-libc valgrind lld git g++ clang wget
- name: Install native Rust toolchain, Valgrind, and build utilitis
if: "matrix.distro == 'fedora:39'"
run: |
Expand All @@ -46,22 +46,14 @@ jobs:
run: |
git clone https://github.com/rust-bitcoin/rust-lightning
cd rust-lightning
git checkout 0.0.118-bindings
- name: Pin memchr
if: "matrix.distro == 'debian:bullseye'"
run: |
# Pin memchr until we can remove it
cd rust-lightning
cargo update -p memchr --precise "2.5.0" --verbose
git checkout 0.0.121-bindings
- 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, quote and memchr to meet MSRV
- name: Pin proc-macro and quote 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 @@ -114,7 +106,7 @@ jobs:
run: |
git clone https://github.com/rust-bitcoin/rust-lightning
cd rust-lightning
git checkout 0.0.118-bindings
git checkout 0.0.121-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 @@ -161,7 +153,7 @@ jobs:
run: |
git clone https://github.com/rust-bitcoin/rust-lightning
cd rust-lightning
git checkout 0.0.118-bindings
git checkout 0.0.121-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
12 changes: 11 additions & 1 deletion c-bindings-gen/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,14 @@ pub fn write_method_call_params<W: std::io::Write>(w: &mut W, sig: &syn::Signatu
/// Prints concrete generic parameters for a struct/trait/function, including the less-than and
/// greater-than symbols, if any generic parameters are defined.
pub fn maybe_write_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generics, generics_impld: &syn::PathArguments, types: &TypeResolver, concrete_lifetimes: bool) {
maybe_write_generics_intern(w, generics, generics_impld, types, concrete_lifetimes, false);
}

pub fn maybe_write_non_lifetime_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generics, generics_impld: &syn::PathArguments, types: &TypeResolver) {
maybe_write_generics_intern(w, generics, generics_impld, types, false, true);
}

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) {
let mut gen_types = GenericTypes::new(None);
assert!(gen_types.learn_generics(generics, types));
if generics.params.is_empty() { return; }
Expand Down Expand Up @@ -789,7 +797,9 @@ pub fn maybe_write_generics<W: std::io::Write>(w: &mut W, generics: &syn::Generi
}
},
syn::GenericParam::Lifetime(lt) => {
if concrete_lifetimes {
if dummy_lifetimes {
write!(w, "'_").unwrap();
} else if concrete_lifetimes {
write!(w, "'static").unwrap();
} else {
write!(w, "{}'{}", if idx != 0 { ", " } else { "" }, lt.lifetime.ident).unwrap();
Expand Down
31 changes: 23 additions & 8 deletions c-bindings-gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,9 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
},
("Sync", _, _) => {}, ("Send", _, _) => {},
("std::marker::Sync", _, _) => {}, ("std::marker::Send", _, _) => {},
("core::fmt::Debug", _, _) => {},
("core::fmt::Debug", _, _) => {
writeln!(w, "\t\tdebug_str: {}_debug_str_void,", ident).unwrap();
},
(s, t, _) => {
if let Some(supertrait_obj) = types.crate_types.traits.get(s) {
macro_rules! write_impl_fields {
Expand Down Expand Up @@ -1298,8 +1300,8 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
write!(w, "#[must_use]\n#[no_mangle]\npub extern \"C\" fn {}_default() -> {} {{\n", ident, ident).unwrap();
write!(w, "\t{} {{ inner: ObjOps::heap_alloc(Default::default()), is_owned: true }}\n", ident).unwrap();
write!(w, "}}\n").unwrap();
} else if path_matches_nongeneric(&trait_path.1, &["core", "cmp", "PartialEq"]) {
} else if path_matches_nongeneric(&trait_path.1, &["core", "cmp", "Eq"]) {
} else if full_trait_path_opt.as_ref().map(|s| s.as_str()) == Some("core::cmp::PartialEq") {
} else if full_trait_path_opt.as_ref().map(|s| s.as_str()) == Some("core::cmp::Eq") {
writeln!(w, "/// Checks if two {}s contain equal inner contents.", ident).unwrap();
writeln!(w, "/// This ignores pointers and is_owned flags and looks at the values in fields.").unwrap();
if types.c_type_has_inner_from_path(&resolved_path) {
Expand All @@ -1325,7 +1327,7 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, w_uses: &mut HashSet<String, NonRa
types.write_from_c_conversion_suffix(w, &ref_type, Some(&gen_types));

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

writeln!(w, "\t}}.into()\n}}").unwrap();
}
} else if full_trait_path_opt.as_ref().map(|s| s.as_str()) == Some("core::fmt::Debug") {
writeln!(w, "/// Get a string which allows debug introspection of a {} object", ident).unwrap();
writeln!(w, "pub extern \"C\" fn {}_debug_str_void(o: *const c_void) -> Str {{", ident).unwrap();

write!(w, "\talloc::format!(\"{{:?}}\", unsafe {{ o as *const crate::{} }}).into()", resolved_path).unwrap();
writeln!(w, "}}").unwrap();
} else if path_matches_nongeneric(&trait_path.1, &["Display"]) {
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "/// Get the string representation of a {} object", ident).unwrap();
Expand Down Expand Up @@ -1809,7 +1817,11 @@ fn writeln_enum<'a, 'b, W: std::io::Write>(w: &mut W, e: &'a syn::ItemEnum, type

macro_rules! write_conv {
($fn_sig: expr, $to_c: expr, $ref: expr) => {
writeln!(w, "\t#[allow(unused)]\n\tpub(crate) fn {} {{\n\t\tmatch {} {{", $fn_sig, if $to_c { "native" } else { "self" }).unwrap();
writeln!(w, "\t#[allow(unused)]\n\tpub(crate) fn {} {{", $fn_sig).unwrap();
if $to_c && $ref {
writeln!(w, "\t\tlet native = unsafe {{ &*(native as *const _ as *const c_void as *const native{}) }};", e.ident).unwrap();
}
writeln!(w, "\t\tmatch {} {{", if $to_c { "native" } else { "self" }).unwrap();
for var in e.variants.iter() {
write!(w, "\t\t\t{}{}::{} ", if $to_c { "native" } else { "" }, e.ident, var.ident).unwrap();
let mut empty_tuple_variant = false;
Expand Down Expand Up @@ -1933,7 +1945,10 @@ fn writeln_enum<'a, 'b, W: std::io::Write>(w: &mut W, e: &'a syn::ItemEnum, type
}
write_conv!(format!("into_native(self) -> native{}", e.ident), false, false);
if is_clonable {
write_conv!(format!("from_native(native: &native{}) -> Self", e.ident), true, true);
let mut args = Vec::new();
maybe_write_non_lifetime_generics(&mut args, &e.generics, &syn::PathArguments::None, &types);
let fn_line = format!("from_native(native: &{}Import{}) -> Self", e.ident, String::from_utf8(args).unwrap());
write_conv!(fn_line, true, true);
}
write_conv!(format!("native_into(native: native{}) -> Self", e.ident), true, false);
writeln!(w, "}}").unwrap();
Expand Down
Loading

0 comments on commit 00ed41f

Please sign in to comment.