From 1bced7322350f32ce915082eecee9843ed528f34 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 8 Mar 2021 14:15:23 -0500 Subject: [PATCH] Update genbindings.sh and Cargo.toml for out-of-tree builds --- genbindings.sh | 23 ++++++++++++++++++----- lightning-c-bindings/Cargo.toml | 8 ++------ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/genbindings.sh b/genbindings.sh index 241ed3e..6358e30 100755 --- a/genbindings.sh +++ b/genbindings.sh @@ -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. 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] -- 2.39.5