Skip to content

Commit 30ecb65

Browse files
authored
Merge pull request #131 from TheBlueMatt/main
LDK 0.1
2 parents 0653124 + f9d608f commit 30ecb65

Some content is hidden

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

59 files changed

+23778
-17468
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ 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:bookworm", "fedora:39" ]
12+
distro: [ "debian:bookworm", "fedora:41" ]
1313
runs-on: ubuntu-latest
1414
container: ${{ matrix.distro }}
1515
env:
@@ -22,7 +22,7 @@ jobs:
2222
apt-get -y dist-upgrade
2323
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
25-
if: "matrix.distro == 'fedora:39'"
25+
if: "matrix.distro == 'fedora:41'"
2626
run: |
2727
dnf -y install cargo rust-std-static-wasm32-wasi valgrind lld git g++ clang wget which diffutils
2828
- name: Checkout source code
@@ -46,7 +46,7 @@ jobs:
4646
run: |
4747
git clone https://github.com/rust-bitcoin/rust-lightning
4848
cd rust-lightning
49-
git checkout 0.0.125-bindings
49+
git checkout 0.1-bindings
5050
- name: Fix Github Actions to not be broken
5151
run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings
5252
- name: Pin proc-macro and quote to meet MSRV
@@ -106,7 +106,7 @@ jobs:
106106
run: |
107107
git clone https://github.com/rust-bitcoin/rust-lightning
108108
cd rust-lightning
109-
git checkout 0.0.125-bindings
109+
git checkout 0.1-bindings
110110
- name: Fix Github Actions to not be broken
111111
run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings
112112
- name: Fetch MacOS SDK
@@ -124,9 +124,8 @@ jobs:
124124
strategy:
125125
matrix:
126126
include:
127-
- platform: macos-11
128-
- platform: macos-12
129127
- platform: macos-13
128+
- platform: macos-latest
130129
runs-on: ${{ matrix.platform }}
131130
env:
132131
TOOLCHAIN: stable
@@ -153,7 +152,7 @@ jobs:
153152
run: |
154153
git clone https://github.com/rust-bitcoin/rust-lightning
155154
cd rust-lightning
156-
git checkout 0.0.125-bindings
155+
git checkout 0.1-bindings
157156
- name: Rebuild bindings using Apple clang, and check the sample app builds + links
158157
run: ./genbindings.sh ./rust-lightning true
159158
- name: Rebuild bindings using upstream clang, and check the sample app builds + links

c-bindings-gen/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2217,7 +2217,7 @@ fn convert_file<'a, 'b>(libast: &'a FullLibraryAST, crate_types: &CrateTypes<'a>
22172217
writeln!(out, "pub mod {};", m).unwrap();
22182218
}
22192219

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

22222222
let import_resolver = ImportResolver::new(orig_crate, libast, module, items);
22232223
let mut type_resolver = TypeResolver::new(module, import_resolver, crate_types);

