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
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"
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.
[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.
[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]