Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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:bookworm", "fedora:39" ]
distro: [ "debian:bookworm", "fedora:41" ]
runs-on: ubuntu-latest
container: ${{ matrix.distro }}
env:
Expand All @@ -22,7 +22,7 @@ jobs:
apt-get -y dist-upgrade
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'"
if: "matrix.distro == 'fedora:41'"
run: |
dnf -y install cargo rust-std-static-wasm32-wasi valgrind lld git g++ clang wget which diffutils
- name: Checkout source code
Expand All @@ -46,7 +46,7 @@ jobs:
run: |
git clone https://github.com/rust-bitcoin/rust-lightning
cd rust-lightning
git checkout 0.0.125-bindings
git checkout 0.1-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 and quote to meet MSRV
Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:
run: |
git clone https://github.com/rust-bitcoin/rust-lightning
cd rust-lightning
git checkout 0.0.125-bindings
git checkout 0.1-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 All @@ -124,9 +124,8 @@ jobs:
strategy:
matrix:
include:
- platform: macos-11
- platform: macos-12
- platform: macos-13
- platform: macos-latest
runs-on: ${{ matrix.platform }}
env:
TOOLCHAIN: stable
Expand All @@ -153,7 +152,7 @@ jobs:
run: |
git clone https://github.com/rust-bitcoin/rust-lightning
cd rust-lightning
git checkout 0.0.125-bindings
git checkout 0.1-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
2 changes: 1 addition & 1 deletion c-bindings-gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,7 @@ fn convert_file<'a, 'b>(libast: &'a FullLibraryAST, crate_types: &CrateTypes<'a>
writeln!(out, "pub mod {};", m).unwrap();
}

eprintln!("Converting {} entries...", module);
eprintln!("\n\n\nConverting {} entries...\n", module);

