From: Matt Corallo <649246+TheBlueMatt@users.noreply.github.com> Date: Mon, 8 Mar 2021 21:34:27 +0000 (-0800) Subject: Merge pull request #1 from TheBlueMatt/main X-Git-Tag: v0.0.98~25 X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-c-bindings;a=commitdiff_plain;h=2c5275b06bd49b7c39242c74d5cfc707827b0cc7;hp=1495575b517c90da925698da14f627bf0d5b313f Merge pull request #1 from TheBlueMatt/main Update genbindings.sh and Cargo.toml for out-of-tree builds --- diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..9511edf --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,43 @@ +name: Continuous Integration Checks + +on: [push, pull_request] + +jobs: + check_bindings: + runs-on: ubuntu-latest + # 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. + container: debian:bullseye + env: + TOOLCHAIN: stable + steps: + - name: Install native Rust toolchain, Valgrind, and build utilitis + run: | + apt-get update + apt-get -y dist-upgrade + apt-get -y install cargo valgrind lld git g++ clang + - name: Checkout source code + uses: actions/checkout@v2 + - name: Sanity test bindings against Cargo.toml RL + working-directory: lightning-c-bindings + run: cargo check + - name: Install cbindgen + run: cargo install --force cbindgen + - name: Checkout Rust-Lightning git + run: git clone https://github.com/rust-bitcoin/rust-lightning + - name: Rebuild bindings, and check the sample app builds + links + run: ./genbindings.sh ./rust-lightning + - name: Check that the latest bindings are in git + run: | + git checkout lightning-c-bindings/Cargo.toml # genbindings edits this to update the path + if [ "$(git diff)" != "" ]; then + # cbindgen's bindings output order can be FS-dependant, so check that the lines are all the same: + mv lightning-c-bindings/include/lightning.h lightning-c-bindings/include/lightning.h.new + git checkout lightning-c-bindings/include/lightning.h + cat lightning-c-bindings/include/lightning.h | grep -v "Generated with cbindgen:[0-9\.]*" | sort > lightning-c-bindings/include/lightning.h.sorted + cat lightning-c-bindings/include/lightning.h.new | grep -v "Generated with cbindgen:[0-9\.]*" | sort > lightning-c-bindings/include/lightning.h.new.sorted + diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted + [ "$(diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted)" != "" ] && exit 2 + git diff --exit-code + fi + diff --git a/genbindings.sh b/genbindings.sh index 241ed3e..0d8a691 100755 --- a/genbindings.sh +++ b/genbindings.sh @@ -3,6 +3,17 @@ set -e set -x +if [ ! -d "$1/lightning" ]; then + echo "USAGE: $0 path-to-rust-lightning" + exit 1 +fi + +# On reasonable systems, we can use realpath here, but OSX is a diva with 20-year-old software. +ORIG_PWD="$(pwd)" +cd "$1/lightning" +LIGHTNING_PATH="$(pwd)" +cd "$ORIG_PWD" + # Generate (and reasonably test) C bindings # First build the latest c-bindings-gen binary @@ -24,11 +35,20 @@ OUT="$(pwd)/lightning-c-bindings/src" OUT_TEMPL="$(pwd)/lightning-c-bindings/src/c_types/derived.rs" OUT_F="$(pwd)/lightning-c-bindings/include/rust_types.h" OUT_CPP="$(pwd)/lightning-c-bindings/include/lightningpp.hpp" +BIN="$(pwd)/c-bindings-gen/target/release/c-bindings-gen" -cd lightning +pushd "$LIGHTNING_PATH" RUSTC_BOOTSTRAP=1 cargo rustc --profile=check -- -Zunstable-options --pretty=expanded | - RUST_BACKTRACE=1 ../c-bindings-gen/target/release/c-bindings-gen $OUT/ lightning $OUT_TEMPL $OUT_F $OUT_CPP -cd .. + RUST_BACKTRACE=1 "$BIN" "$OUT/" lightning "$OUT_TEMPL" "$OUT_F" "$OUT_CPP" +popd + +HOST_PLATFORM="$(rustc --version --verbose | grep "host:")" +if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then + # OSX sed is for some reason not compatible with GNU sed + sed -i '' 's|lightning = { .*|lightning = { path = "'"$LIGHTNING_PATH"'" }|' lightning-c-bindings/Cargo.toml +else + sed -i 's|lightning = { .*|lightning = { path = "'"$LIGHTNING_PATH"'" }|' lightning-c-bindings/Cargo.toml +fi # Now cd to lightning-c-bindings, build the generated bindings, and call cbindgen to build a C header file PATH="$PATH:~/.cargo/bin" @@ -36,8 +56,6 @@ cd lightning-c-bindings cargo build cbindgen -v --config cbindgen.toml -o include/lightning.h >/dev/null 2>&1 -HOST_PLATFORM="$(rustc --version --verbose | grep "host:")" - # cbindgen is relatively braindead when exporting typedefs - # it happily exports all our typedefs for private types, even with the # generics we specified in C mode! So we drop all those types manually here. diff --git a/lightning-c-bindings/Cargo.toml b/lightning-c-bindings/Cargo.toml index 7604731..0b20e3f 100644 --- a/lightning-c-bindings/Cargo.toml +++ b/lightning-c-bindings/Cargo.toml @@ -17,7 +17,8 @@ crate-type = ["staticlib" [dependencies] bitcoin = "0.26" secp256k1 = { version = "0.20.1", features = ["global-context-less-secure"] } -lightning = { version = "0.0.12", path = "../lightning" } +# Note that the following line is matched by genbindings to update the path +lightning = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "8b4ea56966878140b11aa3e17b44fcf1e01d6413" } [patch.crates-io] # Rust-Secp256k1 PR 279. Should be dropped once merged. @@ -29,8 +30,3 @@ panic = "abort" [profile.release] panic = "abort" - -# We eventually want to join the root workspace, but for now, the bindings generation is -# a bit brittle and we don't want to hold up other developers from making changes just -# because they break the bindings -[workspace] diff --git a/lightning-c-bindings/include/lightning.h b/lightning-c-bindings/include/lightning.h index eb6f45b..94ccb26 100644 --- a/lightning-c-bindings/include/lightning.h +++ b/lightning-c-bindings/include/lightning.h @@ -8112,7 +8112,7 @@ void PeerManager_disconnect_by_node_id(const struct LDKPeerManager *NONNULL_PTR * It will send pings to each peer and disconnect those which did not respond to the last round of pings. * Will most likely call send_data on all of the registered descriptors, thus, be very careful with reentrancy issues! */ -void PeerManager_timer_tick_occured(const struct LDKPeerManager *NONNULL_PTR this_arg); +void PeerManager_timer_tick_occurred(const struct LDKPeerManager *NONNULL_PTR this_arg); /** * Build the commitment secret from the seed and the commitment number diff --git a/lightning-c-bindings/src/ln/peer_handler.rs b/lightning-c-bindings/src/ln/peer_handler.rs index 96966a8..9e7422a 100644 --- a/lightning-c-bindings/src/ln/peer_handler.rs +++ b/lightning-c-bindings/src/ln/peer_handler.rs @@ -784,7 +784,7 @@ pub extern "C" fn PeerManager_disconnect_by_node_id(this_arg: &PeerManager, mut /// It will send pings to each peer and disconnect those which did not respond to the last round of pings. /// Will most likely call send_data on all of the registered descriptors, thus, be very careful with reentrancy issues! #[no_mangle] -pub extern "C" fn PeerManager_timer_tick_occured(this_arg: &PeerManager) { - unsafe { &*this_arg.inner }.timer_tick_occured() +pub extern "C" fn PeerManager_timer_tick_occurred(this_arg: &PeerManager) { + unsafe { &*this_arg.inner }.timer_tick_occurred() }