c-bindings-gen/src/types.rs

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -736,9 +736,12 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
736736
// is actually a pub(.*) use statement and map it to the real path.
737737
let path_tmp = path.clone();
738738
let crate_name = path_tmp.splitn(2, "::").next().unwrap();
739-
let mut module_riter = path_tmp.rsplitn(2, "::");
740-
let obj = module_riter.next().unwrap();
741-
if let Some(module_path) = module_riter.next() {
739+
let mut module_part_iter = path_tmp.split("::");
740+
let mut pos = module_part_iter.next().unwrap().len();
741+
while let Some(obj) = module_part_iter.next() {
742+
let module_path = &path_tmp[..pos];
743+
pos += 2 + obj.len();
744+
742745
if let Some(m) = self.library.modules.get(module_path) {
743746
for item in m.items.iter() {
744747
if let syn::Item::Use(syn::ItemUse { vis, tree, .. }) = item {
@@ -756,6 +759,21 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr
756759
},
757760
syn::Visibility::Inherited => {},
758761
}
762+
} else if let syn::Item::ExternCrate(syn::ItemExternCrate { vis, ident, rename, .. }) = item {
763+
match vis {
764+
syn::Visibility::Public(_)|
765+
syn::Visibility::Crate(_)|
766+
syn::Visibility::Restricted(_) => {
767+
if let Some((_, ident)) = rename {
768+
if ident != obj { continue; }
769+
} else {
770+
if ident != obj { continue; }
771+
}
772+
773+
path = format!("{}", ident) + &path_tmp[pos..];
774+
},
775+
syn::Visibility::Inherited => {},
776+
}
759777
}
760778
}
761779
}
@@ -845,8 +863,9 @@ impl FullLibraryAST {
845863
syn::Item::Mod(_) => panic!("--pretty=expanded output should never have non-body modules"),
846864
syn::Item::ExternCrate(c) => {
847865
if export_status(&c.attrs) == ExportStatus::Export {
848-
self.dependencies.insert(c.ident);
866+
self.dependencies.insert(c.ident.clone());
849867
}
868+
non_mod_items.push(syn::Item::ExternCrate(c));
850869
},
851870
_ => { non_mod_items.push(item); }
852871
}
@@ -1128,15 +1147,15 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11281147
if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
11291148
"bitcoin::secp256k1::Message" if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
11301149
"bitcoin::secp256k1::Message" if is_ref => Some("*const [u8; 32]"),
1131-
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash"
1132-
|"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
1133-
|"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret"
1150+
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash"
1151+
|"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
1152+
|"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret"
11341153
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
11351154
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
11361155
if is_ref => Some("*const [u8; 32]"),
1137-
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash"
1138-
|"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
1139-
|"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret"
1156+
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash"
1157+
|"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
1158+
|"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret"
11401159
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
11411160
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
11421161
if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
@@ -1251,11 +1270,11 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
12511270
"bitcoin::constants::ChainHash" => Some("::bitcoin::constants::ChainHash::from(&"),
12521271
"bitcoin::hashes::sha256::Hash" if is_ref => Some("&::bitcoin::hashes::sha256::Hash::from_slice(&unsafe { &*"),
12531272
"bitcoin::hashes::sha256::Hash" => Some("::bitcoin::hashes::sha256::Hash::from_slice(&"),
1254-
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash" if !is_ref => Some("::lightning::ln::types::PaymentHash("),
1255-
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash" if is_ref => Some("&::lightning::ln::types::PaymentHash(unsafe { *"),
1256-
"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage" if !is_ref => Some("::lightning::ln::types::PaymentPreimage("),
1257-
"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage" if is_ref => Some("&::lightning::ln::types::PaymentPreimage(unsafe { *"),
1258-
"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret" if !is_ref => Some("::lightning::ln::types::PaymentSecret("),
1273+
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash" if !is_ref => Some("::lightning::types::payment::PaymentHash("),
1274+
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash" if is_ref => Some("&::lightning::types::payment::PaymentHash(unsafe { *"),
1275+
"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage" if !is_ref => Some("::lightning::types::payment::PaymentPreimage("),
1276+
"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage" if is_ref => Some("&::lightning::types::payment::PaymentPreimage(unsafe { *"),
1277+
"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret" if !is_ref => Some("::lightning::types::payment::PaymentSecret("),
12591278
"lightning::ln::channelmanager::PaymentId" if !is_ref => Some("::lightning::ln::channelmanager::PaymentId("),
12601279
"lightning::ln::channelmanager::PaymentId" if is_ref=> Some("&::lightning::ln::channelmanager::PaymentId( unsafe { *"),
12611280
"lightning::ln::channelmanager::InterceptId" if !is_ref => Some("::lightning::ln::channelmanager::InterceptId("),
@@ -1362,15 +1381,15 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
13621381
"bitcoin::hash_types::BlockHash"|"bitcoin::BlockHash" if !is_ref => Some(".data[..]).unwrap()"),
13631382
"bitcoin::constants::ChainHash" if !is_ref => Some(".data)"),
13641383
"bitcoin::hashes::sha256::Hash" => Some(" }[..]).unwrap()"),
1365-
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash"
1366-
|"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
1367-
|"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret"
1384+
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash"
1385+
|"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
1386+
|"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret"
13681387
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
13691388
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
13701389
if !is_ref => Some(".data)"),
1371-
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash"
1372-
|"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
1373-
|"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret"
1390+
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash"
1391+
|"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
1392+
|"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret"
13741393
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
13751394
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
13761395
if is_ref => Some(" })"),
@@ -1410,6 +1429,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
14101429
"[u8; 32]" if is_ref => Some(""),
14111430
"[u8; 20]" if !is_ref => Some("crate::c_types::TwentyBytes { data: "),
14121431
"[u8; 16]" if !is_ref => Some("crate::c_types::SixteenBytes { data: "),
1432+
"[u8; 16]" if is_ref => Some(""),
14131433
"[u8; 12]" if !is_ref => Some("crate::c_types::TwelveBytes { data: "),
14141434
"[u8; 4]" if !is_ref => Some("crate::c_types::FourBytes { data: "),
14151435
"[u8; 3]" if !is_ref => Some("crate::c_types::ThreeBytes { data: "),
@@ -1492,15 +1512,15 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
14921512
if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: *"),
14931513
"bitcoin::secp256k1::Message" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
14941514
"bitcoin::secp256k1::Message" if is_ref => Some(""),
1495-
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash"
1496-
|"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
1497-
|"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret"
1515+
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash"
1516+
|"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
1517+
|"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret"
14981518
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
14991519
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
15001520
if is_ref => Some("&"),
1501-
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash"
1502-
|"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
1503-
|"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret"
1521+
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash"
1522+
|"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
1523+
|"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret"
15041524
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
15051525
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
15061526
if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
@@ -1523,6 +1543,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
15231543
"[u8; 32]" if !is_ref => Some(" }"),
15241544
"[u8; 32]" if is_ref => Some(""),
15251545
"[u8; 20]" if !is_ref => Some(" }"),
1546+
"[u8; 16]" if is_ref => Some(""),
15261547
"[u8; 16]" if !is_ref => Some(" }"),
15271548
"[u8; 12]" if !is_ref => Some(" }"),
15281549
"[u8; 4]" if !is_ref => Some(" }"),
@@ -1601,15 +1622,15 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
16011622
if !is_ref => Some(".as_ref() }"),
16021623
"bitcoin::secp256k1::Message" if !is_ref => Some(".as_ref().clone() }"),
16031624
"bitcoin::secp256k1::Message" if is_ref => Some(".as_ref()"),
1604-
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash"
1605-
|"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
1606-
|"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret"
1625+
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash"
1626+
|"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
1627+
|"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret"
16071628
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
16081629
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
16091630
if is_ref => Some(".0"),
1610-
"lightning::ln::types::PaymentHash"|"lightning_types::payment::PaymentHash"
1611-
|"lightning::ln::types::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
1612-
|"lightning::ln::types::PaymentSecret"|"lightning_types::payment::PaymentSecret"
1631+
"lightning::types::payment::PaymentHash"|"lightning_types::payment::PaymentHash"
1632+
|"lightning::types::payment::PaymentPreimage"|"lightning_types::payment::PaymentPreimage"
1633+
|"lightning::types::payment::PaymentSecret"|"lightning_types::payment::PaymentSecret"
16131634
|"lightning::ln::channelmanager::PaymentId"|"lightning::ln::channelmanager::InterceptId"
16141635
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
16151636
if !is_ref => Some(".0 }"),

0 commit comments

Comments
 (0)