Merge pull request #1 from TheBlueMatt/main
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Mon, 8 Mar 2021 21:34:27 +0000 (13:34 -0800)
committerGitHub <noreply@github.com>
Mon, 8 Mar 2021 21:34:27 +0000 (13:34 -0800)
Update genbindings.sh and Cargo.toml for out-of-tree builds

.github/workflows/build.yml [new file with mode: 0644]
genbindings.sh
lightning-c-bindings/Cargo.toml
lightning-c-bindings/include/lightning.h
lightning-c-bindings/src/ln/peer_handler.rs

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644 (file)
index 0000000..9511edf
--- /dev/null
@@ -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
+
index 241ed3e8c882fc1446c58a0fb151c08dcb77adad..0d8a691bfdcac33aa34a314b3cbca19cf95a264b 100755 (executable)
@@ -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.
index 76047314ea148ad27d667ec63155a2f91a43bde8..0b20e3f6cc4d9f8b034340486651def3067836f2 100644 (file)
@@ -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]
index eb6f45b713c3d9bd4fbe60f69cd1c0744f634000..94ccb2656800a731dce218802daac93fc7bcb82e 100644 (file)
@@ -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
index 96966a8599444b43b73e0e18d87fe37f1cf61f61..9e7422a6eac6f4b5606201e80ebb53968ea762ff 100644 (file)
@@ -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()
 }