Skip to content

Commit de58bcf

Browse files
authored
Merge pull request #795 from TheBlueMatt/2021-02-features-bindings
Map Features objects in bindings
2 parents 414e622 + 954e66e commit de58bcf

File tree

21 files changed

+10423
-6634
lines changed

21 files changed

+10423
-6634
lines changed

c-bindings-gen/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ edition = "2018"
88
syn = { version = "1", features = ["full", "extra-traits"] }
99
proc-macro2 = "1"
1010

11+
[profile.release]
12+
debug = true
13+
1114
# We're not in the workspace as we're just a binary code generator:
1215
[workspace]

c-bindings-gen/src/main.rs

Lines changed: 363 additions & 400 deletions
Large diffs are not rendered by default.

c-bindings-gen/src/types.rs

Lines changed: 262 additions & 200 deletions
Large diffs are not rendered by default.

genbindings.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set -x
66
# Generate (and reasonably test) C bindings
77

88
# First build the latest c-bindings-gen binary
9-
cd c-bindings-gen && cargo build && cd ..
9+
cd c-bindings-gen && cargo build --release && cd ..
1010

1111
# Then wipe all the existing C bindings (because we're being run in the right directory)
1212
# note that we keep the few manually-generated files first:
@@ -20,12 +20,15 @@ mv ./mod.rs lightning-c-bindings/src/c_types/
2020
mv ./bitcoin lightning-c-bindings/src/
2121

2222
# Finally, run the c-bindings-gen binary, building fresh bindings.
23-
SRC="$(pwd)/lightning/src"
2423
OUT="$(pwd)/lightning-c-bindings/src"
2524
OUT_TEMPL="$(pwd)/lightning-c-bindings/src/c_types/derived.rs"
2625
OUT_F="$(pwd)/lightning-c-bindings/include/rust_types.h"
2726
OUT_CPP="$(pwd)/lightning-c-bindings/include/lightningpp.hpp"
28-
RUST_BACKTRACE=1 ./c-bindings-gen/target/debug/c-bindings-gen $SRC/ $OUT/ lightning $OUT_TEMPL $OUT_F $OUT_CPP
27+
28+
cd lightning
29+
RUSTC_BOOTSTRAP=1 cargo rustc --profile=check -- -Zunstable-options --pretty=expanded |
30+
RUST_BACKTRACE=1 ../c-bindings-gen/target/release/c-bindings-gen $OUT/ lightning $OUT_TEMPL $OUT_F $OUT_CPP
31+
cd ..
2932

3033
# Now cd to lightning-c-bindings, build the generated bindings, and call cbindgen to build a C header file
3134
PATH="$PATH:~/.cargo/bin"

lightning-c-bindings/demo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,9 @@ int main() {
385385
assert(channels2->datalen == 0);
386386

387387
LDK::RoutingMessageHandler net_msgs2 = NetGraphMsgHandler_as_RoutingMessageHandler(&net_graph2);
388-
LDK::ChannelAnnouncement chan_ann = ChannelAnnouncement_read(LDKu8slice { .data = valid_node_announcement, .datalen = sizeof(valid_node_announcement) });
389-
LDK::CResult_boolLightningErrorZ ann_res = net_msgs2->handle_channel_announcement(net_msgs2->this_arg, &chan_ann);
388+
LDK::CResult_ChannelAnnouncementDecodeErrorZ chan_ann = ChannelAnnouncement_read(LDKu8slice { .data = valid_node_announcement, .datalen = sizeof(valid_node_announcement) });
389+
assert(chan_ann->result_ok);
390+
LDK::CResult_boolLightningErrorZ ann_res = net_msgs2->handle_channel_announcement(net_msgs2->this_arg, chan_ann->contents.result);
390391
assert(ann_res->result_ok);
391392

392393
LDK::MessageHandler msg_handler2 = MessageHandler_new(ChannelManager_as_ChannelMessageHandler(&cm2), std::move(net_msgs2));

0 commit comments

Comments
 (0)