let import_resolver = ImportResolver::new(orig_crate, libast, module, items);
let mut type_resolver = TypeResolver::new(module, import_resolver, crate_types);
Expand Down
87 changes: 54 additions & 33 deletions c-bindings-gen/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,12 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
// is actually a pub(.*) use statement and map it to the real path.
let path_tmp = path.clone();
let crate_name = path_tmp.splitn(2, "::").next().unwrap();
let mut module_riter = path_tmp.rsplitn(2, "::");
let obj = module_riter.next().unwrap();
if let Some(module_path) = module_riter.next() {
let mut module_part_iter = path_tmp.split("::");
let mut pos = module_part_iter.next().unwrap().len();
while let Some(obj) = module_part_iter.next() {
let module_path = &path_tmp[..pos];
pos += 2 + obj.len();

if let Some(m) = self.library.modules.get(module_path) {
for item in m.items.iter() {
if let syn::Item::Use(syn::ItemUse { vis, tree, .. }) = item {
Expand All @@ -756,6 +759,21 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
},
syn::Visibility::Inherited => {},
}
} else if let syn::Item::ExternCrate(syn::ItemExternCrate { vis, ident, rename, .. }) = item {
match vis {
syn::Visibility::Public(_)|
syn::Visibility::Crate(_)|
syn::Visibility::Restricted(_) => {
if let Some((_, ident)) = rename {
if ident != obj { continue; }
} else {
if ident != obj { continue; }
}

path = format!("{}", ident) + &path_tmp[pos..];
},
syn::Visibility::Inherited => {},
}
}
}
}
Expand Down Expand Up @@ -845,8 +863,9 @@ impl FullLibraryAST {
syn::Item::Mod(_) => panic!("--pretty=expanded output should never have non-body modules"),
syn::Item::ExternCrate(c) => {
if export_status(&c.attrs) == ExportStatus::Export {
self.dependencies.insert(c.ident);
self.dependencies.insert(c.ident.clone());
}
non_mod_items.push(syn::Item::ExternCrate(c));
},
_ => { non_mod_items.push(item); }
}
Expand Down Expand Up @@ -1128,15 +1147,15 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
"bitcoin::secp256k1::Message" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
"bitcoin::secp256k1::Message" if is_ref => Some("*const [u8; 32]"),
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash"
|"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
|"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret"
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash"
|"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
|"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret"
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
if is_ref => Some("*const [u8; 32]"),
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash"
|"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
|"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret"
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash"
|"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
|"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret"
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
Expand Down Expand Up @@ -1251,11 +1270,11 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
"bitcoin::constants::ChainHash" => Some("::bitcoin::constants::ChainHash::from(&"),
"bitcoin::hashes::sha256::Hash" if is_ref => Some("&::bitcoin::hashes::sha256::Hash::from_slice(&unsafe { &*"),
"bitcoin::hashes::sha256::Hash" => Some("::bitcoin::hashes::sha256::Hash::from_slice(&"),
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash" if !is_ref => Some("::lightning::ln::types::PaymentHash("),
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash" if is_ref => Some("&::lightning::ln::types::PaymentHash(unsafe { *"),
"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage" if !is_ref => Some("::lightning::ln::types::PaymentPreimage("),
"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage" if is_ref => Some("&::lightning::ln::types::PaymentPreimage(unsafe { *"),
"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret" if !is_ref => Some("::lightning::ln::types::PaymentSecret("),
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash" if !is_ref => Some("::lightning::types::payment::PaymentHash("),
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash" if is_ref => Some("&::lightning::types::payment::PaymentHash(unsafe { *"),
"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage" if !is_ref => Some("::lightning::types::payment::PaymentPreimage("),
"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage" if is_ref => Some("&::lightning::types::payment::PaymentPreimage(unsafe { *"),
"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret" if !is_ref => Some("::lightning::types::payment::PaymentSecret("),
"lightning::ln::channelmanager::PaymentId" if !is_ref => Some("::lightning::ln::channelmanager::PaymentId("),
"lightning::ln::channelmanager::PaymentId" if is_ref=> Some("&::lightning::ln::channelmanager::PaymentId( unsafe { *"),
"lightning::ln::channelmanager::InterceptId" if !is_ref => Some("::lightning::ln::channelmanager::InterceptId("),
Expand Down Expand Up @@ -1362,15 +1381,15 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
"bitcoin::hash_types::BlockHash"|"bitcoin::BlockHash" if !is_ref => Some(".data[..]).unwrap()"),
"bitcoin::constants::ChainHash" if !is_ref => Some(".data)"),
"bitcoin::hashes::sha256::Hash" => Some(" }[..]).unwrap()"),
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash"
|"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
|"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret"
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash"
|"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
|"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret"
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
if !is_ref => Some(".data)"),
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash"
|"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
|"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret"
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash"
|"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
|"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret"
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
if is_ref => Some(" })"),
Expand Down Expand Up @@ -1410,6 +1429,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
"[u8; 32]" if is_ref => Some(""),
"[u8; 20]" if !is_ref => Some("crate::c_types::TwentyBytes { data: "),
"[u8; 16]" if !is_ref => Some("crate::c_types::SixteenBytes { data: "),
"[u8; 16]" if is_ref => Some(""),
"[u8; 12]" if !is_ref => Some("crate::c_types::TwelveBytes { data: "),
"[u8; 4]" if !is_ref => Some("crate::c_types::FourBytes { data: "),
"[u8; 3]" if !is_ref => Some("crate::c_types::ThreeBytes { data: "),
Expand Down Expand Up @@ -1492,15 +1512,15 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: *"),
"bitcoin::secp256k1::Message" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
"bitcoin::secp256k1::Message" if is_ref => Some(""),
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash"
|"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
|"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret"
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash"
|"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
|"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret"
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
if is_ref => Some("&"),
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash"
|"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
|"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret"
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash"
|"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
|"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret"
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
Expand All @@ -1523,6 +1543,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
"[u8; 32]" if !is_ref => Some(" }"),
"[u8; 32]" if is_ref => Some(""),
"[u8; 20]" if !is_ref => Some(" }"),
"[u8; 16]" if is_ref => Some(""),
"[u8; 16]" if !is_ref => Some(" }"),
"[u8; 12]" if !is_ref => Some(" }"),
"[u8; 4]" if !is_ref => Some(" }"),
Expand Down Expand Up @@ -1601,15 +1622,15 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
if !is_ref => Some(".as_ref() }"),
"bitcoin::secp256k1::Message" if !is_ref => Some(".as_ref().clone() }"),
"bitcoin::secp256k1::Message" if is_ref => Some(".as_ref()"),
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash"
|"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
|"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret"
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash"
|"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
|"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret"
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
if is_ref => Some(".0"),
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash"
|"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
|"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret"
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash"
|"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
|"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret"
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
if !is_ref => Some(".0 }"),
Expand Down
Loading
Loading