Update genbindings.sh and Cargo.toml for out-of-tree builds
authorMatt Corallo <git@bluematt.me>
Mon, 8 Mar 2021 19:15:23 +0000 (14:15 -0500)
committerMatt Corallo <git@bluematt.me>
Mon, 8 Mar 2021 19:30:39 +0000 (14:30 -0500)
genbindings.sh
lightning-c-bindings/Cargo.toml

index 241ed3e8c882fc1446c58a0fb151c08dcb77adad..6358e30d59d4cad1ba979c21635f8357f9c0361c 100755 (executable)
@@ -3,6 +3,12 @@
 set -e
 set -x
 
+if [ ! -d "$1/lightning" ]; then
+       echo "USAGE: $0 path-to-rust-lightning"
+       exit 1
+fi
+LIGHTNING_PATH="$(realpath "$1/lightning")"
+
 # Generate (and reasonably test) C bindings
 
 # First build the latest c-bindings-gen binary
@@ -24,11 +30,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 +51,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]